Skip to content

Commit

Permalink
Merge pull request #103 from MajorLift/master
Browse files Browse the repository at this point in the history
fix(protocol.js): wrong input type in charset() call
  • Loading branch information
reZach authored Feb 11, 2022
2 parents 8c3c315 + a5a52c2 commit 74b3326
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/electron/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ const mimeTypes = {
".map": "text/plain"
};

function charset(mimeType) {
return [".html", ".htm", ".js", ".mjs"].some((m) => m === mimeType) ?
function charset(mimeExt) {
return [".html", ".htm", ".js", ".mjs"].some((m) => m === mimeExt) ?
"utf-8" :
null;
}

function mime(filename) {
const type = mimeTypes[path.extname(`${filename || ""}`).toLowerCase()];
return type ? type : null;
const mimeExt = path.extname(`${filename || ""}`).toLowerCase();
const mimeType = mimeTypes[mimeExt];
return mimeType ? { mimeExt, mimeType } : { mimeExt: null, mimeType: null };
}

function requestHandler(req, next) {
Expand All @@ -51,12 +52,12 @@ function requestHandler(req, next) {
}
const reqFilename = path.basename(reqPath);
fs.readFile(path.join(DIST_PATH, reqPath), (err, data) => {
const mimeType = mime(reqFilename);
const { mimeExt, mimeType } = mime(reqFilename);
if (!err && mimeType !== null) {
next({
mimeType: mimeType,
charset: charset(mimeType),
data: data
mimeType,
charset: charset(mimeExt),
data
});
} else {
console.error(err);
Expand Down

0 comments on commit 74b3326

Please sign in to comment.