繁体   English   中英

SailsJS-永久加载路线

[英]SailsJS - Route loading forever

我是初级laravel开发人员,我想切换到NodeJS。 我正在尝试使用SailsJS构建API,首先,我想创建一个模型实例,并将其作为JSON字符串返回。 所以:

我创建了一个新的SailsJS应用

$ sails new app
cd  Choose a template for your new Sails app:
1. Web App  ·  Extensible project with auth, login, & password recovery
2. Empty    ·  An empty Sails app, yours to configure
(type "?" for help, or <CTRL+C> to cancel)
1
 info: Installing dependencies...
Press CTRL+C to cancel.
(to skip this step in the future, use --fast)
info: Created a new Sails app `app`!

然后创建了一个新的api(以及模型和控制器)

$ sails generate api school
info: Created a new api!

这是我的config / routes.js文件,我添加了api / school路由,它重定向到SchoolController中的getSchool函数:

  module.exports.routes = {
  //  ╦ ╦╔═╗╔╗ ╔═╗╔═╗╔═╗╔═╗╔═╗
  //  ║║║║╣ ╠╩╗╠═╝╠═╣║ ╦║╣ ╚═╗
  //  ╚╩╝╚═╝╚═╝╩  ╩ ╩╚═╝╚═╝╚═╝
  'GET /':                   { action: 'view-homepage-or-redirect' },
  'GET /welcome/:unused?':   { action: 'dashboard/view-welcome' },

  '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' },
  'GET /api/school': 'SchoolController.getSchool',


  //  ╔╦╗╦╔═╗╔═╗  ╦═╗╔═╗╔╦╗╦╦═╗╔═╗╔═╗╔╦╗╔═╗   ┬   ╔╦╗╔═╗╦ ╦╔╗╔╦  ╔═╗╔═╗╔╦╗╔═╗
  //  ║║║║╚═╗║    ╠╦╝║╣  ║║║╠╦╝║╣ ║   ║ ╚═╗  ┌┼─   ║║║ ║║║║║║║║  ║ ║╠═╣ ║║╚═╗
  //  ╩ ╩╩╚═╝╚═╝  ╩╚═╚═╝═╩╝╩╩╚═╚═╝╚═╝ ╩ ╚═╝  └┘   ═╩╝╚═╝╚╩╝╝╚╝╩═╝╚═╝╩ ╩═╩╝╚═╝
  '/terms':                   '/legal/terms',
  '/logout':                  '/api/v1/account/logout',

这是api / controllers / SchoolController.js,出于测试目的,我只返回字符串“ School 123”

module.exports = {
    getSchool: function() {
        return 'School 123';
    },
};

我希望它无需登录即可工作,所以我修改了config / policies.js

module.exports.policies = {
  '*': 'is-logged-in',
  // Bypass the `is-logged-in` policy for:
  'entrance/*': true,
  'account/logout': true,
  'view-homepage-or-redirect': true,
  'deliver-contact-form-message': true,
  SchoolController: {
    'getSchool': true
  },
};

现在的问题是,当我尝试访问http:// localhost:1337 / api / school时,我期望使用字符串“ School 123”,但浏览器将永久加载,与Postman相同。 我究竟做错了什么?

提前致谢!

这是永远的,因为您没有返回任何响应,而邮递员正在等待某种响应。 查看链接

module.exports = {
    getSchool: function(req, res) {
        return res.send('School 123');
    },
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM