Sails.js从API查看信息
我刚开始对Sails.JS感兴趣 我正在遵循Traversy Media的教育指南。在本指南中,在他生成一个API并通过Sails.js从API查看信息,sails.js,Sails.js,我刚开始对Sails.JS感兴趣 我正在遵循Traversy Media的教育指南。在本指南中,在他生成一个API并通过localhost:1337/articles访问之前,一切都很顺利。 我无法访问此文件,只能获得404页,因此我在internet上搜索帮助。我发现我需要将/articles添加到config/routes.js中,但我还没有弄清楚在操作部分中放置什么。 在Traversy Sails.JS教程中,它显示了我无法浏览到的部分。 有人能帮忙吗?提前谢谢 ArticlesCont
localhost:1337/articles
访问之前,一切都很顺利。
我无法访问此文件,只能获得404页,因此我在internet上搜索帮助。我发现我需要将/articles
添加到config/routes.js
中,但我还没有弄清楚在操作部分中放置什么。
在Traversy Sails.JS教程中,它显示了我无法浏览到的部分。
有人能帮忙吗?提前谢谢
ArticlesController.js
文件是默认文件
Myroutes.js
:
module.exports.routes = {
'GET /': { action: 'view-homepage-or-redirect' },
'GET /welcome': { action: 'dashboard/view-welcome' },
'GET /articles': { action: 'view-Articles' },
'GET /faq': { view: 'pages/faq' },
'GET /legal/terms': { view: 'pages/legal/terms' },
'GET /legal/privacy': { view: 'pages/legal/privacy' },
'GET /contact': { view: 'pages/contact' },
'GET /signup': { action: 'entrance/view-signup' },
'GET /email/confirm': { action: 'entrance/confirm-email' },
'GET /email/confirmed': { view: 'pages/entrance/confirmed-email' },
'GET /login': { action: 'entrance/view-login' },
'GET /password/forgot': { action: 'entrance/view-forgot-password' },
'GET /password/new': { action: 'entrance/view-new-password' },
'GET /account': { action: 'account/view-account-overview' },
'GET /account/password': { action: 'account/view-edit-password' },
'GET /account/profile': { action: 'account/view-edit-profile' },
'/api/v1/account/logout': { action: 'account/logout' },
'PUT /api/v1/account/update-password': { action: 'account/update-password' },
'PUT /api/v1/account/update-profile': { action: 'account/update-profile' },
'PUT /api/v1/account/update-billing-card': { action: 'account/update-billing-card' },
'PUT /api/v1/entrance/login': { action: 'entrance/login' },
'POST /api/v1/entrance/signup': { action: 'entrance/signup' },
'POST /api/v1/entrance/send-password-recovery-email': { action: 'entrance/send-password-recovery-email' },
'POST /api/v1/entrance/update-password-and-login': { action: 'entrance/update-password-and-login' },
'POST /api/v1/deliver-contact-form-message': { action: 'deliver-contact-form-message' },
'/terms': '/legal/terms',
'/logout': '/api/v1/account/logout',
};
Blueprints is also default
如果你有兴趣
config/blueprints.js
module.exports.blueprints = {
actions: true,
rest: false,
shortcuts: true,
};
和一些动作(方法),例如
module.exports = {
hello: function(req, res) {
return res.json('ok');
}
}
您应该能够通过url查看“ok”,网址是:1337/Article/hello
您有Articles控制器吗?请发布其代码,也请发布config/blueprints.js和config/routes.js(最好不要评论)是的,我有一篇文章controllera,请检查一下,您在sails上使用的版本是否与视频中相同。最新版本是1,但视频大约是0.12。我也注意到了这一点。但是我仍然对我需要如何访问API感到困惑仍然得到了404是的,他们都工作,只是文章一个不工作,我使用nodemon检查任何更改。我试过sails lift和nodemon app.js如果你说,其他路线好,这意味着这是关于iti中的控制器或操作的事情,我只需要能够看到数据库中的文章