Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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') {