无法获取/路由错误
Cannot GET /the route Error
我正在按照本教程(源代码)并添加了突出显示的代码。
应用程序.js
app.get("/notebooks", function(req, res) {
var client = new Evernote.Client({ token: req.session.oauthAccessToken }),
noteStore = client.getNoteStore();
noteStore.listNotebooks(function(err, noteBooks) {
res.send(err || noteBooks);
});
});
app.get('/importNotes', function (req, res) {
res.send('importNotes');
});
app.get("/notes/:guid", function(req, res) {
var client = new Evernote.Client({ token: req.session.oauthAccessToken }),
noteStore = client.getNoteStore();
noteStore.getNote(req.params.guid, true, true, true, true, function(err, note) {
if (!err) {
note.content = ENML.HTMLOfENML(note.content, note.resources);
}
res.send(err || note);
});
});
另一个尝试:
app.get('/importNotes', function (req, res) {
res.render('importNotes', {});
});
我创建了importNotes.html靠近index.html。
使用 node app.js
启动服务器后我收到一条错误消息,指出Cannot GET /importNotes
当我访问localhost:3000/importNotes
我计划在处理此问题后使用此页面添加其他功能(从特殊的txt文件中导入注释)。
我做错了什么,我该如何纠正?
如何正确定义所需的路线?
这是史蒂夫 - 感谢您尝试代码!
如果您使用此代码:
app.get('/importNotes', function (req, res) {
res.send('importNotes');
});
然后我希望服务器会将字符串"importNotes"发送回浏览器。 也许如果你有一个名为"importNotes"的文件,就会有一些混乱。
如果你想创建一个名为importNotes.html的文件 - 那么只需将其放入"公共"文件夹中即可。 然后可以通过 localhost:3000/importNotes.html 访问它
行 :
app.use(express.static(__dirname + "/public"));
告知 Express 在应用程序的根级别提供"公共"文件夹的内容,因此放入该文件夹中的任何文件都应该是可 GETable。 例如
/公共 索引.html 史蒂夫.html
localhost:3000/steve.html
相关文章:
- Angular2路由错误/缺少组件
- Rails4:资产管道(javascripts)路由错误
- 404 Angularjs TemplateUrl路由错误
- Yii 2路由错误
- 大视频.js在 Rails 路由错误中
- 使用 jQuery 的 angularjs 应用程序中的路由错误
- 无法获取/路由错误
- html5mode 中的 AngularJS 路由错误
- 路由错误:错误:发送标头后无法设置标头
- 角度 2 页面路由错误
- 使用正斜杠加载页面时出现主干路由错误
- 服务器在ajax调用上返回空响应可能是路由错误
- Ember.js转换渲染错误或路由错误
- angular.js和express的路由错误
- Angular.js 404路由错误
- expressjs中的路由错误
- 灵活和Navlink路由错误
- 使用expressjs和对象构造函数路由错误
- AngularJS中的路由错误
- 删除的AJAX路由错误.为什么索引页出现DELETE路由错误