1
0
Fork 0

Fix swagger static path resolution

This commit is contained in:
Alan Plum 2016-11-15 18:08:05 +01:00
parent 295e0ea19c
commit 57cd82f88c
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
2 changed files with 5 additions and 4 deletions

View File

@ -25,6 +25,7 @@
var _ = require('lodash');
var fs = require('fs');
var joinPath = require('path').join;
var resolvePath = require('path').resolve;
var internal = require('internal');
var ArangoError = require('@arangodb').ArangoError;
var errors = require('@arangodb').errors;
@ -93,12 +94,10 @@ function createSwaggerRouteHandler (defaultAppPath, opts) {
}
function swaggerPath (path, basePath) {
if (path.charAt(0) === '/') {
return path;
}
if (!basePath) {
basePath = joinPath(internal.startupPath, 'server', 'assets', 'swagger');
}
path = resolvePath('/', path);
return joinPath(basePath, path);
}

View File

@ -25,6 +25,7 @@
const NotFound = require('http-errors').NotFound;
const fs = require('fs');
const joinPath = require('path').join;
const resolvePath = require('path').resolve;
const internal = require('internal');
const errors = require('@arangodb').errors;
const FoxxManager = require('@arangodb/foxx/manager');
@ -101,7 +102,8 @@ module.exports = function createSwaggerRouteHandler (foxxMount, opts) {
} else if (path === 'index.html') {
path = indexFile;
}
const filePath = path.charAt(0) === '/' ? path : joinPath(swaggerRoot, path);
path = resolvePath('/', path);
const filePath = joinPath(swaggerRoot, path);
if (!fs.isFile(filePath)) {
throw new NotFound(`unknown path "${req._raw.url}"`);
}