当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript InversifyExpressServer.setConfig方法代码示例

本文整理汇总了TypeScript中inversify-express-utils.InversifyExpressServer.setConfig方法的典型用法代码示例。如果您正苦于以下问题:TypeScript InversifyExpressServer.setConfig方法的具体用法?TypeScript InversifyExpressServer.setConfig怎么用?TypeScript InversifyExpressServer.setConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inversify-express-utils.InversifyExpressServer的用法示例。


在下文中一共展示了InversifyExpressServer.setConfig方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: InversifyExpressServer

import 'reflect-metadata';
import { InversifyExpressServer } from 'inversify-express-utils';
import * as bodyParser from 'body-parser';
import * as helmet from 'helmet';
import { container } from './ioc/ioc';

// load all injectable entities.
// the @provide() annotation will then automatically register them.
import './ioc/loader';

// start the server
let server = new InversifyExpressServer(container);

server.setConfig((app) => {
  app.use(bodyParser.urlencoded({
    extended: true
  }));
  app.use(bodyParser.json());
  app.use(helmet());
});

let app = server.build();
app.listen(3000);
console.log('Server started on port 3000 :)');

exports = module.exports = app;
开发者ID:inversify,项目名称:inversify-express-example,代码行数:26,代码来源:bootstrap.ts

示例2: bunyanLogger

import 'reflect-metadata';
import * as routes from './routes';
import * as appInsights from 'applicationinsights';
import { InversifyExpressServer } from 'inversify-express-utils';
import { container } from './ioc/ioc-container';
import './controllers';
import { bunyanLogger } from './logger';
import { requestLogger } from './middleware';

if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY) {
  appInsights.setup();
  appInsights.start();
}

const logger = bunyanLogger();
const server = new InversifyExpressServer(container);
server.setConfig(a => {
  a.use(requestLogger(logger));
  routes.init(a);
});

const app = server.build();
app.set('port', process.env.PORT || 3001);

console.log('Going to try port ' + app.get('port'));
app.listen(app.get('port'), () => {
  console.log('Express server listening on port ' + app.get('port'));
});
开发者ID:eliakaris,项目名称:blog,代码行数:28,代码来源:server.ts

示例3: InversifyExpressServer

import {Express} from 'express-serve-static-core';

/* tslint:enable */

let server: InversifyExpressServer;
let app: Express.Application;
server = new InversifyExpressServer(kernel);

server.setConfig((exApp) => {
    exApp.use(cookieParser());
    exApp.use(bodyParser.json());
    exApp.use(bodyParser.urlencoded({extended: true}));
    exApp.use(helmet());

    exApp.use(session({
        resave: false,
        saveUninitialized: true,
        secret: 'testing',
    }));
    exApp.use(passport.initialize());
    exApp.use(passport.session()); // persistent login sessions

});


// generic Error Handler1
server.setErrorConfig((exApp) => {
    exApp.use(errorHandler);
});

app = server.build();
开发者ID:Uter1007,项目名称:sumobase.core,代码行数:31,代码来源:app.fake.ts

示例4: Kernel

/// <reference path="./inversify-express-utils.d.ts" />

import { InversifyExpressServer, Controller, Get, All, Delete, Head, Put, Patch, Post, Method, TYPE } from "inversify-express-utils";
import * as express from "express";
import { Kernel } from "inversify";

let kernel = new Kernel();

module server {

    let server = new InversifyExpressServer(kernel);

    server
        .setConfig((app: express.Application) => {
            app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
                console.log("hello world");
                next();
            });
        })
        .setErrorConfig((app: express.Application) => {
            app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
                console.error(err.stack);
                res.status(500).send("Something broke!");
            });
        })
        .build()
        .listen(3000, "localhost");
}

module decorators {
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:30,代码来源:inversify-express-utils-tests.ts

示例5: callback

let httpServer = http.createServer();

server.setConfig((app) => {

    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());
    app.use(morgan('combined'));
    app.use(cors({
        origin: (origin, callback) => {
            try {
                let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
                callback(null, ok);
            } catch (e) {
                callback(e, null);
            }

        }
    }));
    app.use(jwt({ secret: config.appSecret })
        .unless({
            path: ['/api/account/login', '/setup', '/',
                {
                    url: '/api/donors',
                    methods: ['GET', 'POST']
                }]
        }));

   let feed: DonorsFeed = kernel.get<DonorsFeed>(TYPES.DonorsFeed);
   feed.start(httpServer);
});

let app = server.build();
开发者ID:kibiluzbad,项目名称:kamrusepa,代码行数:32,代码来源:server.ts

示例6: Kernel

import { config } from './config';

let kernel = new Kernel();
kernel.load(infra, commands, queries, controllers);

let server = new InversifyExpressServer(kernel);

server.setConfig((app) => {

    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());
    app.use(morgan('combined'));
    app.use(cors({
        origin: (origin, callback) => {
            try {
                let ok: boolean = config.originsWhitelist.indexOf(origin) !== -1
                callback(null, ok);
            } catch (e) {
                callback(e, null);
            }

        }
    }));
    app.use(jwt({ secret: config.appSecret})
    .unless({path: ['/api/account/login', '/setup', '/']}));
    
});

let app = server.build();

app.listen(config.appPort);
开发者ID:marinet-web,项目名称:marinet-api,代码行数:31,代码来源:server.ts

示例7: InversifyExpressServer

    user: config.db.username,
});

process.setMaxListeners(0);

// start the server
let server = new InversifyExpressServer(kernel);
server.setConfig((app: express.Application) => {
    app.use(cookieParser());
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(helmet());

    app.use(session({ resave: false,
                      saveUninitialized: true,
                      secret: config.passwordHandler.sessionPw,
                      store: new MongoStore( {mongooseConnection: mongoose.connection})
                    }));

    app.use(passport.initialize());
    app.use(passport.session()); // persistent login sessions

    app.use('/documentation', express.static(__dirname + '/public/documentation/api'));

});

// generic Error Handler1
server.setErrorConfig((app) => {
    app.use(errorHandler);
});

let app = server.build();
开发者ID:Uter1007,项目名称:sumobase.core,代码行数:32,代码来源:app.ts

示例8: InversifyExpressServer

import "reflect-metadata";
import { createExpressServer } from "routing-controllers";
import { BookController } from './controllers/book.controller';
import * as express from 'express'
import { BootStrapper } from './bootstrapper'
import { InversifyExpressServer } from "inversify-express-utils";
import * as bodyParser from 'body-parser';

// build kernel and register dependencies
let kernel = BootStrapper.Load();

// create express server 
let server = new InversifyExpressServer(kernel);
server
    .setConfig(configureMiddleware)
    .setErrorConfig(configureGlobalErrorHandler)
    .build()
    .listen(8080, () => {'Server started on port 8080'});

function configureGlobalErrorHandler(){
    return (app) => {
        app.use((err, req, res, next) => {
            console.error(err.stack);
            res.status(500).send('Something broke!');
        });
    };
}

function configureMiddleware() {
    return (app) => {
        app.use(bodyParser.urlencoded({
开发者ID:ArminNaish,项目名称:LibraryApp,代码行数:31,代码来源:index.ts


注:本文中的inversify-express-utils.InversifyExpressServer.setConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。