Fix wws runtime compatibility - use module.exports pattern
- Update api/index.js to use handler export format
- Update chat/index.js to use handler export format
- Update webhook/index.js to use handler export format
- Remove addEventListener('fetch') pattern incompatible with wws
- Remove URL API usage (not available in wws JS runtime)
- Remove spread operator for better compatibility
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
19
api/index.js
19
api/index.js
@@ -1,22 +1,17 @@
|
||||
// Health check and API info endpoint
|
||||
// Path: /api
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(handleRequest(event.request))
|
||||
})
|
||||
|
||||
async function handleRequest(request) {
|
||||
const url = new URL(request.url)
|
||||
|
||||
async function handler(request) {
|
||||
// CORS headers for browser requests
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
if (request.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders })
|
||||
return new Response('', { headers: corsHeaders })
|
||||
}
|
||||
|
||||
const response = {
|
||||
@@ -38,9 +33,9 @@ async function handleRequest(request) {
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(response, null, 2), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...corsHeaders
|
||||
}
|
||||
headers: corsHeaders
|
||||
})
|
||||
}
|
||||
|
||||
// Export for wws
|
||||
module.exports = { handler }
|
||||
|
||||
Reference in New Issue
Block a user