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


TypeScript InversifyExpressServer.build方法代码示例

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


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

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

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

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

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


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