chore: 调整文件结构 service 和 web 分离

This commit is contained in:
ChenZhaoYu
2023-02-13 10:00:08 +08:00
parent 98e75c0c5c
commit f910b5f8a4
16 changed files with 3180 additions and 773 deletions

26
service/src/index.ts Normal file
View File

@@ -0,0 +1,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)
})