forked from Rosetta/landing
Add Sites worker entrypoint
This commit is contained in:
11
build/prepare-sites-build.mjs
Normal file
11
build/prepare-sites-build.mjs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { copyFile, mkdir } from 'node:fs/promises';
|
||||||
|
import { resolve } from 'node:path';
|
||||||
|
|
||||||
|
const root = process.cwd();
|
||||||
|
const serverDirectory = resolve(root, 'dist', 'server');
|
||||||
|
|
||||||
|
await mkdir(serverDirectory, { recursive: true });
|
||||||
|
await copyFile(
|
||||||
|
resolve(root, 'worker', 'index.js'),
|
||||||
|
resolve(serverDirectory, 'index.js'),
|
||||||
|
);
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build && node build/prepare-sites-build.mjs",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
|||||||
18
worker/index.js
Normal file
18
worker/index.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
const worker = {
|
||||||
|
async fetch(request, env) {
|
||||||
|
const response = await env.ASSETS.fetch(request);
|
||||||
|
|
||||||
|
if (
|
||||||
|
response.status !== 404 ||
|
||||||
|
request.method !== 'GET' ||
|
||||||
|
!request.headers.get('accept')?.includes('text/html')
|
||||||
|
) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
const indexUrl = new URL('/index.html', request.url);
|
||||||
|
return env.ASSETS.fetch(new Request(indexUrl, request));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default worker;
|
||||||
Reference in New Issue
Block a user