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 });
|
||||
|
||||
|
Reference in New Issue
Block a user