Skip to content

Commit

Permalink
Add missing http headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Sep 23, 2023
1 parent 599ef14 commit 5978f41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/containers/server/routes/FolderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const extToMime = {
'mjs': 'application/javascript',
'css': 'text/css',
'txt': 'text/plain',
'md': 'text/plain',
'md': 'text/x-markdown',
'htm': 'text/html',
'html': 'text/html',
'svg': 'image/svg+xml'
Expand Down Expand Up @@ -330,13 +330,25 @@ export default class FolderController extends Controller {
return;
} else {
const ext = await transformedFileSystem.guessExtension(filePath);
const mimeType = extToMime[ext];

const mimeType = extToMime[ext] || (isTextFileName(filePath) ? 'text/plain' : undefined);
if (mimeType) {
this.res.setHeader('Content-type', mimeType);
} else {
if (isTextFileName(filePath)) {
this.res.setHeader('Content-type', 'text/plain');
}
}

if ('md' === ext) {
const previewMdUrl = filePath
? '/' + driveId + (userConfigService.config.hugo_theme?.id ? `/${userConfigService.config.hugo_theme?.id}` : '/_manual') + filePath
: '';

const previewUrl = '/preview' +
previewMdUrl
.replace(/.md$/, '')
.replace(/_index$/, '');

this.res.setHeader('wgd-path', filePath || '');
this.res.setHeader('wgd-mime-type', mimeType);
this.res.setHeader('wgd-preview-url', previewUrl);
}

const buffer = await transformedFileSystem.readBuffer(filePath);
Expand Down
3 changes: 3 additions & 0 deletions src/containers/transform/DirectoryScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export function isTextFileName(fileName) {
if (fileName.endsWith('.css')) {
return true;
}
if (fileName.endsWith('.md')) {
return true;
}
return false;
}

Expand Down

0 comments on commit 5978f41

Please sign in to comment.