Skip to content

Commit

Permalink
Merge pull request #17 from thedevdojo/latestUpdates
Browse files Browse the repository at this point in the history
Adding updates and fixes to allow custom headers
  • Loading branch information
tnylea committed Feb 27, 2024
2 parents 9409cc1 + c6faa60 commit 9f20ad4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devdojo/static",
"version": "1.0.25",
"version": "1.0.26",
"description": "Static Site Generator",
"main": "index.js",
"scripts": {
Expand Down
28 changes: 17 additions & 11 deletions src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,26 @@ module.exports = {
});

// TODO: Allow user to specify setting headers in the dev server via a config file
// app.use(function(req, res, next) {
// res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
// res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
// next();
// });
let staticJSON = {};

const staticJsonPath = path.join(currentDirectory, 'static.json');
if (fs.existsSync(staticJsonPath)) {
const staticJsonContent = fs.readFileSync(staticJsonPath, 'utf8');
staticJSON = JSON.parse(staticJsonContent);
}

app.use(function(req, res, next) {
if (staticJSON.hasOwnProperty('headers')) {
for (const header in staticJSON.headers) {
res.setHeader(header, staticJSON.headers[header]);
}
}
next();
});

app.use(connectLiveReload(liveReloadOptions));

// let options = {
// setHeaders: function (res, path, stat) {
// res.set("Cross-Origin-Opener-Policy", "same-origin");
// res.set("Cross-Origin-Embedder-Policy", "require-corp");
// }
// }


app.use('/assets', express.static(path.join(currentDirectory, '_site/assets')))
app.use('/', express.static(path.join(currentDirectory, 'public/')))
Expand Down

0 comments on commit 9f20ad4

Please sign in to comment.