代码之家  ›  专栏  ›  技术社区  ›  CCCC

Feathers js-TypeError:app。get不是一个函数

  •  1
  • CCCC  · 技术社区  · 4 年前

    我想从winston logger中的配置文件(config/default.json等)中提取主机和端口。js。

    当我尝试使用应用程序时。获取('host'),发生错误。

    TypeError: app.get is not a function
    

    配置/默认值。json

    {
      "host": "localhost",
      "port": 3030,
      "public": "../public/",
      "paginate": {
        "default": 10,
        "max": 50
      },
    }
    
    

    温斯顿·洛格。js

    // How to get app.settings in this file?
    
    const app = require('./app');
    
    console.log(app.get('host'), app.get('port'));//TypeError: app.get is not a function
    
    const logger = expressWinston.logger({
      ...
    })
    
    module.exports = logger
    

    应用程序。js

    const path = require('path');
    const favicon = require('serve-favicon');
    const compress = require('compression');
    const helmet = require('helmet');
    const cors = require('cors');
    const logger = require('./logger');
    const winstonLogger = require('./winston-logger');
    
    const feathers = require('@feathersjs/feathers');
    const configuration = require('@feathersjs/configuration');
    const express = require('@feathersjs/express');
    const socketio = require('@feathersjs/socketio');
    
    
    const middleware = require('./middleware');
    const services = require('./services');
    const appHooks = require('./app.hooks');
    const channels = require('./channels');
    
    const authentication = require('./authentication');
    
    const sequelize = require('./sequelize');
    
    const app = express(feathers());
    
    // Load app configuration
    app.configure(configuration());
    // Enable security, CORS, compression, favicon and body parsing
    app.use(helmet({
      contentSecurityPolicy: false
    }));
    app.use(cors());
    app.use(compress());
    app.use(express.json({ limit: '10mb' }));
    app.use(express.urlencoded({ limit: '10mb', extended: true }));
    app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
    // Host the public folder
    app.use('/', express.static(app.get('public')));
    
    // Set-Up http request logger
    app.use(winstonLogger)
    
    // Set up Plugins and providers
    app.configure(express.rest());
    app.configure(socketio());
    
    app.configure(sequelize);
    
    // Configure other middleware (see `middleware/index.js`)
    app.configure(middleware);
    app.configure(authentication);
    // Set up our services (see `services/index.js`)
    app.configure(services);
    // Set up event channels (see channels.js)
    app.configure(channels);
    
    // Configure a middleware for 404s and the error handler
    app.use(express.notFound());
    app.use(express.errorHandler({ logger }));
    
    app.hooks(appHooks);
    
    module.exports = app;
    
    
    0 回复  |  直到 4 年前