mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 13:44:54 +03:00
properly handling relative paths
This commit is contained in:
parent
35ac32fe49
commit
6c410cb734
|
@ -6,7 +6,7 @@ import { ServerStyleSheet } from 'styled-components';
|
||||||
|
|
||||||
import { compile } from 'handlebars';
|
import { compile } from 'handlebars';
|
||||||
import { createServer, IncomingMessage, ServerResponse } from 'http';
|
import { createServer, IncomingMessage, ServerResponse } from 'http';
|
||||||
import { dirname, join, resolve } from 'path';
|
import { dirname, join, resolve, normalize, relative } from 'path';
|
||||||
import { lookup } from 'mime-types';
|
import { lookup } from 'mime-types';
|
||||||
|
|
||||||
import * as zlib from 'zlib';
|
import * as zlib from 'zlib';
|
||||||
|
@ -202,8 +202,9 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (options.static && options.static !== '' && request.url?.startsWith('/' + options.static)) {
|
const filePath = normalize(join(dirname(pathToSpec), request.url || ''));
|
||||||
const filePath = join(dirname(pathToSpec), request.url);
|
const relativePath = relative(dirname(pathToSpec), filePath);
|
||||||
|
if (options.static && options.static !== '' && relativePath.startsWith(options.static)) {
|
||||||
const file = createReadStream(filePath);
|
const file = createReadStream(filePath);
|
||||||
file.on('open', function () {
|
file.on('open', function () {
|
||||||
response.setHeader('Content-Type', lookup(filePath) || 'text/plain');
|
response.setHeader('Content-Type', lookup(filePath) || 'text/plain');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user