Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import routes from './routes';
import json from './middlewares/json';
import logger, { logStream } from './utils/logger';
import * as errorHandler from './middlewares/errorHandler';
// Initialize Sentry
// https://docs.sentry.io/platforms/node/express/
Sentry.init({ dsn: process.env.SENTRY_DSN });
const app = express();
const APP_PORT =
(process.env.NODE_ENV === 'test' ? process.env.TEST_APP_PORT : process.env.APP_PORT) || process.env.PORT || '3000';
const APP_HOST = process.env.APP_HOST || '0.0.0.0';
const pathToSwaggerUi = require('swagger-ui-dist').absolutePath();
app.set('port', APP_PORT);
app.set('host', APP_HOST);
app.locals.title = process.env.APP_NAME;
app.locals.version = process.env.APP_VERSION;
// This request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
app.use(favicon(path.join(__dirname, '/../public', 'favicon.ico')));
app.use(cors());
app.use(helmet());
app.use(compression());
app.use(morgan('tiny', { stream: logStream }));
app.use(bodyParser.json());
import * as path from 'path';
import * as fs from 'fs';
import * as url from 'url';
import * as Koa from 'koa';
import * as send from 'koa-send';
// tslint:disable-next-line
const swaggerUIAbsolutePath = require('swagger-ui-dist').absolutePath();
import config from '../config';
export default () => {
const swaggerIndex = fs
.readFileSync(path.join(swaggerUIAbsolutePath, 'index.html'), { encoding: 'utf8' })
.replace('https://petstore.swagger.io/v2/swagger.json', url.resolve(config.BACKEND_URL, 'spec'));
return async (ctx: Koa.Context, next: () => Promise) => {
if (ctx.path.match(/^\/swagger\/.*$/)) {
const _path = ctx.path.replace('/swagger/', '');
if (_path === '' || _path === '/index.html') {
ctx.body = swaggerIndex;
return;
}
await send(ctx, _path, { root: swaggerUIAbsolutePath });
} else {
created() {
const route = _.defaultsDeep(mixinOptions.routeOptions, {
use: [
ApiGateway.serveStatic(SwaggerUI.absolutePath())
],
aliases: {
"GET /openapi.json"(req, res) {
// Send back the generated schema
if (shouldUpdateSchema || !schema) {
// Create new server & regenerate GraphQL schema
this.logger.info("♻ Regenerate OpenAPI/Swagger schema...");
try {
schema = this.generateOpenAPISchema();
shouldUpdateSchema = false;
this.logger.debug(schema);
export const command: Command = async() => {
log(LogCategory.Progress, 'Starting the API browser...');
const app = express();
// Add backend proxy
backendEndpoints.forEach(path => app.use(path, backend));
// Add index page
app.get(['/', '/index.html'], (_: Request, res: Response) => {
res.send(renderOpenApiHtml());
});
// Add static resources
const pathToSwaggerUi = require('swagger-ui-dist').absolutePath();
app.use(express.static(pathToSwaggerUi));
// Start the server
const server = require('http').createServer(app);
const listen = util.promisify(server.listen);
await listen.call(server, CONNECT_API_PORT, CONNECT_API_HOSTNAME);
// Log the started server url
const {address, port} = server.address();
const hostname = CONNECT_API_HOSTNAME || address;
const url = new URL(`http://${hostname}:${port}`);
log(LogCategory.Success, `The API browser is running at: ${url}`);
return () => {
log(LogCategory.Progress, 'Stopping the API browser...');
// Cleanup
const config_1 = require("./config");
const fs = require("fs");
const url = require("url");
const path = require("path");
const knex = require("knex");
const Koa = require("koa");
const bodyParser = require("koa-bodyparser");
const cors = require("kcors");
const send = require("koa-send");
const Router = require("koa-router");
const objection_1 = require("objection");
objection_1.Model.knex(knex(config_1.default.DATABASE));
const jwt = require("jsonwebtoken");
const yaml = require("yamljs");
// tslint:disable-next-line
const swaggerUIAbsolutePath = require('swagger-ui-dist').absolutePath();
const routes_1 = require("./authentication/jwt/routes");
const middleware_1 = require("./authentication/jwt/middleware");
const ProjectViewSet_1 = require("./viewsets/ProjectViewSet");
const UserViewSet_1 = require("./viewsets/UserViewSet");
const ClientViewSet_1 = require("./viewsets/ClientViewSet");
const WebHookViewSet_1 = require("./viewsets/WebHookViewSet");
const ProjectInviteViewSet_1 = require("./viewsets/ProjectInviteViewSet");
const MediaViewSet_1 = require("./viewsets/MediaViewSet");
const MediaTagViewSet_1 = require("./viewsets/MediaTagViewSet");
const EntryTypeViewSet_1 = require("./viewsets/EntryTypeViewSet");
const EntryViewSet_1 = require("./viewsets/EntryViewSet");
const EntryTagViewSet_1 = require("./viewsets/EntryTagViewSet");
const Client_1 = require("./models/Client");
const Entry_1 = require("./models/Entry");
const EntryTag_1 = require("./models/EntryTag");
const EntryType_1 = require("./models/EntryType");
import * as expressWinston from "express-winston";
import * as cors from "cors";
import * as connector from "./routes/connector";
import * as events from "./routes/events";
import * as remoteApis from "./routes/remoteApis";
import * as localApis from "./routes/localApis";
import * as config from "@varkes/configuration"
const VARKES_LOGO = path.resolve(__dirname, 'resources/logo.svg')
const LOGO_URL = "/logo";
const LOCAL_APIS_URL = "/local";
const REMOTE_APIS_URL = "/remote/apis";
const EVENTS_URL = "/events";
const CONNECTION = "/connection";
const BATCH_REGISTRATION = "/local/registration";
const pathToSwaggerUI = require("swagger-ui-dist").absolutePath()
const LOGGER = config.logger("api-server")
async function init(config: config.Config) {
let app = express()
app.use(bodyParser.json())
app.use(cors())
app.options('*', cors())
app.use(expressWinston.logger(LOGGER))
app.use(REMOTE_APIS_URL, remoteApis.router())
app.use(LOCAL_APIS_URL, localApis.router(config))
app.use(CONNECTION, connector.router())
app.use(EVENTS_URL, events.router())
app.use("/swagger-ui", express.static(pathToSwaggerUI))
app.get("/info", function (req, res) {
#!/usr/bin/env node
'use strict'
import * as bodyParser from "body-parser"
import { mock } from "./mock"
import * as express from "express"
import * as config from "@varkes/configuration"
import * as morgan from "morgan"
import * as fs from "fs"
const LOGGER = config.logger("openapi-mock")
const pathToSwaggerUI = require("swagger-ui-dist").absolutePath()
async function init(config: config.Config) {
let app = express()
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))
registerLogger(app);
app.use(await mock(config))
app.use("/swagger-ui", express.static(pathToSwaggerUI))
customErrorResponses(app)
return app;
}
import {ControllerProvider, ControllerService, EndpointMetadata, ExpressApplication, ServerSettingsService, Service} from "@tsed/common";
import {deepExtends, nameOf, Store} from "@tsed/core";
import * as Express from "express";
import * as Fs from "fs";
import * as PathUtils from "path";
import {Schema, Spec, Tag} from "swagger-schema-official";
import {$log} from "ts-log-debug";
import {OpenApiEndpointBuilder} from "../class/OpenApiEndpointBuilder";
import {ISwaggerPaths, ISwaggerSettings, ISwaggerSpec} from "../interfaces";
import {getReducers} from "../utils";
const swaggerUiPath = require("swagger-ui-dist").absolutePath();
const ejs = require("ejs");
@Service()
export class SwaggerService {
constructor(
private controllerService: ControllerService,
private serverSettingsService: ServerSettingsService,
@ExpressApplication private expressApplication: Express.Application
) {
(this as any).rand = Math.random();
}
/**
*
*/
$afterRoutesInit() {
import {AfterRoutesInit, ExpressApplication, OnServerReady, ServerSettingsService, Service} from "@tsed/common";
import * as Express from "express";
import * as Fs from "fs";
import * as PathUtils from "path";
import {$log} from "ts-log-debug";
import {ISwaggerSettings} from "./interfaces";
import {SwaggerService} from "./services/SwaggerService";
const swaggerUiPath = require("swagger-ui-dist").absolutePath();
const ejs = require("ejs");
@Service()
export class SwaggerModule implements AfterRoutesInit, OnServerReady {
constructor(
private swaggerService: SwaggerService,
private serverSettingsService: ServerSettingsService,
@ExpressApplication private expressApplication: Express.Application
) {}
/**
*
*/
$afterRoutesInit() {
const swagger: ISwaggerSettings[] = [].concat(this.serverSettingsService.get("swagger")).filter(o => !!o);
module.exports = (config = {}) => {
if (config.title === undefined) {
config.title = 'nanoexpress - Swagger UI';
}
if (config.path === undefined) {
config.path = '/docs';
}
if (config.fsPath === undefined) {
config.fsPath = absolutePath();
}
const fn = async (req, res) => {
if (config.url === undefined) {
config.url = `//${
req.headers !== undefined ? req.headers.host : req.getHeader('host')
}/docs/swagger.json`;
}
if (req.path.indexOf('/swagger-ui') !== -1) {
return res.sendFile(
`${config.fsPath}${req.path.substr(req.path.lastIndexOf('/'))}`
);
} else if (req.path === config.path) {
return res.end(`