第一件事,我得到了错误:
Fetch API cannot load file:///xxxx/web-frontend/node_modules/axios/lib/core/createError.js. URL scheme must be "http" or "https" for CORS request.
我无法确定为什么会这样。然后我在Python Backend API控制台中看到了以下消息:
[10/Dec/2019 14:24:54] "GET /api/main_get/boards/b/ HTTP/1.1" 500 17478
[10/Dec/2019 14:24:54] "GET /api/main_get/ HTTP/1.1" 200 87
[10/Dec/2019 14:24:54] "GET /api/main_get/ HTTP/1.1" 200 87
Not Found: /api/main_get/boards/_stream_readable.js/
Not Found: /api/main_get/boards/events.js/
[10/Dec/2019 14:24:54] "GET /api/main_get/boards/_stream_readable.js/ HTTP/1.1" 404 30
[10/Dec/2019 14:24:54] "GET /api/main_get/boards/events.js/ HTTP/1.1" 404 30
然后,我决定在Node.js控制台中记录参数。我得到了:
{ abbr: 'b' }
{ abbr: 'events.js' }
{ abbr: '_stream_readable.js' }
我的前端服务器设置:
const express = require('express');
const next = require('next');
const port = +process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.get('/boards/:abbr', (req, res) => {
console.log(req.params);
return app.render(req, res, '/boards', { abbr : req.params.abbr });
})
server.all('*', (req, res) => {
return handle(req, res);
});
server.listen(port, err => {
if (err) throw err;
console.log(`Server is listening on port ${port}!`);
})
});
为什么Express / Next.js服务器将文件识别为“ abbr”参数?
答案 0 :(得分:0)
该错误是由API引起的。我在DB中手动创建了线程,但忘记在第一篇文章中分配它们。