无法GET /路由错误

时间:2016-02-22 20:02:09

标签: javascript node.js express routes evernote

我关注this tutorialsource code)并添加了突出显示的代码。

// app.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', {});
});

我在index.html附近创建了importNotes.html。

使用node app.js启动服务器后 我收到错误声明Cannot GET /importNotes  当我访问localhost:3000/importNotes

我计划在处理此问题后使用此页面添加其他功能(从特殊txt文件导入备注)。

我做错了什么以及如何纠正错误?

如何正确定义所需的路线?

1 个答案:

答案 0 :(得分:1)

这是史蒂夫 - 感谢你试用代码!

如果您使用此代码:

app.get('/importNotes', function (req, res) {
    res.send('importNotes');
});

然后我希望服务器将字符串“importNotes”发送回浏览器。也许如果你有一个名为“importNotes”的文件就会有一些混乱。

如果要创建名为importNotes.html的文件,请将其放入“public”文件夹中。然后可以通过localhost:3000 / importNotes.html

访问它

该行:

app.use(express.static(__dirname + "/public"));

告诉Express在应用程序的根级别提供“public”文件夹的内容,因此您放在该文件夹中的任何文件都应该是GETable。 e.g。

/公共    的index.html    steve.html

本地主机:3000 / steve.html

相关问题