-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial
vercel-plugin-middleware
(#6892)
* Add initial `vercel-plugin-middleware` * Ignore `entries.js` from ESLint * Add `runDevMiddleware()` stub * Add test * Add support for "_middleware.{js,ts}" to `vercel dev` (#6880) * Add websandbox from next.js codebase. * Use node-fetch instead of next's polyfilled fetch. * Handle middleware rewrites. * Add response, headers, and request to websandbox context. * Move websandbox dependency to middleware plugin. * Add integration tests, update websandbox to support ts files and json imports. * commit yarn.lock changes after rebasing * Clean up left over console.logs, fix some tsc issues, and rebase issue. * Fix failing test and eslint. * Fix middleware test on windows. * [examples] Update Vercel Next.js example template to 12.0.1 (#6905) * Mark the Plugins as external to CLI's ncc build * [cli] Improve tracing in vc build (#6898) * [cli] Fix tracing for `vc build` * Ignore object when there are no changes * Make Next < 12 work with FS API w/ nft * Update packages/cli/src/commands/build.ts Co-authored-by: Nathan Rajlich <n@n8.io> * Document how Next.js processing works in build * [cli] Fix static assets (#6906) * Make sure output path is .next * Fix up require-server-files for processing * Fix typo * Move static * Update static rename Co-authored-by: Andy Bitz <artzbitz@gmail.com> Co-authored-by: Nathan Rajlich <n@n8.io> Co-authored-by: Andy <AndyBitz@users.noreply.github.com> * Publish Canary - vercel@23.1.3-canary.17 - @vercel/client@10.2.3-canary.15 - @vercel/static-config@0.0.1-canary.0 * [cli] Ignore `.env` and `.gitignore` in "vc build" (#6910) * Publish Canary - vercel@23.1.3-canary.18 * Pass workPath to plugins. The new plugin architecture doesn't pass a full BuildOptions object, previous to this commit it wasn't passing any options at all. I've added workingPath to support running dev/build from directories other than the project root. * Remove error state when package.json exists, but no build script This allows vercel build to continue working for projects that are not using frameworks, but use package.json to manage dependencies. * Fix types, pull in middleware header fix from next.js Next js PR w/ the header fix: vercel/next.js#30560 * Fix missing entries file for vc build. * Update call signature of middleware when using vc build. Co-authored-by: Drew Bredvick <dbredvick@gmail.com> Co-authored-by: Nathan Rajlich <n@n8.io> Co-authored-by: Jared Palmer <jared@jaredpalmer.com> Co-authored-by: Andy Bitz <artzbitz@gmail.com> Co-authored-by: Andy <AndyBitz@users.noreply.github.com> Co-authored-by: Gary Borton <gdborton@gmail.com> Co-authored-by: Drew Bredvick <dbredvick@gmail.com> Co-authored-by: Jared Palmer <jared@jaredpalmer.com> Co-authored-by: Andy Bitz <artzbitz@gmail.com> Co-authored-by: Andy <AndyBitz@users.noreply.github.com>
- Loading branch information
1 parent
df9a4af
commit 44868d7
Showing
40 changed files
with
2,602 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
node_modules | ||
dist | ||
examples | ||
packages/build-utils/test/fixtures | ||
packages/*/test/fixtures | ||
packages/cli/@types | ||
packages/cli/download | ||
packages/cli/dist | ||
packages/cli/test/fixtures | ||
packages/cli/test/dev/fixtures | ||
packages/cli/bin | ||
packages/cli/link | ||
packages/cli/src/util/dev/templates/*.ts | ||
packages/client/tests/fixtures | ||
packages/client/lib | ||
packages/node/src/bridge.ts | ||
packages/node/test/fixtures | ||
packages/node-bridge/bridge.js | ||
packages/node-bridge/launcher.js | ||
packages/static-config/test/fixtures | ||
packages/middleware/src/entries.js |
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
5 changes: 5 additions & 0 deletions
5
packages/cli/test/fixtures/unit/edge-middleware-ts/_middleware.ts
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,5 @@ | ||
import { response } from './response'; | ||
|
||
export default () => { | ||
return new Response(response); | ||
}; |
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 @@ | ||
export const response = 'response'; |
10 changes: 10 additions & 0 deletions
10
packages/cli/test/fixtures/unit/edge-middleware/_middleware.js
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,10 @@ | ||
import response from './response.json'; | ||
|
||
export default function () { | ||
return new Response(JSON.stringify(response), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} |
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 @@ | ||
not hello world |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/fixtures/unit/edge-middleware/response.json
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,3 @@ | ||
{ | ||
"text": "hello world" | ||
} |
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,2 @@ | ||
entries.js | ||
dist |
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,2 @@ | ||
/dist | ||
/test/fixtures/*/.output |
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,25 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs-extra'); | ||
const execa = require('execa'); | ||
const { join } = require('path'); | ||
|
||
async function main() { | ||
const outDir = join(__dirname, 'dist'); | ||
|
||
// Start fresh | ||
await fs.remove(outDir); | ||
|
||
await execa('tsc', [], { | ||
stdio: 'inherit', | ||
}); | ||
|
||
await fs.copyFile( | ||
join(__dirname, 'src/entries.js'), | ||
join(outDir, 'entries.js') | ||
); | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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,59 @@ | ||
{ | ||
"name": "vercel-plugin-middleware", | ||
"version": "0.0.0-canary.3", | ||
"license": "MIT", | ||
"main": "./dist/index", | ||
"homepage": "", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/vercel/vercel.git", | ||
"directory": "packages/middleware" | ||
}, | ||
"scripts": { | ||
"build": "node build", | ||
"test-unit": "jest", | ||
"prepublishOnly": "node build" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
"@peculiar/webcrypto": "1.2.0", | ||
"cookie": "0.4.1", | ||
"esbuild": "0.13.10", | ||
"formdata-node": "4.3.1", | ||
"globby": "9", | ||
"http-proxy": "1.18.1", | ||
"node-fetch": "^2", | ||
"querystring": "0.2.1", | ||
"ua-parser-js": "1.0.2", | ||
"url": "0.11.0", | ||
"uuid": "8.3.2", | ||
"web-streams-polyfill": "3.1.1" | ||
}, | ||
"devDependencies": { | ||
"@types/cookie": "0.4.1", | ||
"@types/glob": "7.2.0", | ||
"@types/http-proxy": "1.17.7", | ||
"@types/jest": "27.0.2", | ||
"@types/node": "16.11.6", | ||
"@types/node-fetch": "^2", | ||
"@types/ua-parser-js": "0.7.36", | ||
"@types/uuid": "8.3.1", | ||
"@vercel/ncc": "0.24.0" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest", | ||
"globals": { | ||
"ts-jest": { | ||
"diagnostics": false, | ||
"isolatedModules": true | ||
} | ||
}, | ||
"verbose": false, | ||
"testEnvironment": "node", | ||
"testMatch": [ | ||
"<rootDir>/test/**/*.test.ts" | ||
] | ||
} | ||
} |
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,15 @@ | ||
import * as middleware from './_middleware'; | ||
_ENTRIES = typeof _ENTRIES === 'undefined' ? {} : _ENTRIES; | ||
_ENTRIES['middleware_pages/_middleware'] = { | ||
default: async function (ev) { | ||
const result = await middleware.default(ev.request, ev); | ||
if (result instanceof Response) { | ||
return { | ||
promise: Promise.resolve(), | ||
waitUntil: Promise.resolve(), | ||
response: result, | ||
}; | ||
} | ||
return result; | ||
}, | ||
}; |
Oops, something went wrong.