-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
39 lines (32 loc) · 978 Bytes
/
index.ts
File metadata and controls
39 lines (32 loc) · 978 Bytes
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
import cors from 'cors'
import express from 'express'
import dotenv from 'dotenv'
import { HandlerError, handleRawRequest } from './handler'
dotenv.config()
const app = express()
app.use(cors())
app.use(express.json())
app.post('/', async (req, res) => {
console.log(`[INFO] Received POST request:`, req.body)
const responseData = await handleRawRequest(req.body)
switch (responseData) {
case HandlerError.ParseFailed:
console.log('[WARN] Invalid request received and ignored.')
res.status(400).send()
break
case HandlerError.ForwardingFailed:
console.log('[WARN] Failed to forward request to evaluation function.')
res.status(400).send()
break
default:
console.log(
'[INFO] Received response from evaluation function:',
responseData,
)
res.send(responseData)
}
})
const port = process.env.PORT ?? 3070
app.listen(port, () => {
console.log(`[INFO] Listening on port ${port}`)
})