mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
Refactor context handling and migrate Wrangler config format.
Replaces `createServerContext` with `createRequestContext` for clarity and consistency across the application. Migrates `wrangler.toml` to `wrangler.jsonc` for improved configuration management and compatibility. Updates related files to align with the new context model and configuration structure.
This commit is contained in:

committed by
Geoff Seemueller

parent
6ce22d8ef2
commit
d0d55f58a6
@@ -6,8 +6,8 @@ import ChatService from "./services/ChatService";
|
||||
import TransactionService from "./services/TransactionService";
|
||||
import FeedbackService from "./services/FeedbackService";
|
||||
|
||||
const Context = types
|
||||
.model("ApplicationContext", {
|
||||
const RequestContext = types
|
||||
.model("RequestContext", {
|
||||
chatService: ChatService,
|
||||
contactService: types.optional(ContactService, {}),
|
||||
assetService: types.optional(AssetService, {}),
|
||||
@@ -36,10 +36,10 @@ const Context = types
|
||||
};
|
||||
});
|
||||
|
||||
export type IRootStore = Instance<typeof Context>;
|
||||
export type IRootStore = Instance<typeof RequestContext>;
|
||||
|
||||
const createServerContext = (env, ctx) => {
|
||||
const instance = Context.create({
|
||||
const createRequestContext = (env, ctx) => {
|
||||
const instance = RequestContext.create({
|
||||
contactService: ContactService.create({}),
|
||||
assetService: AssetService.create({}),
|
||||
transactionService: TransactionService.create({}),
|
||||
@@ -61,6 +61,6 @@ const createServerContext = (env, ctx) => {
|
||||
return instance;
|
||||
};
|
||||
|
||||
export { createServerContext };
|
||||
export { createRequestContext };
|
||||
|
||||
export default Context;
|
||||
export default RequestContext;
|
@@ -1,21 +1,21 @@
|
||||
import { Router, withParams } from "itty-router";
|
||||
import { createServerContext } from "./context";
|
||||
import { createRequestContext } from "./RequestContext";
|
||||
|
||||
export function createRouter() {
|
||||
return (
|
||||
Router()
|
||||
.get("/assets/*", (r, e, c) => {
|
||||
const { assetService } = createServerContext(e, c);
|
||||
const { assetService } = createRequestContext(e, c);
|
||||
return assetService.handleStaticAssets(r, e, c);
|
||||
})
|
||||
|
||||
.post("/api/contact", (r, e, c) => {
|
||||
const { contactService } = createServerContext(e, c);
|
||||
const { contactService } = createRequestContext(e, c);
|
||||
return contactService.handleContact(r);
|
||||
})
|
||||
|
||||
.post("/api/chat", (r, e, c) => {
|
||||
const { chatService } = createServerContext(e, c);
|
||||
const { chatService } = createRequestContext(e, c);
|
||||
return chatService.handleChatRequest(r);
|
||||
})
|
||||
|
||||
@@ -23,18 +23,18 @@ export function createRouter() {
|
||||
"/api/streams/:streamId",
|
||||
withParams,
|
||||
async ({ streamId }, env, ctx) => {
|
||||
const { chatService } = createServerContext(env, ctx);
|
||||
const { chatService } = createRequestContext(env, ctx);
|
||||
return chatService.handleSseStream(streamId); // Handles SSE for streamId
|
||||
},
|
||||
)
|
||||
|
||||
.post("/api/feedback", async (r, e, c) => {
|
||||
const { feedbackService } = createServerContext(e, c);
|
||||
const { feedbackService } = createRequestContext(e, c);
|
||||
return feedbackService.handleFeedback(r);
|
||||
})
|
||||
|
||||
.post("/api/tx", async (r, e, c) => {
|
||||
const { transactionService } = createServerContext(e, c);
|
||||
const { transactionService } = createRequestContext(e, c);
|
||||
return transactionService.handleTransact(r);
|
||||
})
|
||||
|
||||
@@ -50,12 +50,12 @@ export function createRouter() {
|
||||
// })
|
||||
|
||||
.all("/api/metrics/*", async (r, e, c) => {
|
||||
const { metricsService } = createServerContext(e, c);
|
||||
const { metricsService } = createRequestContext(e, c);
|
||||
return metricsService.handleMetricsRequest(r);
|
||||
})
|
||||
|
||||
.get("*", async (r, e, c) => {
|
||||
const { assetService } = createServerContext(e, c);
|
||||
const { assetService } = createRequestContext(e, c);
|
||||
|
||||
console.log("Request received:", { url: r.url, headers: r.headers });
|
||||
|
||||
|
54
wrangler.jsonc
Normal file
54
wrangler.jsonc
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "open-gsio",
|
||||
"assets": {
|
||||
"binding": "ASSETS",
|
||||
"directory": "./dist/client"
|
||||
},
|
||||
"dev": {
|
||||
"ip": "localhost",
|
||||
"port": 3001
|
||||
},
|
||||
"compatibility_date": "2025-04-04",
|
||||
"compatibility_flags": [
|
||||
"nodejs_compat"
|
||||
],
|
||||
"main": "./workers/site/worker.ts",
|
||||
"preview_urls": false,
|
||||
"workers_dev": false,
|
||||
"kv_namespaces": [
|
||||
{
|
||||
"binding": "KV_STORAGE",
|
||||
// $ npx wrangler kv namespace create open-gsio
|
||||
"id": "placeholderId",
|
||||
// $ npx wrangler kv namespace create open-gsio --preview
|
||||
"preview_id": "placeholderIdPreview"
|
||||
}
|
||||
],
|
||||
"migrations": [
|
||||
{
|
||||
"new_classes": [
|
||||
"SiteCoordinator"
|
||||
],
|
||||
"tag": "v1"
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"binding": "EMAIL_SERVICE",
|
||||
"service": "email-service-rpc"
|
||||
}
|
||||
],
|
||||
|
||||
"durable_objects": {
|
||||
"bindings": [
|
||||
{
|
||||
"class_name": "SiteCoordinator",
|
||||
"name": "SITE_COORDINATOR",
|
||||
"script_name": "open-gsio"
|
||||
}
|
||||
]
|
||||
},
|
||||
"observability": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
main="./workers/site/worker.ts"
|
||||
name = "geoff-seemueller-io"
|
||||
compatibility_date = "2025-04-04"
|
||||
workers_dev = false
|
||||
dev.port = 3001
|
||||
dev.ip = "localhost"
|
||||
observability.enabled = true
|
||||
compatibility_flags = ["nodejs_compat"]
|
||||
assets = { directory = "./dist/client", binding = "ASSETS" }
|
||||
preview_urls = false
|
||||
# wrangler.toml (wrangler v3.78.6^)
|
||||
|
||||
# Dev configuration (local)
|
||||
durable_objects.bindings = [{name = "SITE_COORDINATOR", class_name = "SiteCoordinator", script_name = "geoff-seemueller-io"}]
|
||||
migrations = [{tag = "v1", new_classes = ["SiteCoordinator"]}]
|
||||
kv_namespaces = [{binding = "KV_STORAGE", id = "placeholderId", preview_id = "placeholderIdPreview"}]
|
||||
services = [{binding = "EMAIL_SERVICE", service = "email-service-rpc"}]
|
Reference in New Issue
Block a user