2023-02-09 01:55:27 -05:00
|
|
|
import express from 'express'
|
2023-02-09 22:40:40 -05:00
|
|
|
import { chatReply } from './chatgpt'
|
2023-02-09 01:55:27 -05:00
|
|
|
|
|
|
|
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
|
2023-02-09 22:40:40 -05:00
|
|
|
const response = await chatReply(message)
|
2023-02-09 01:55:27 -05:00
|
|
|
res.send(response)
|
|
|
|
})
|