老師您好,跟著影片打代碼執行 npm run dev 出現404的訊息,以下是我的 server.js 檔案,不太確定是什麼問題造成的,想請老師看看
錯誤訊息
server.js
const Koa = require('koa')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare().then(() => {
const server = new Koa()
server.use(async (ctx, next) => {
await handle(ctx.req, ctx.res)
ctx.respond = false
})
server.listen(3000, () => {
console.log('koa server listening on 3000')
})
})
package.json 檔
{
"name": "nextjs-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node server.js",
"buid": "next build",
"start": "next start"
},
"repository": {
"type": "git",
"url": "git+https://github.com/elftvxq/nextjs-project.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/elftvxq/nextjs-project/issues"
},
"homepage": "https://github.com/elftvxq/nextjs-project#readme",
"dependencies": {
"koa": "^2.13.0",
"next": "^10.0.4",
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
}
学习React/Next.js服务端渲染SSR同构设计方案,理解OAuth登录体系的实现原理
了解课程