Skip to content

Commit

Permalink
update to mime version 2 (#1639)
Browse files Browse the repository at this point in the history
* update to mime version 2

* mime ver 2

* mime update in cdn-mock

Co-authored-by: Divya Karippath <[email protected]>
  • Loading branch information
divyakarippath and divyavkarippath authored May 12, 2020
1 parent 874513b commit 4a57109
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/xarc-app-dev/lib/dev-admin/cdn-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const cdnMock = {
asset = LOADED_ASSETS[filePath] = Fs.readFileSync(fp);
}
const ext = Path.extname(filePath);
const mimeType = mime.lookup(ext);
const mimeType = mime.getType(ext);
res.writeHead(200, {
"Content-Type": mimeType,
"Content-Length": Buffer.byteLength(asset)
Expand Down
5 changes: 2 additions & 3 deletions packages/xarc-app-dev/lib/dev-admin/dev-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ function setup(app, protocol, port) {
replyNotFound: () => res.status(404).send("Not Found"),
replyError: err => res.status(500).send(err),
replyStaticData: data => {
const type = mime.lookup(req.url);
const type = mime.getType(req.url);
if (type) {
const charset = mime.charsets.lookup(type);
res.set("Content-Type", type + (charset ? `; charset=${charset}` : ""));
res.set("Content-Type", type);
}
res.status(200).send(data);
},
Expand Down
10 changes: 4 additions & 6 deletions packages/xarc-app-dev/lib/dev-admin/dev-fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ async function register(fastify) {
reply.send(err);
},
replyStaticData: data => {
const type = mime.lookup(request.url);
const type = mime.getType(request.url);
if (type) {
const charset = mime.charsets.lookup(type);
reply.header("Content-Type", type + (charset ? `; charset=${charset}` : ""));
reply.header("Content-Type", type);
}
reply.code(200).send(data);
},
Expand All @@ -59,10 +58,9 @@ async function register(fastify) {
reply.code(404);
return;
}
const type = mime.lookup(name);
const type = mime.getType(name);
if (type) {
const charset = mime.charsets.lookup(type);
reply.header("Content-Type", type + (charset ? `; charset=${charset}` : ""));
reply.header("Content-Type", type);
}
reply.code(200).send(data);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/xarc-app-dev/lib/dev-admin/dev-hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ function register(server, options, next) {
},
replyError: err => reply(err),
replyStaticData: data => {
const type = mime.lookup(req.url);
const type = mime.getType(req.url);
const resp = reply.response(data).code(200);
if (type) {
const charset = mime.charsets.lookup(type);
return resp.header("Content-Type", type + (charset ? `; charset=${charset}` : ""));
return resp.header("Content-Type", type);
}
return resp;
},
Expand All @@ -60,11 +59,10 @@ function register(server, options, next) {
} catch (e) {
return reply.code(404);
}
const type = mime.lookup(name);
const type = mime.getType(name);
const resp = reply.response(data).code(200);
if (type) {
const charset = mime.charsets.lookup(type);
resp.header("Content-Type", type + (charset ? `; charset=${charset}` : ""));
resp.header("Content-Type", type);
}
return resp;
}
Expand Down
10 changes: 4 additions & 6 deletions packages/xarc-app-dev/lib/dev-admin/dev-hapi17.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ function register(server) {
return h.response(err);
},
replyStaticData: data => {
const type = mime.lookup(req.url);
const type = mime.getType(req.url);
const resp = h.response(data).code(200);
if (type) {
const charset = mime.charsets.lookup(type);
resp.header("Content-Type", type + (charset ? `; charset=${charset}` : ""));
resp.header("Content-Type", type);
}
return resp.takeover();
},
Expand All @@ -62,11 +61,10 @@ function register(server) {
} catch (e) {
return h.code(404);
}
const type = mime.lookup(name);
const type = mime.getType(name);
const resp = h.response(data).code(200);
if (type) {
const charset = mime.charsets.lookup(type);
resp.header("Content-Type", type + (charset ? `; charset=${charset}` : ""));
resp.header("Content-Type", type);
}
return resp.takeover();
}
Expand Down
5 changes: 2 additions & 3 deletions packages/xarc-app-dev/lib/dev-admin/dev-koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ function setup(app, protocol, port) {
return res;
},
replyStaticData: data => {
const type = mime.lookup(req.url);
const type = mime.getType(req.url);
if (type) {
const charset = mime.charsets.lookup(type);
res.append("Content-Type", type + (charset ? `; charset=${charset}` : ""));
res.append("Content-Type", type);
}
res.status = 200;
res.body = data;
Expand Down
3 changes: 1 addition & 2 deletions packages/xarc-app-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"isomorphic-loader": "^3.1.0",
"lodash": "^4.13.1",
"log-update": "^4.0.0",
"mime": "^1.6.0",
"mime": "^2.4.5",
"mkdirp": "^0.5.1",
"nix-clap": "^1.3.7",
"nyc": "^14.1.1",
Expand Down Expand Up @@ -120,7 +120,6 @@
},
"fyn": {
"dependencies": {
"@jchip/redbird": "../../../redbird",
"@xarc/webpack": "../xarc-webpack",
"electrode-node-resolver": "../electrode-node-resolver",
"subapp-util": "../subapp-util"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe("dev-admin-fastify", function() {
expect(reply.statusCode).eq(200);
expect(reply.savedHeaders[0]).deep.eq({
name: "Content-Type",
value: "text/plain; charset=UTF-8"
value: "text/plain"
});
expect(reply.savedPayloads.length).eq(1);
expect(reply.savedPayloads[0].toString()).eq("blah");
Expand Down
6 changes: 3 additions & 3 deletions packages/xarc-app-dev/test/spec/dev-hapi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("dev-hapi", function() {
const { result } = cycle.replyFile("./xclap.js");
expect(result.code).to.equal(200);
expect(result).to.have.any.keys("response");
expect(result.headers["Content-Type"]).to.equal("application/javascript; charset=UTF-8");
expect(result.headers["Content-Type"]).to.equal("application/javascript");
});
});

Expand All @@ -96,7 +96,7 @@ describe("dev-hapi", function() {
expect(result.code).to.equal(200);
expect(result.takeover).to.equal(true);
expect(result).to.have.any.keys("response");
expect(result.headers["Content-Type"]).to.equal("application/javascript; charset=UTF-8");
expect(result.headers["Content-Type"]).to.equal("application/javascript");
});
});

Expand All @@ -115,7 +115,7 @@ describe("dev-hapi", function() {
expect(result.code).to.equal(200);
expect(result.takeover).to.equal(true);
expect(result).to.have.any.keys("response");
expect(result.headers["Content-Type"]).to.equal("application/javascript; charset=UTF-8");
expect(result.headers["Content-Type"]).to.equal("application/javascript");
});
});

Expand Down

0 comments on commit 4a57109

Please sign in to comment.