nextjs-server-modules
Advanced tools
Comparing version 1.3.2 to 1.4.0
#!/usr/bin/env node | ||
require("./dist/lib/cli.js").default() | ||
require("esbuild-runner/register") | ||
require("./lib/cli.js").default() |
@@ -31,4 +31,5 @@ const glob = require("glob-promise") | ||
await require(`${dir}/.nsm/scripts/generate-routes.js`).generateRoutes() | ||
await require(`${dir}/.nsm/scripts/copy-nextjs-config.js`).copyNextjsConfig() | ||
} | ||
module.exports = { build, default: build } |
@@ -12,2 +12,4 @@ import routes from "./generated_routes" | ||
import wrappers from "@seamapi/wrappers" | ||
import resolveRewrites from "./nextjs-middleware/resolve-rewrites" | ||
import nextConfig from "./next.config" | ||
@@ -21,6 +23,24 @@ const debug = Debug("nsm") | ||
} | ||
const routeMatcher = getRouteMatcher(routes) | ||
const server = micro(async (req: IncomingMessage, res) => { | ||
const query = querystring.parse(req.url.split("?").slice(1).join("?")) | ||
debug(`got request for "${req.url}"`) | ||
const resolveResult = resolveRewrites( | ||
req.url, | ||
Object.keys(routes), | ||
{ | ||
afterFiles: [], | ||
beforeFiles: [], | ||
fallback: [], | ||
...(nextConfig as any).rewrites, | ||
}, | ||
query, | ||
(s) => s | ||
) | ||
req.url = resolveResult.resolvedHref || req.url | ||
debug(`resolved request to "${req.url}"`) | ||
req.url = req.url.split("?")[0] | ||
if (req.url.startsWith("/_next/static")) { | ||
@@ -27,0 +47,0 @@ req.url = req.url.replace(/^\/_next\/static/, "") |
@@ -1,2 +0,1 @@ | ||
const glob = require("glob-promise") | ||
const path = require("path") | ||
@@ -8,23 +7,19 @@ const prettier = require("prettier") | ||
const pagesDir = path.resolve(__dirname, "../../.next/server/pages") | ||
const allPageFiles = (await glob("**/*", { cwd: pagesDir })).filter( | ||
(fp) => !fp.endsWith(".nft.json") && fp.includes(".") | ||
const pagesManifest = JSON.parse( | ||
await fs.readFile(path.resolve(pagesDir, "../pages-manifest.json")) | ||
) | ||
const routesFile = prettier.format( | ||
`const path = require("path") | ||
`import path from "path" | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true, | ||
}) | ||
exports.default = void 0 | ||
var _default = { | ||
${allPageFiles | ||
.map((fp) => | ||
fp.startsWith("api") | ||
? `"/${fp.split(".js")[0]}": require("../.next/server/pages/${fp}")` | ||
: `"/${fp}": path.resolve(__dirname, "../.next/server/pages/${fp}")` | ||
export default { | ||
${Object.entries(pagesManifest) | ||
.map(([route, fp]) => | ||
fp.startsWith("pages/api") | ||
? `"${route}": require("../${fp}")` | ||
: `"${route}": path.resolve(__dirname, "../.next/server/${fp}")` | ||
) | ||
.join(",")} | ||
} | ||
exports.default = _default | ||
@@ -36,3 +31,3 @@ `, | ||
await fs.writeFile( | ||
path.resolve(__dirname, "../generated_routes.js"), | ||
path.resolve(__dirname, "../generated_routes.ts"), | ||
routesFile | ||
@@ -39,0 +34,0 @@ ) |
@@ -66,1 +66,21 @@ // https://github.com/vercel/next.js/blob/bb6d4d71fd419b64e2a3ce4d3496f2150f9ff86b/packages/next/shared/lib/utils.ts | ||
) => void | Promise<void> | ||
export type RouteHas = | ||
| { | ||
type: "header" | "query" | "cookie" | ||
key: string | ||
value?: string | ||
} | ||
| { | ||
type: "host" | ||
key?: undefined | ||
value: string | ||
} | ||
export type Rewrite = { | ||
source: string | ||
destination: string | ||
basePath?: false | ||
locale?: false | ||
has?: RouteHas[] | ||
} |
{ | ||
"name": "nextjs-server-modules", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"main": "bin.js", | ||
@@ -8,3 +8,3 @@ "repository": "git@github.com:hello-seam/nextjs-server-modules.git", | ||
"scripts": { | ||
"build": "rimraf ./dist && swc ./lib -d ./dist/lib && swc ./nsm -d ./dist/nsm" | ||
"build:old": "rimraf ./dist && swc ./lib -d ./dist/lib && swc ./nsm -d ./dist/nsm" | ||
}, | ||
@@ -37,2 +37,3 @@ "bin": { | ||
"@seamapi/wrappers": "^1.0.1", | ||
"path-to-regexp": "^6.2.0", | ||
"cookie": "^0.4.1", | ||
@@ -39,0 +40,0 @@ "debug": "^4.3.3", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
10
53753
15
1586
1
+ Addedpath-to-regexp@^6.2.0
+ Addedpath-to-regexp@6.3.0(transitive)