我正在尝试创建一个文件夹视图/圆,我可以在其中渲染数组,但是当我执行localhost:3001 / views / circle时不加载任何内容,相反,标题出现错误... ................................................... ................................................... .............
//-------I added this part in the code as you can see bellow this code-------
//const path = require("path");
//app.set("views", path.join(__dirname, "views"));
//app.set("view engine", "ejs");
//---------------------------------------------------------------------------
const express = require('express')
const path = require("path");
const cors = require('cors')
const app = express()
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(express.static('public'))
app.use(cors())
const circles = [
{
id: 1,
name: 'Twitter',
image: 'img/twitter.jpg',
color: '#aa2b31',
size: 3
},
{
id: 2,
name: 'Facebook',
image: 'img/facebook.jpg',
color: '#63e184',
size: 1
},
{
id: 3,
name: 'Skype',
image: 'img/skype.png',
color: '#033d49',
size: 2
},
]
app.get('/', (req, res) => {
const help = `
`
res.send(help)
})
app.get('/circles', (req, res) => {
res.render(circles)
})
app.listen(3001, () => {
console.log('Server listening on port 3001')
})
module.exports = app;
答案 0 :(得分:0)
在这种特定情况下,这可能无济于事,但对于搜索此错误的人来说可能是无济于事。我得到这个是因为我将路线安排不正确。我的/:id
路径在到达请求的位置之前捕获了发布请求。