hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.63k stars 65 forks source link

1.0 Release #126

Closed hoangvvo closed 2 years ago

hoangvvo commented 3 years ago

This library has been sitting in v0 for awhile. After a period of using it in several production apps, it does not seem to yield any problems. After all, most crux of this library depends on the awesome https://github.com/lukeed/trouter library, so nothing much can really go wrong.

Before the 1.0 release though:

qnxdev commented 3 years ago

How to use it with GrahQL

If I use it in my production build, how difficult could it be to switch to expressjs later?

hoangvvo commented 3 years ago

You can always switch to express by replace nc() with express(). Regarding GraphQL, you probably use it with something like express-graphql, in which case their example works simply by replacing express() with nc()

qnxdev commented 3 years ago

What about using GraphQL with next-connect? And even if I achieve it will it work on Vercel serverless?

hoangvvo commented 3 years ago

It definitely works:

// api/graphql.js
const nc = require("next-connect");
const { graphqlHTTP } = require("express-graphql");

module.exports = nc()
  .use(middleware)
  .all(graphqlHTTP({
    schema: MyGraphQLSchema
  }));
stigkj commented 2 years ago

Would it be smart to include support for the new middleware support in Next.js? Or do you see that as a v2? Or never ;-)

hoangvvo commented 2 years ago

Would it be smart to include support for the new middleware support in Next.js? Or do you see that as a v2? Or never ;-)

It is totally possible. I am just wondering what would be a good naming for this functionality:

import nc from "next-connect/next-middleware
// or
import { middleware } from "next-connect"
stigkj commented 2 years ago

I think I would go with the second one.