尝试提交时出现交易问题

问题描述 投票:0回答:1

[尝试在数据库上提交行时遇到问题。

Api url

尝试调用此api网址时出现以下错误。

Error

我正在设置这样的标题

const session = require('express-session');
const bodyParser = require('body-parser');
const pool = require('../database/database');

const apiEndpoints = require('./endpoints/api');
const authEndpoints = require('./endpoints/auth');


const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

const secret = 'IHDuhjdnoHODPdd526DDhkDKdDd2365d5d5BkgJSAdddsjxzpls23x32s';
app.use(session({
  secret,
  resave: true,
  saveUninitialized: true,
}));

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Content-Type', 'application/json');
  next();
});

const api = apiEndpoints.initEndpoints(pool);
const auth = authEndpoints.initEndpoints(pool);

app.use('/api', api);
app.use('/auth', auth);
const port = 4201;
app.listen(port, () => {
  console.log(`listening on port ${port}`);
});```


Can someone help me on this issue ? I'm unable to resolve it since a day now...


mysql node.js express database-connection
1个回答
0
投票

您必须在res.json(err)之后添加return语句,因为您已经发送了响应。

© www.soinside.com 2019 - 2024. All rights reserved.