Skip to content

Commit

Permalink
Redirect from www. to non www.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa authored Jan 17, 2024
1 parent 9280ce5 commit ffc06bd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ type ContextEnv = { Bindings: RuntimeEnv };

const server = new Hono<ContextEnv>();

server.use("*", (context, next) => {
let url = new URL(context.req.url);
if (!url.origin.includes("www.")) return next();
url.hostname = url.hostname.slice(4);
return c.redirect(url.href, 302);
});

server.use("/write", (context, next) => {
let { WRITE_PASSWORD } = EnvSchema.parse(context.env);
return basicAuth({ username: "sergiodxa", password: WRITE_PASSWORD })(
Expand Down

0 comments on commit ffc06bd

Please sign in to comment.