nodemon启动后,浏览器访问loacalhost:3000,报错404

来源:2-8 深入理解async和await

慕侠8534226

2020-03-29

const Koa = require(‘koa’);
const app = new Koa();

app.use(async (ctx, next) => {
await next()
const res = ctx.res
console.log(“res”, res)
})
app.use(async (ctx, next) => {
const axios = require(‘axios’)
const res = await axios.get(‘http://7yue.pro’)
ctx.res = res;
await next()
})

app.listen(3000)

老师,这段代码nodemon启动后报错
Error: Request failed with status code 404
at createError (D:\project\island\node_modules\axios\lib\core\createError.js:16:15)
at settle (D:\project\island\node_modules\axios\lib\core\settle.js:18:12)
at IncomingMessage.handleStreamEnd (D:\project\island\node_modules\axios\lib\adapters\http.js:202:11)
at IncomingMessage.emit (events.js:215:7)
at endReadableNT (_stream_readable.js:1183:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
请问是怎么回事?

写回答

2回答

stone2019

2020-04-07

ctx.body给浏览器返回点东西试试

0
0

7七月

2020-03-30

提供的信息看不出来问题,请提供更多信息

0
0

Node.js+Koa2+MySQL打造前后端分离精品项目《旧岛》

理解异步编程本质/培养面向对象思维,独立完成Node.js服务端开发

2223 学习 · 878 问题

查看课程