gpt4 book ai didi

javascript - 无法获取/路由错误

转载 作者:行者123 更新时间:2023-12-03 07:37:08 25 4
gpt4 key购买 nike

我正在关注 this tutorial ( source 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文件导入注释)。

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

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

最佳答案

我是史蒂夫 - 感谢您尝试代码!

如果您使用此代码:

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。例如

/公共(public) 索引.html 史蒂夫.html

本地主机:3000/steve.html

关于javascript - 无法获取/路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35562734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com