-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (35 loc) Β· 1.22 KB
/
server.js
File metadata and controls
43 lines (35 loc) Β· 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Simple Express server for API endpoints during development
* Handles the insights API endpoint
*/
import express from 'express'
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import insightsHandler from './scripts/insights-api.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const app = express()
const PORT = 3001
// Middleware
app.use(express.json())
// CORS headers
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
if (req.method === 'OPTIONS') {
res.sendStatus(200)
} else {
next()
}
})
// Insights API endpoint
app.post('/api/insights', insightsHandler)
// Serve static files from public directory
app.use(express.static(join(__dirname, 'public')))
// Start server
app.listen(PORT, () => {
console.log(`π API server running on http://localhost:${PORT}`)
console.log(`π Insights endpoint available at http://localhost:${PORT}/api/insights`)
console.log(`π Using OPENAI_API_KEY from environment: ${process.env.OPENAI_API_KEY ? 'β
' : 'β Not set'}`)
})