This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matheus Sampaio Queiroga <[email protected]>
- Loading branch information
1 parent
b5d2777
commit c27791b
Showing
8 changed files
with
140 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { NextServer, NextServerOptions } from "next/dist/server/next.js"; | ||
Check failure on line 1 in src/middles/nextjs.ts GitHub Actions / Test in node 17.x
Check failure on line 1 in src/middles/nextjs.ts GitHub Actions / Test in node 16.x
|
||
import type { RequestHandler } from "../handler.js"; | ||
import { defineProperties } from "../util.js"; | ||
|
||
/** | ||
* Create config to Nextjs pages | ||
* | ||
* in config set full pages path `dir`, and current middle path | ||
* | ||
* @example | ||
* { | ||
* dir: "/root/nextjs_example", | ||
* conf: { | ||
* basePath: "/foo/bar/page_next" | ||
* } | ||
* } | ||
* | ||
* @param config - Next config | ||
* @returns | ||
*/ | ||
export async function nextjsPages(config: Omit<NextServerOptions, "customServer">): Promise<RequestHandler> { | ||
const app = ((await import("next")).default as any as (options: NextServerOptions) => NextServer)({ | ||
Check failure on line 22 in src/middles/nextjs.ts GitHub Actions / Test in node 17.x
Check failure on line 22 in src/middles/nextjs.ts GitHub Actions / Test in node 16.x
|
||
...config, | ||
customServer: true, | ||
dir: "/root/nextjs_example", | ||
conf: { | ||
basePath: "/page_next" | ||
} | ||
}); | ||
await app.prepare(); | ||
const handler = await app.getRequestHandler(); | ||
return (req, res) => handler(defineProperties(req, { | ||
"url": { | ||
writable: true, | ||
configurable: true, | ||
enumerable: true, | ||
value: String().concat(req.path, ...(Object.keys(req.query).length > 0 ? [ "?", Object.keys(req.query).map(k => String().concat(k, "=", req.query[k])).join("&") ] : [])) | ||
} | ||
}), res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters