當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript inversify-express-utils.InversifyExpressServer類代碼示例

本文整理匯總了TypeScript中inversify-express-utils.InversifyExpressServer的典型用法代碼示例。如果您正苦於以下問題:TypeScript InversifyExpressServer類的具體用法?TypeScript InversifyExpressServer怎麽用?TypeScript InversifyExpressServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了InversifyExpressServer類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Container

(async () => {

    const port = 3000;
    const container = new Container();
    await container.loadAsync(bindings);
    const app = new InversifyExpressServer(container);
    const server = app.build();
    
    server.listen(port, () => {
        console.log(`Server running at http://127.0.0.1:${port}/`)
    });

})();
開發者ID:inversify,項目名稱:inversify-express-example,代碼行數:13,代碼來源:index.ts

示例2: express

export const buildApp = () => {
  const newApp = express();
  newApp.use(bodyParser.json());
  newApp.use(bodyParser.urlencoded({ extended: false }));

  const server = new InversifyExpressServer(container, null, null, newApp);
  server.setErrorConfig((app) => {
    app.use((req: Request, res: Response, next: NextFunction) => {
      res.status(404).send({
        statusCode: 404,
        error: 'Route is not found'
      });
    });

    app.use((err: Error, req: Request, res: Response, next: NextFunction) => handle(err, req, res, next));
  });

  return server.build();
};
開發者ID:Norestlabs-Mariya,項目名稱:backend-ico-dashboard,代碼行數:19,代碼來源:test.app.factory.ts

示例3: 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

示例4: require

import * as bodyParser from 'body-parser';
import * as cookieParser from 'cookie-parser';
import * as helmet from 'helmet';
import * as passport from 'passport';
import {Strategy} from 'passport-local';

import errorHandler = require('../../../../core/error/middleware/error.handler.logic');
import notFoundHandler = require('../../../../core/error/middleware/notfound.handler.logic');

import kernel from '../helper/user.kernel.test.helper';
import {PassportMiddleware} from '../../../../core/authenticate/middleware/passport.middleware';
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());
開發者ID:Uter1007,項目名稱:sumobase.core,代碼行數:31,代碼來源:app.fake.ts

示例5: 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

示例6: Kernel

import 'reflect-metadata';
import { Kernel, injectable } from 'inversify';
import * as express from 'express';
import * as morgan from 'morgan';
import { interfaces, InversifyExpressServer, TYPE, Get, Controller } from 'inversify-express-utils';
import { controllerFactory } from './controller';

let kernel = new Kernel();

kernel.bind<express.RequestHandler>('Morgan').toConstantValue(morgan('combined'));
kernel.bind<express.RequestHandler>('CustomMiddleware').toConstantValue(function customMiddleware(req: any, res: any, next: any) {
    req.user = {
        username: 'foo',
        password: 'bar'
    };
    next();
});

let controller = controllerFactory(kernel);
kernel.bind<interfaces.Controller>(TYPE.Controller).to(controller).whenTargetNamed('TestController');

let server = new InversifyExpressServer(kernel);
server.build().listen('3000', () => {console.log('Listening on port 3000')});
開發者ID:codyjs,項目名稱:inversify-express-example,代碼行數:23,代碼來源:main.ts

示例7: index

import { injectable, inject } from 'inversify';

@Controller('/')
@injectable()
class RootController {
  @Get('/')
  private index(req: express.Request): string {
    return 'indexi';
  }

  @Get('/async')
  private async(req: express.Request, res: express.Response) {
    setTimeout(() => {
      res.status(200).json({
        success: true
      });
    }, 1000);
  }
}

import { Kernel } from 'inversify';
import { InversifyExpressServer } from 'inversify-express-utils';

const kernel = new Kernel();
kernel.bind<RootController>('RootController').to(RootController);

const server = new InversifyExpressServer(kernel);

const app: express.Application = server.build();
app.listen(3000);
開發者ID:m-abs,項目名稱:testing-inversify-express-utils,代碼行數:30,代碼來源:index.ts

示例8: 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

示例9: Kernel

import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import * as jwt from 'express-jwt';

import { commands, controllers, infra, queries } from './bootstrap';
import { config } from './config';

import { DonorsFeed } from './donors-feed';
import { TYPES } from './lib/types';

import * as http from 'http';

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

let server = new InversifyExpressServer(kernel);

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);
開發者ID:kibiluzbad,項目名稱:kamrusepa,代碼行數:31,代碼來源:server.ts

示例10: Container

import 'reflect-metadata';
import { InversifyExpressServer } from 'inversify-express-utils';
import { Container } from 'inversify';
import * as bodyParser from 'body-parser';
import TYPES from './constant/types';
import { UserService } from './service/user';
import './controller/home';
import './controller/user';

// load everything needed to the Container
let container = new Container();
container.bind<UserService>(TYPES.UserService).to(UserService);

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

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

let serverInstance = server.build();
serverInstance.listen(3000);

console.log('Server started on port 3000 :)');
開發者ID:inversify,項目名稱:inversify-express-example,代碼行數:27,代碼來源:bootstrap.ts

示例11: Kernel

import 'reflect-metadata';
import { Controller, InversifyExpressServer, TYPE } from 'inversify-express-utils';
import { Kernel } from 'inversify';
import * as morgan from 'morgan';
import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import * as jwt from 'express-jwt';
import * as guard from 'express-jwt-permissions';

import { commands, controllers, infra, queries } from './bootstrap';
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);
            }
開發者ID:marinet-web,項目名稱:marinet-api,代碼行數:30,代碼來源:server.ts

示例12: next

  if (
    !req.header('Content-Type') ||
    (req.header('Content-Type') !== 'application/json' && !req.header('Content-Type').includes('application/x-www-form-urlencoded'))
  ) {
    return res.status(406).json({
      error: 'Unsupported "Content-Type"'
    });
  }

  return next();
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

let server = new InversifyExpressServer(container, null, null, app);
server.setErrorConfig((app) => {
  // 404 handler
  app.use((req: Request, res: Response, next: NextFunction) => {
    res.status(404).send({
      statusCode: 404,
      error: 'Route is not found'
    });
  });

  // exceptions handler
  app.use((err: Error, req: Request, res: Response, next: NextFunction) => handle(err, req, res, next));
});

export default server.build();
開發者ID:Norestlabs-Mariya,項目名稱:backend-ico-dashboard,代碼行數:30,代碼來源:app.ts

示例13: InversifyExpressServer

import {ConfigLoader} from './modules/core/configloader/configloader.service';
import {PassportMiddleware} from './modules/core/authenticate/middleware/passport.middleware';
import {Strategy} from 'passport-local';

const config = ConfigLoader.getConfig();

mongoose.connect(config.db.uri, {
    pass: config.db.password,
    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
開發者ID:Uter1007,項目名稱:sumobase.core,代碼行數:29,代碼來源:app.ts

示例14: 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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。