SailsJS - 永远加载路由

SailsJS - Route loading forever

我是初级 laravel 开发人员,我想切换到 NodeJS。我正在尝试使用 SailsJS 构建一个 API,首先我想创建一个模型实例并将其 return 作为 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 文件,我在 SchoolController 中添加了重定向到 getSchool 函数的 api/school 路由:

  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,出于测试目的,我只是 returning 字符串 '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 一样。我做错了什么?

提前致谢!

这需要很长时间,因为您没有返回任何响应,而邮递员正在等待某种响应。查看 this link

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