简体   繁体   English

接收无法获取/错误 NodeJS 和 Express

[英]Receiving Cannot GET/ Error NodeJS and Express

I'm learning how to use NodeJS and Express, and I'm having trouble loading pages using express.我正在学习如何使用 NodeJS 和 Express,但在使用 express 加载页面时遇到了问题。 I'm able to load static pages (index.html works fine), but having trouble with anything dynamic;我能够加载静态页面(index.html 工作正常),但在处理任何动态页面时遇到问题; in this case, I keep receiving the error "Cannot GET /store.html".在这种情况下,我不断收到错误“无法获取/store.html”。 Would someone be able to explain what is happening?有人能够解释发生了什么吗?

server.js服务器.js

app.set('view engine', 'ejs')
app.use(express.static('public'))

app.get('/store', function(req, res) {
    res.render('store.ejs', {
        FOO: foo
    })
})

file structure文件结构

server.js
public
    index.html
views
    store.ejs

您应该使用 /store 来访问 store.ejs 模板而不是 /store.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM