Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/npm/@amazeelabs/publisher/publisher.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ export default defineConfig({
},
},
databaseUrl: './test/database.sqlite',
responseHeaders: new Map()
.set('X-Frame-Options', 'deny')
.set('X-Content-Type-Options', 'nosniff')
.set('Content-Security-Policy', "frame-ancestors 'none'"),
});
7 changes: 7 additions & 0 deletions packages/npm/@amazeelabs/publisher/src/core/tools/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ export type PublisherConfig = {
credentials: boolean;
origin: Array<string>;
};
/**
* A Map of response headers that should be added to every route.
*
* Example: (new Map()).set('X-Frame-Options', 'deny')
* The above would set the "X-Frame-Options" response header to "deny".
*/
responseHeaders?: Map<string, string>;
/**
* Proxy settings.
*
Expand Down
14 changes: 14 additions & 0 deletions packages/npm/@amazeelabs/publisher/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ const runServer = async (): Promise<HttpTerminator> => {
next();
});

// Add any configured response headers which should apply on every route.
app.use((req, res, next) => {
// The spread operator applied on a Map generates a 2D key-value array. So
// if we have a Map with two items: key1 => value1, key2 => value2, then
// the spread operator applied on the Map would return
// [["key1", "value1"], ["key2", "value2"]].
[...(getConfig().responseHeaders || new Map<string, string>())].map(
(responseHeader) => {
res.set(responseHeader[0], responseHeader[1]);
},
);
next();
});

core.state.applicationState$.subscribe((state) => {
app.locals.isReady = state === ApplicationState.Ready;
stateNotify(state);
Expand Down