How to use the typescript-rest.Server.buildServices function in typescript-rest

To help you get started, we’ve selected a few typescript-rest 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 vellengs / typerx / server / api.server.ts View on Github external
constructor() {
        this.app = express();
        this.config();

        mongoose.connect(config.db, {
            useMongoClient: true,
        });
        const db = mongoose.connection;
        autoIncrement.initialize(db);

        db.on('error', (err: any) => {
            throw new Error('unable to connect to database at ' + config.db + err);
        });

        Server.buildServices(this.app, ...controllers);
        // TODO: enable for Swagger generation error
        // Server.loadServices(this.app, 'controllers/*', __dirname);
        Server.swagger(this.app, './dist/swagger.json', '/api-docs', 'localhost:' + this.PORT, ['http']);

        this.app.use((
            err: any,
            req: express.Request,
            res: express.Response, next: any) => {
            if (res.headersSent) {
                return next(err);
            }
            if (err && err.statusCode) {
                res.status(err.statusCode);
            } else {
                res.status(500);
            }
github TreeGateway / tree-gateway / src / lib / gateway.ts View on Github external
private configureAdminServer() {
        this.adminApp = express();
        this.adminApp.disable('x-powered-by'); 
        this.adminApp.use(compression());
        if (this.config.adminLogger) {
            if (!this.config.disableAdminStats) {
                this.configureStatsMiddleware(this.adminApp, 'admin');
            }
            AccessLogger.configureAccessLoger(this.config.adminLogger, 
                        this, this.adminApp, './logs/admin');
        }
        
        AdminServer.gateway = this;

        Server.buildServices(this.adminApp, ...adminApi);
    }
github Soluto / tweek / services / authoring / src / routes / index.ts View on Github external
{ from: 'manifests', to: 'manifest' },
    { from: 'revision-history', to: 'revision-history' },
    { from: 'dependents', to: 'dependent' },
    { from: 'resource/policy', to: 'resource/policy' },
  ];

  prefixes.forEach((prefix) => {
    app.all(`/${prefix.from}/*`, (req, res, next) => {
      req.query['keyPath'] = req.params[0];
      req.url = `/${prefix.to}`;
      next();
    });
  });

  Server.setFileDest('uploads/');
  Server.buildServices(
    app,
    AppsController,
    TagsController,
    SearchController,
    BulkKeysUpload,
    SchemaController,
    KeysController,
    PolicyController,
    ResourcePolicyController,
    SubjectExtractionRulesController,
  );

  return app;
}