How to use the routing-controllers.useKoaServer 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 TEsTsLA / apijson / src / server.ts View on Github external
import * as koaViews from 'koa-views';
import * as path from 'path';

routingUseContainer(Container);
ormUseContainer(Container);

const koa = new Koa();
koa.use(koaViews(path.join(__dirname, 'views'), {
    options: {
        ext: 'ejs',
    },
    extension: 'ejs',
}))

// use koa app, registers all controller routes and returns you koa app instance
const app = useKoaServer(koa, {
    // controllers: [`${__dirname}/controllers/**/*{.js,.ts}`],
    controllers: [UserController, ApiJsonController] // we specify controllers we want to use
})
// creates koa app, registers all controller routes and returns you koa app instance
// const app = createKoaServer({
//     controllers: [UserController, ApiJsonController] // we specify controllers we want to use
// });
 
// run koa application on port 3000
// app.listen(3000);
const databaseInitializer = async () => createConnection().then(async connection => {
    console.log('连接成功')
}).catch(error => console.log(error));

const bootstrap = async () => {
    await databaseInitializer();
github nicolaspearson / node.api.boilerplate / src / app / KoaConfig.ts View on Github external
public async setupKoa(options: IApplicationOptions): Promise {
		this.appLogger.winston.debug(`KoaConfig: Started`);
		this.app = new Koa();

		// Setup logging
		if (options.useKoaLogger) {
			const logging: Logging = Container.get(Logging);
			logging.setupLogging(this.app);
		}

		// Setup Cors
		const cors: Cors = Container.get(Cors);

		// Initialize the Routing Controllers
		useKoaServer(this.app, this.getRoutingControllerOptions(cors));

		// Add the rest of the middleware
		this.app.use(helmet());
		this.app.use(bodyParser());
		this.appLogger.winston.debug(
			`KoaConfig: Finished: Controllers & Middleware Configured`
		);
		return this.app;
	}
github SammyLiang97 / FULL-STACK-TUTORIAL / tutorial3 / dist / demoServer.js View on Github external
exports.createServer = (PORT) => {
    const app = new Application();
    app.use(cors());
    app.use(json());
    app.use(views(__dirname + '/views'));
    routing_controllers_1.useKoaServer(app, {
        routePrefix: '/',
        controllers: [
            DemoApiController
        ]
    });
    app.listen(PORT, () => {
        console.log(`Demo Server is running on PORT: ${PORT}`);
    });
};
exports.createServer(3000);
github Lxxyx / koa2-easy / ts_template / src / app.ts View on Github external
code: ctx.status || 403,
      message: e.message,
      data: e.errors ? e.errors : {}
    }
  }
})

app.use(compress({ threshold: 2048 }))
app.use(cors())
app.use(bodyparser())
app.use(createLogger({
  timestamp: true
}))

useContainer(Container)
useKoaServer(app, {
  controllers: [__dirname + "/controllers/*.{ts,js}"],
  defaults: { paramOptions: { required: true } },
  defaultErrorHandler: false,
  middlewares: Object.values(middlewares)
})

const port = process.env.PORT ? Number(process.env.PORT) : 3000

app.listen(port)

console.log(`Now server is listen http://localhost:${port}`)
github SammyLiang97 / FULL-STACK-TUTORIAL / tutorial3 / demoServer.ts View on Github external
export const createServer = (PORT) => {
    const app = new Application()

    app.use(cors())

    app.use(json())

    app.use(views(__dirname + '/views'))




    useKoaServer(app, {
        routePrefix: '/',
        controllers: [
            DemoApiController
        ]
    })

    app.use(async(ctx: Context, next) => {
        if (ctx.req.url === '/') {
            await ctx.render('index.html')
        } else {
            await next()
        }
    })


    app.listen(PORT, () => {
github unix / koa-ts / configs / application.ts View on Github external
export const createServer = async(): Promise => {
  
  const koa: Koa = new Koa()
  
  useMiddlewares(koa)
  
  const app: Koa = useKoaServer(koa, routingConfigs)
  
  useContainer(Container)
  
  return app
}
github SammyLiang97 / Mikey / src / app.ts View on Github external
koa.use(cors())

    koa.use(jwt({
        secret: Environment.jwtSecret
    }).unless({
        path: [
            /\/api\/login/,
            /\/api\/share\/./,
            (() => {if (Environment.identity === 'development') return /\/admin\/api\/admin_user/ })()
        ]
    }))



    useKoaServer(koa, {
        routePrefix: '/api',
        controllers: [
            UserController,
            TodoController,
            HomeController,
            EvaluateController
        ],
        classTransformer: false,
        development: Environment.identity === 'development'
    })

    useKoaServer(koa, {
        routePrefix: '/admin/api',
        controllers: [
            UserAdminController,
        ],