How to use the swagger-ui.dist function in swagger-ui

To help you get started, we’ve selected a few swagger-ui 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 wikimedia / restbase / lib / swaggerUI.js View on Github external
"use strict";

var P = require('bluebird');
var fs = P.promisifyAll(require('fs'));
var path = require('path');
// Swagger-ui helpfully exports the absolute path of its dist directory
var docRoot = require('swagger-ui').dist + '/';
var HTTPError = require('./exports').HTTPError;

function staticServe(hyper, req) {
    var reqPath = req.query.path;

    var filePath = path.join(docRoot, reqPath);

    // Disallow relative paths.
    // Test relies on docRoot ending on a slash.
    if (filePath.substring(0, docRoot.length) !== docRoot) {
        throw new Error("Invalid path.");
    }

    return fs.readFileAsync(filePath)
    .then(function(body) {
        if (reqPath === '/index.html') {

swagger-ui

[![NPM version](https://badge.fury.io/js/swagger-ui.svg)](http://badge.fury.io/js/swagger-ui) [![Build Status](https://jenkins.swagger.io/view/OSS%20-%20JavaScript/job/oss-swagger-ui-master/badge/icon?subject=jenkins%20build)](https://jenkins.swagger.io/v

Apache-2.0
Latest version published 5 months ago

Package Health Score

86 / 100
Full package analysis