forked from Chanzhaoyu/chatgpt-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
26 lines (20 loc) · 674 Bytes
/
index.ts
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
import express from 'express'
import { chatReply, clearChatContext } from './chatgpt'
const app = express()
app.use(express.json())
app.all('*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Content-Type')
res.header('Access-Control-Allow-Methods', '*')
next()
})
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
app.post('/chat', async (req, res) => {
const { message } = req.body
const response = await chatReply(message)
res.send(response)
})
app.post('/clear', async (req, res) => {
const response = await clearChatContext()
res.send(response)
})