Skip to content

Commit

Permalink
add res.type()
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgeoa committed Mar 1, 2024
1 parent 5647f1e commit 7775b5a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(!(port && docRoot)) {
process.exit();
}

app.all('*', async (req, res) => {
app.all('*', async (req, res, next) => {
const filePath = "file://" + docRoot + req.path;
try{
const solidRestRequest = mungeRestRequest(req);
Expand All @@ -25,13 +25,22 @@ app.all('*', async (req, res) => {
res.send(content);
}
catch(e){console.log(e)}
next()
});
function mungeRestResponse(res,solidRestResponse){
res.status = solidRestResponse.status;
res.statusText = solidRestResponse.statusText;
res.headers = solidRestResponse.headers;
res.url = solidRestResponse.url;
res.location = solidRestResponse.location;
// https://expressjs.com/en/api.html#res.type
// TODO more types to be tested image, json ....
const type = res.headers.get('content-type')
if (type.includes('html')) {
res.type('html');
} else if (type.includes('text')) {
res.type('text');
}
return res;
}
function mungeRestRequest(req){
Expand Down

0 comments on commit 7775b5a

Please sign in to comment.