Skip to content

Commit

Permalink
fixed a cors problem when servering files locally
Browse files Browse the repository at this point in the history
  • Loading branch information
brendena committed Jan 15, 2024
1 parent 77a6ea2 commit 16e2d20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
/* node.js script that creates a webserver to serve up the pages from the html directory */

var express = require('express');
const cors = require('cors');
const homeDirectory = require('os').homedir();
var app = express();
app.use(cors());

app.all('/*', function(req, res, next) {
// The root page is part of the large site and so is not available
// locally. Instead we default to a given page to kick off.
var urlLocation = __dirname + '/html';
if (req.url === '/') {
res.redirect('/Original.html');
return next();
} else if (!req.url.match(/.*\/?\./)) {
req.url += '.html';
} else if (req.url.match(/^\/modules\//)){
console.log("got here")
urlLocation = homeDirectory + "/workspace/espruinowebsite/www";
}
console.log('returning: ' + req.url);
return express.static(__dirname + '/html')(req, res, next);
return express.static(urlLocation)(req, res, next);
});

app.listen(process.env.PORT || 3040, function(app){
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"acorn": "^6.0.2",
"acorn-walk": "^6.1.0",
"cors": "^2.8.5",
"eslint": "^5.14.1",
"express": "^4.13.3",
"highlight.js": "^8.9.1",
Expand Down

0 comments on commit 16e2d20

Please sign in to comment.