无法获取/路由错误

Cannot GET /the route Error

本文关键字:路由 错误 获取      更新时间:2023-09-26

我正在按照本教程(源代码)并添加了突出显示的代码。

应用程序.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