refactor: Modularize server into separate concerns
Split monolithic index.ts (~1400 lines) into modular structure: - config.ts: Server configuration and constants - db/: Database initialization, migrations, and seeds - routes/: API handlers by domain (themes, canvas, components, etc.) - services/: Terminal WebSocket server - utils/: CORS helpers Entry point now only coordinates initialization.
This commit is contained in:
21
server/utils/cors.ts
Normal file
21
server/utils/cors.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type'
|
||||
}
|
||||
|
||||
export function optionsResponse() {
|
||||
return new Response(null, { headers: corsHeaders })
|
||||
}
|
||||
|
||||
export function jsonResponse(data: unknown, status = 200) {
|
||||
return Response.json(data, { status, headers: corsHeaders })
|
||||
}
|
||||
|
||||
export function errorResponse(error: string, status = 400) {
|
||||
return Response.json({ error }, { status, headers: corsHeaders })
|
||||
}
|
||||
|
||||
export function notFoundResponse() {
|
||||
return new Response('Not Found', { status: 404, headers: corsHeaders })
|
||||
}
|
||||
Reference in New Issue
Block a user