【问题标题】:Loopback is not defined环回未定义
【发布时间】:2018-10-01 21:18:37
【问题描述】:

Web 服务器监听:http://localhost:3000http://localhost:3000/explorer 浏览您的 REST API D:\PPL\Laundry\Front\api\node_modules\mysql\lib\protocol\Parser.js:80 抛出错误; // 重新抛出非 MySQL 错误 ^

ReferenceError: 环回未定义

【问题讨论】:

    标签: loopback


    【解决方案1】:
    Please add this line to fix this Error
    
        var loopback = require('loopback');
    

    【讨论】:

      【解决方案2】:
      'use strict';
      
      var loopback = require('loopback');
      var boot = require('loopback-boot');
      
      var app = module.exports = loopback();
      
      app.use(function(req, res, next) {
        var allowedOrigins = [
          'http://localhost',
          'http://localhost:3000',
          'http://127.0.0.1',
          'http://127.0.0.1:3000',
        ];
        var origin = req.headers.origin;
        if (allowedOrigins.indexOf(origin) > -1) {
          res.setHeader('Access-Control-Allow-Origin', origin);
        }
        res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
        res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
        res.header('Access-Control-Allow-Credentials', true);
        next();
      });
      
      app.start = function() {
        // start the web server
        return app.listen(function() {
          app.emit('started');
          var baseUrl = app.get('url').replace(/\/$/, '');
          console.log('Web server listening at: %s', baseUrl);
          if (app.get('loopback-component-explorer')) {
            var explorerPath = app.get('loopback-component-explorer').mountPath;
            console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
          }
        });
      };
      
      // Bootstrap the application, configure models, datasources and middleware.
      // Sub-apps like REST API are mounted via boot scripts.
      boot(app, __dirname, function(err) {
        if (err) throw err;
      
        // start the server if `$ node server.js`
        if (require.main === module)
          app.start();
      });
      

      这可能是一个示例server.js。请确保引用了loopback 模块。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-05
        • 2012-11-29
        • 2019-01-08
        • 2016-06-19
        • 2013-02-19
        相关资源
        最近更新 更多