Skip to content

Commit

Permalink
add security headers
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCogley committed Nov 8, 2024
1 parent c50f77b commit e1dc2d0
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions serve.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Server from "lume/core/server.ts";
import { basicAuth } from "lume/middlewares/basic_auth.ts"
import precompress from "lume/middlewares/precompress.ts";
import expires from "lume/middlewares/expires.ts";
import csp from "https://raw.githubusercontent.com/lumeland/experimental-plugins/main/csp/mod.ts";

const server = new Server({
port: 8000,
Expand All @@ -23,13 +25,38 @@ server.use((req, next) => {
return next(req);
});

server.use(precompress());

function isProtected(req) {
const url = new URL(req.url);
return url.pathname.includes("/private/");
}

// assumes you are precompressing, say with the brotli plugin
server.use(precompress());
server.use(expires());
// pass your preferred security header options:
server.use(csp({
"Strict-Transport-Security": {
maxAge: DEFAULT_MAX_AGE,
includeSubDomains: true,
preload: true,
},
"Referrer-Policy": ["no-referrer", "strict-origin-when-cross-origin"],
"X-Frame-Options": true,
"X-Content-Type-Options": true,
"X-XSS-Protection": true,
"X-Permitted-Cross-Domain-Policies": true,
"X-Powered-By": true,
});

server.use(async (request, next) => {
const response = await next(request);

// Add additional headers to the request
response.headers.set("X-Powered-By", "Lume and sweat, blood, and tears");

return response;
});

server.start();

console.log("Listening on http://localhost:8000");

1 comment on commit e1dc2d0

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on e1dc2d0 Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

The module's source code could not be parsed: Expected ',', got ';' at file:///src/serve.ts:49:3

  });
    ~

Please sign in to comment.