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:
2025-12-15 05:56:18 +01:00
parent 9d83a9d2f0
commit 02d32536a0
3 changed files with 72 additions and 68 deletions

View File

@@ -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 }