Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { build } from 'esbuild';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

try {
await build({
bundle: true,
sourcemap: true,
format: 'esm',
target: 'esnext',
external: ['__STATIC_CONTENT_MANIFEST'],
conditions: ['worker', 'browser'],
entryPoints: [path.join(__dirname, 'src', 'index.ts')],
outdir: path.join(__dirname, 'dist'),
outExtension: { '.js': '.mjs' },
});
} catch {
process.exitCode = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cachable response at 2023-09-02T14:43:53.339Z
Binary file not shown.
58 changes: 58 additions & 0 deletions examples/hono/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "cloudworker-proxy-hono-example",
"version": "1.0.0",
"description": "An api gateway for cloudflare workers",
"main": "build/src/server.js",
"scripts": {
"build": "node build.js",
"dev": "wrangler dev",
"format": "prettier --write '**/*.{js,css,json,md}'"
},
"repository": {
"type": "git",
"url": "git+https://github.com/markusahlstrand/cloudworker-proxy.git"
},
"keywords": [
"cloudflare",
"workers",
"api",
"gateway",
"proxy"
],
"author": "Markus Ahlstrand",
"license": "MIT",
"bugs": {
"url": "https://github.com/markusahlstrand/cloudworker-proxy/issues"
},
"homepage": "https://github.com/markusahlstrand/cloudworker-proxy#readme",
"dependencies": {
"aws4fetch": "1.0.17",
"cloudworker-router": "4.1.5",
"cookie": "0.5.0",
"hono": "^3.5.6",
"lodash.get": "4.4.2",
"lodash.set": "4.3.2",
"shortid": "2.2.16"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230821.0",
"@semantic-release/git": "^10.0.1",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.9",
"@types/service-worker-mock": "^2.0.1",
"chai": "4.3.8",
"fetch-mock": "9.11.0",
"husky": "^8.0.3",
"jest": "29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jest-fetch-mock": "^3.0.3",
"miniflare": "^3.20230807.0",
"mocha": "10.2.0",
"prettier": "^3.0.1",
"semantic-release": "^21.0.7",
"ts-jest": "29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"wrangler": "^3.6.0"
}
}
69 changes: 69 additions & 0 deletions examples/hono/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Hono } from 'hono';

import packageJson from '../package.json';
import { Env } from './types/Env';
import { registerRoutes } from '../../../src/';
import { basicAuth } from 'hono/basic-auth';
import { cache } from 'hono/cache';
import { originHandler } from '../../../src/handlers';

const app = new Hono<Env>();

app.get('/', async () => {
return new Response(
JSON.stringify({
name: packageJson.name,
version: packageJson.version,
}),
);
});

registerRoutes(app, [
{
path: '/test',
methods: 'GET',
handler: basicAuth({ username: 'test', password: 'password' }),
},
{
path: '/test',
methods: 'GET',
handler: async () => new Response('Raw response'),
},
{
path: '/cache',
methods: 'GET',
handler: cache({ cacheName: 'test' }),
},
{
path: '/cache',
methods: 'GET',
handler: async () =>
new Response(`Cachable response at ${new Date().toISOString()}`, {
headers: {
'Cache-Control': 'max-age=10',
},
}),
},
{
path: '/origin',
methods: 'GET',
handler: originHandler({
baseUrl: 'https://wordpress.com',
proxyUrl: 'http://localhost:8787',
skipPath: '/origin',
rewriteLinks: true,
}),
},
{
path: '/origin/*',
methods: 'GET',
handler: originHandler({
baseUrl: 'https://wordpress.com',
proxyUrl: 'http://localhost:8787',
skipPath: '/origin',
rewriteLinks: true,
}),
},
]);

export default app;
1 change: 1 addition & 0 deletions examples/hono/src/types/Env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface Env {}
12 changes: 12 additions & 0 deletions examples/hono/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "cloudworker-proxy"
main = "src/server.ts"
compatibility_date = "2022-07-06"

# Add your account_id here..
account_id = "0c8c22bdcd98c3dc6a35190650ef7906"

kv_namespaces = []

route = { pattern = "proxy.ahlstrand.es/*", zone_id = "b56a76d859fe2ed6a8d77270cd2e8ba8" }

[vars]
Loading