🔒 add app access token middleware

Create a middleware app access token, so that all requests must include `access_token` in the header with a value equal
to API_KEY in the .env file. If not, a `403 Forbidden` error will be returned.
This commit is contained in:
Rafi Arrafif
2025-08-13 11:26:57 +07:00
parent c1adb767e7
commit 89ebfb8aa4
2 changed files with 17 additions and 1 deletions

View File

@ -1,10 +1,14 @@
import { appAccessTokenMiddleware } from "./middleware/global/appAccessToken.middleware";
import { validateEnv } from "./utils/startups/validateEnv";
validateEnv();
const { Elysia } = await import("elysia");
const { routes } = await import("./routes");
const app = new Elysia().use(routes).listen(process.env.APP_PORT || 3000);
const app = new Elysia()
.use(appAccessTokenMiddleware())
.use(routes)
.listen(process.env.APP_PORT || 3000);
console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`