How to use the typescript-rest.Server.swagger 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
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);
            }
            res.send({ error: err });
        });
    }
github vellengs / typerx / packages / server / src / application.ts View on Github external
private hostSwaggerDocs() {
    const swaggerPath = process.env.SWAGGER;
    if (existsSync(path.resolve(process.env.SWAGGER))) {
      Server.swagger(
        this.app,
        swaggerPath,
        '/docs',
        'localhost:' + this.PORT,
        ['http', 'https'],
      );
    }
  }