How to use the routing-controllers.createExpressServer function in routing-controllers

To help you get started, we’ve selected a few routing-controllers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shanmugharajk / react-point-of-sale / api / src / index.ts View on Github external
async function createServer(): Promise {
  try {
    await openConnection();

    // its important to set container before any operation you do with routing-controllers,
    // including importing controllers
    useContainer(Container);

    const app: Application = createExpressServer({
      authorizationChecker: authorizationChecker,
      cors: true,
      routePrefix: '/api',
      defaultErrorHandler: false,
      middlewares: [__dirname + '/middlewares/**/*{.ts,.js}'],
      controllers: [__dirname + '/controllers/**/*{.ts,.js}']
    });

    const port = process.env.PORT || 3500;

    app.listen(port, () => {
      console.log(`server started at ${port}`);
    });
  } catch (error) {
    console.log(error);
  }
github ktanakaj / typeorm-example / typeorm-example / src / index.ts View on Github external
createConnection(options).then(() => {
	// Expressサーバー作成
	const app = createExpressServer({
		routePrefix: '/api',
		controllers: [__dirname + '/controllers/*.js'],
		middlewares: [__dirname + '/middlewares/*.js'],
	});

	// log4jsでアクセスログ出力設定
	app.use(log4js.connectLogger(log4js.getLogger('access'), {
		level: 'auto',
		nolog: config['noaccesslog'],
	}));

	// API検証用のswagger設定
	if (app.get('env') === 'development') {
		app.get('/api-docs.json', handleSwaggerApi);
	}
github typeorm / typeorm-routing-controllers-extensions / sample / sample1-simple-usage / app.ts View on Github external
}).then(async connection => {

    console.log("Connected. Now run express app");
    createExpressServer({
        controllers: [PostController]
    }).listen(3000);
    console.log("Server is up and running on port 3000. Now send requests to check if everything works.");

}).catch(error => console.log("Error: ", error));
github pleerock / routing-controllers-express-demo / src / app.ts View on Github external
import "reflect-metadata";
import {createExpressServer, useContainer, useExpressServer} from "routing-controllers";
import {Container} from "typedi";
import {CategoryController} from "./controllers/CategoryController";
import {PostController} from "./controllers/PostController";

/**
 * Setup routing-controllers to use typedi container.
 */
useContainer(Container);

/**
 * We create a new express server instance.
 * We could have also use useExpressServer here to attach controllers to an existing express instance.
 */
const expressApp = createExpressServer({
    /**
     * We can add options about how routing-controllers should configure itself.
     * Here we specify what controllers should be registered in our express server.
     */
    controllers: [
        CategoryController,
        PostController
    ]
});

/**
 * Start the express app.
 */
expressApp.listen(3000);

console.log("Server is up and running at port 3000");
github jmaicaaan / express-starter-ts / src / app.ts View on Github external
import { createExpressServer, useContainer } from 'routing-controllers';
import { Container } from 'typedi';
import { IntroController, UserController } from './controllers/index';
import 'reflect-metadata';


useContainer(Container);

const app = createExpressServer({
  controllers: [
    IntroController,
    UserController,
  ]
});
const port = process.env.PORT || 1111;

app.listen(port, () => {
  console.log(`The server is starting at http://localhost:${port}`);
});
github jmaicaaan / express-starter-ts / dist / app.js View on Github external
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var routing_controllers_1 = require("routing-controllers");
var typedi_1 = require("typedi");
var index_1 = require("./controllers/index");
require("reflect-metadata");
routing_controllers_1.useContainer(typedi_1.Container);
var app = routing_controllers_1.createExpressServer({
    controllers: [
        index_1.IntroController,
        index_1.UserController,
        index_1.TestController
    ]
});
var port = process.env.PORT || 1111;
app.listen(port, function () {
    console.log("The server is starting at http://localhost:" + port);
});
//# sourceMappingURL=app.js.map
github w3tecch / express-typescript-boilerplate / src / loaders / expressLoader.ts View on Github external
export const expressLoader: MicroframeworkLoader = (settings: MicroframeworkSettings | undefined) => {
    if (settings) {
        const connection = settings.getData('connection');

        /**
         * We create a new express server instance.
         * We could have also use useExpressServer here to attach controllers to an existing express instance.
         */
        const expressApp: Application = createExpressServer({
            cors: true,
            classTransformer: true,
            routePrefix: env.app.routePrefix,
            defaultErrorHandler: false,
            /**
             * We can add options about how routing-controllers should configure itself.
             * Here we specify what controllers should be registered in our express server.
             */
            controllers: env.app.dirs.controllers.map(controller => path.join(process.cwd(), controller)),
            middlewares: env.app.dirs.middlewares.map(middleware => path.join(process.cwd(), middleware)),
            interceptors: env.app.dirs.interceptors.map(interceptor => path.join(process.cwd(), interceptor)),

            /**
             * Authorization features
             */
            authorizationChecker: authorizationChecker(connection),
github jmaicaaan / express-starter-ts / src / utils / bootstrap-server.ts View on Github external
public bootApp() {
    if (this.app) {
      return this.app;
    }

    const express = createExpressServer({
      controllers: [ __dirname + '/../controllers/**/*.controller.js' ],
      authorizationChecker
    });

    this.app = express;
    return this.app;
  }
github jmaicaaan / express-starter-ts / src / app / app.ts View on Github external
public constructor() {
    useContainer(Container);
    this.application = createExpressServer({
      routePrefix: '/api',
      controllers: [ __dirname + '/../app/controllers/**/*.controller.js' ],
      middlewares: [ __dirname + '/../app/middlewares/*.middleware.js' ],
      authorizationChecker
    });
  }