mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
change semantics
Update README deployment steps and add deploy:secrets script to package.json update local inference script and README update lockfile reconfigure package scripts for development update test execution pass server tests Update README with revised Bun commands and workspace details remove pnpm package manager designator create bun server
This commit is contained in:

committed by
Geoff Seemueller

parent
1055cda2f1
commit
497eb22ad8
50
packages/server/services/AssetService.ts
Normal file
50
packages/server/services/AssetService.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { types } from "mobx-state-tree";
|
||||
import { renderPage } from "vike/server";
|
||||
|
||||
export default types
|
||||
.model("StaticAssetStore", {})
|
||||
.volatile((self) => ({
|
||||
env: {} as Env,
|
||||
ctx: {} as ExecutionContext,
|
||||
}))
|
||||
.actions((self) => ({
|
||||
setEnv(env: Env) {
|
||||
self.env = env;
|
||||
},
|
||||
setCtx(ctx: ExecutionContext) {
|
||||
self.ctx = ctx;
|
||||
},
|
||||
async handleSsr(
|
||||
url: string,
|
||||
headers: Headers,
|
||||
env: Vike.PageContext["env"],
|
||||
) {
|
||||
console.log("handleSsr");
|
||||
const pageContextInit = {
|
||||
urlOriginal: url,
|
||||
headersOriginal: headers,
|
||||
fetch: (...args: Parameters<typeof fetch>) => fetch(...args),
|
||||
env,
|
||||
};
|
||||
|
||||
const pageContext = await renderPage(pageContextInit);
|
||||
const { httpResponse } = pageContext;
|
||||
|
||||
|
||||
if (!httpResponse) {
|
||||
return null;
|
||||
} else {
|
||||
const { statusCode: status, headers } = httpResponse;
|
||||
return new Response(httpResponse.pipe, { headers, status });
|
||||
}
|
||||
},
|
||||
async handleStaticAssets(request: Request, env) {
|
||||
console.log("handleStaticAssets");
|
||||
try {
|
||||
return await env.ASSETS.fetch(request);
|
||||
} catch (error) {
|
||||
console.error("Error serving static asset:", error);
|
||||
return new Response("Asset not found", { status: 404 });
|
||||
}
|
||||
},
|
||||
}));
|
Reference in New Issue
Block a user