feat: drop /docs URL prefix (variant B, shorter URLs) + bump 0.0.2
This commit is contained in:
@@ -5,7 +5,7 @@ const path = require('path');
|
||||
const { S3Client, GetObjectCommand, HeadBucketCommand } = require('@aws-sdk/client-s3');
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const VERSION = process.env.APP_VERSION || '0.0.1';
|
||||
const VERSION = process.env.APP_VERSION || '0.0.2';
|
||||
const SERVICE = 'tf-docs';
|
||||
const S3_BUCKET = process.env.S3_BUCKET || '';
|
||||
const DOCS_S3_PREFIX = (process.env.DOCS_S3_PREFIX || 'docs').replace(/^\/+|\/+$/g, '');
|
||||
@@ -22,7 +22,7 @@ const s3 = new S3Client({
|
||||
});
|
||||
|
||||
function getDocsCandidates(urlPath) {
|
||||
const relativePath = decodeURIComponent(urlPath.replace(/^\/docs\/?/, ''));
|
||||
const relativePath = decodeURIComponent(urlPath.replace(/^\/+/, ''));
|
||||
const normalized = path.posix.normalize(`/${relativePath}`).replace(/^\/+|\/+$/g, '');
|
||||
if (!normalized || normalized === '.' || normalized.startsWith('../') || normalized.includes('/../')) {
|
||||
return null;
|
||||
@@ -106,23 +106,7 @@ const server = http.createServer((req, res) => {
|
||||
health(req, res);
|
||||
return;
|
||||
}
|
||||
if (req.url.startsWith('/docs/')) {
|
||||
docsHandler(req, res);
|
||||
return;
|
||||
}
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
res.end(`<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>${SERVICE}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>${SERVICE}</h1>
|
||||
<p>version: ${VERSION}</p>
|
||||
</body>
|
||||
</html>`);
|
||||
docsHandler(req, res);
|
||||
});
|
||||
|
||||
if (require.main === module) {
|
||||
|
||||
Reference in New Issue
Block a user