🔒 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:
@ -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}`
|
||||
|
||||
Reference in New Issue
Block a user