const express = require('express');
const router = express.Router();
const request = require('request');
router.use('/openai/v1/chat/completions', (req, res) => {
let url = 'https://www.baidu.com/';//需要转发的接口
let options = {
url: url,
json: true,
body:{}//要传入的数据
}
request.post(options, (error, response, body) => {
console.log(body)
res.send({
data: {
code: 200,
data:body
}
});
});
});
module.exports = router;
在app.js中引入上面router文件夹
let express = require('express');
let app = express();
let router = require('./server/router');
app.use(router);
module.exports = app;
启动node