-
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.
Merge pull request #35 from BunnyWay/feat-add-middlewares
feat: add middlewares for local dev
- Loading branch information
Showing
20 changed files
with
528 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"example/middleware-simple-http": minor | ||
"example/deno-middleware-http": minor | ||
--- | ||
|
||
Add new examples for middleware |
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 @@ | ||
--- | ||
"@bunny.net/edgescript-sdk": minor | ||
--- | ||
|
||
Add middleware for local development |
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 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
/dist/ | ||
/esm/ | ||
/esm-bunny/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
.vscode | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
Empty file.
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,28 @@ | ||
{ | ||
"name": "example/deno-middleware-http", | ||
"version": "0.0.0", | ||
"main": "src/index.ts", | ||
"type": "module", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/BunnyWay/edge-script-sdk.git" | ||
}, | ||
"keywords": [ | ||
"github", | ||
"bunny" | ||
], | ||
"author": "Bunny Devs", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "deno lint", | ||
"test": "deno test --allow-none", | ||
"build": "echo \"No build with Deno!\"", | ||
"dev": "deno run src/main.ts", | ||
"release": "echo \"No release\"" | ||
}, | ||
"dependencies": { | ||
"@bunny.net/edgescript-sdk": "^0.10.0" | ||
}, | ||
"devDependencies": {} | ||
} |
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,19 @@ | ||
import * as BunnySDK from "../../../libs/bunny-sdk/esm/lib.mjs"; | ||
|
||
function sleep(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
console.log("Starting server..."); | ||
|
||
BunnySDK.net.http.servePullZone({ url: "https://perdu.com/" }).onOriginRequest(async (ctx) => { | ||
const req = ctx.request; | ||
console.log(`[INFO]: ${req.method} - ${req.url}`); | ||
await sleep(1); | ||
return ctx.request; | ||
}).onOriginResponse(async (ctx) => { | ||
const res = ctx.response; | ||
console.log(`[INFO]: ${res.status}`); | ||
await sleep(1); | ||
return ctx.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
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 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
/dist/ | ||
/esm/ | ||
/esm-bunny/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
.vscode | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.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,12 @@ | ||
import globals from "globals"; | ||
import pluginJs from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
|
||
export default [ | ||
{ files: ["**/*.{js,mjs,cjs,ts}"] }, | ||
{ languageOptions: { globals: globals.browser } }, | ||
pluginJs.configs.recommended, | ||
...tseslint.configs.recommended, | ||
]; | ||
|
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,9 @@ | ||
export default { | ||
clearMocks: true, | ||
moduleFileExtensions: ['js', 'ts'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.ts'], | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
} |
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,46 @@ | ||
{ | ||
"name": "example/middleware-simple-http", | ||
"version": "0.0.0", | ||
"main": "src/index.ts", | ||
"type": "module", | ||
"files": [ | ||
"dist" | ||
], | ||
"private": true, | ||
"scripts": { | ||
"lint": "eslint src", | ||
"test": "jest --silent --coverage", | ||
"dev": "pnpm run build && node dist/index.js", | ||
"build": "ncc build src/main.ts -o dist/", | ||
"release": "echo \"No release\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/BunnyWay/edge-script-sdk.git" | ||
}, | ||
"keywords": [ | ||
"github", | ||
"bunny" | ||
], | ||
"author": "Bunny Devs", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@eslint/js": "^9.8.0", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^22.1.0", | ||
"@typescript-eslint/eslint-plugin": "^8.0.1", | ||
"@typescript-eslint/parser": "^8.0.1", | ||
"@vercel/ncc": "^0.38.1", | ||
"esbuild": "0.23.0", | ||
"eslint": "^9.8.0", | ||
"globals": "^15.9.0", | ||
"jest": "^29.5.12", | ||
"prettier": "^3.3.3", | ||
"ts-jest": "^29.2.4", | ||
"typescript": "^5.5.4", | ||
"typescript-eslint": "^8.0.1" | ||
}, | ||
"dependencies": { | ||
"@bunny.net/edgescript-sdk": "workspace:*" | ||
} | ||
} |
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,19 @@ | ||
import * as BunnySDK from "@bunny.net/edgescript-sdk"; | ||
|
||
function sleep(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
console.log("Starting server..."); | ||
|
||
BunnySDK.net.http.servePullZone({ url: "https://perdu.com/" }).onOriginRequest(async (ctx) => { | ||
const req = ctx.request; | ||
console.log(`[INFO]: ${req.method} - ${req.url}`); | ||
await sleep(1); | ||
return ctx.request; | ||
}).onOriginResponse(async (ctx) => { | ||
const res = ctx.response; | ||
console.log(`[INFO]: ${res.status}`); | ||
await sleep(1); | ||
return ctx.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,8 @@ | ||
// import { jest } from '@jest/globals'; | ||
|
||
describe('empty', () => { | ||
test('empty test', async () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
}); |
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,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "nodenext", | ||
"lib": [ | ||
"esnext" | ||
], | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"strict": true, | ||
"allowSyntheticDefaultImports": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"downlevelIteration": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"suppressExcessPropertyErrors": false, | ||
"declaration": true, | ||
"sourceMap": false, | ||
"noImplicitAny": false, | ||
"noEmitOnError": false, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"**/*.test.*" | ||
] | ||
} |
Oops, something went wrong.