Skip to content

Commit bd6ada3

Browse files
fix(app-next): align next handler with express handler (#40)
1 parent 4afbf65 commit bd6ada3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/app-next/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path');
22
const next = require('next');
33
const nextBuild = require('next/dist/build').default;
4+
const { parse } = require('url');
45

56
class NextApp {
67
constructor({ dir } = {}) {
@@ -15,7 +16,16 @@ class NextApp {
1516
// We want to keep this behaviour, so I omitted it for now
1617
const nextApp = next({ dir: this._dir, dev });
1718
await nextApp.prepare();
18-
return nextApp.getRequestHandler();
19+
20+
// NOTE: There's a conflict between Next.js handler and express handler in third argument
21+
// Next.js one expects optional parsed string, while express gives next callback
22+
// https://nextjs.org/docs/pages/guides/custom-server
23+
const nextHandler = nextApp.getRequestHandler();
24+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
25+
return function expressHandler(req, res, _next) {
26+
const parsedUrl = parse(req.url, true);
27+
return nextHandler(req, res, parsedUrl);
28+
};
1929
}
2030

2131
async build() {

0 commit comments

Comments
 (0)