Skip to content

Commit 06bca99

Browse files
elit-altumandrewn
andauthored
fix(file.controller.js): set headers for file extensions from MIME -I1218 (#1330)
* fix(file.controller.js): set headers for file extensions from MIME - I1218 * Use name to work out content type and provide fallback Co-authored-by: Andrew Nicolaou <[email protected]>
1 parent 866d67d commit 06bca99

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
"jshint": "^2.11.0",
135135
"lodash": "^4.17.15",
136136
"loop-protect": "github:catarak/loop-protect",
137+
"mime-types": "^2.1.26",
137138
"mjml": "^3.3.2",
138139
"mockingoose": "^2.13.2",
139140
"mongoose": "^5.9.2",

server/controllers/file.controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import each from 'async/each';
2+
import mime from 'mime-types';
23
import isBefore from 'date-fns/is_before';
34
import Project from '../models/project';
45
import { resolvePathToFile } from '../utils/filePath';
@@ -120,6 +121,8 @@ export function getFileContent(req, res) {
120121
res.status(404).send({ success: false, message: 'File with that name and path does not exist.' });
121122
return;
122123
}
124+
const contentType = mime.lookup(resolvedFile.name) || 'application/octet-stream';
125+
res.set('Content-Type', contentType);
123126
res.send(resolvedFile.content);
124127
});
125128
}

0 commit comments

Comments
 (0)