Skip to content

Commit

Permalink
Merge pull request #46 from ruchernchong/45-add-auth-middleware-to-api
Browse files Browse the repository at this point in the history
Add bearer auth middleware to API
  • Loading branch information
ruchernchong authored Aug 6, 2024
2 parents 1827379 + 4e2a365 commit 2ececc3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CLOUDFLARE_API_TOKEN=
MONGODB_URI=
SG_CARS_TRENDS_API_TOKEN=
1 change: 1 addition & 0 deletions .github/workflows/sst.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/sst.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Deployment (Staging)

on:
push:
branches:
- "*"
tags-ignore:
- '*'

Expand All @@ -19,6 +21,7 @@ jobs:
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SG_CARS_TRENDS_API_TOKEN: ${{ secrets.SG_CARS_TRENDS_API_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
Expand Down
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ declare namespace NodeJS {
export interface ProcessEnv {
CLOUDFLARE_API_TOKEN: string;
MONGODB_URI: string;
SG_CARS_TRENDS_API_TOKEN: string;
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Hono } from "hono";
import { handle } from "hono/aws-lambda";
import { bearerAuth } from "hono/bearer-auth";
import { compress } from "hono/compress";
import { showRoutes } from "hono/dev";
import { logger } from "hono/logger";
Expand All @@ -10,6 +11,7 @@ import v1 from "./v1";

const app = new Hono();

app.use(bearerAuth({ token: process.env.SG_CARS_TRENDS_API_TOKEN }));
app.use(logger());
app.use(compress());
app.use(prettyJSON());
Expand Down
1 change: 1 addition & 0 deletions sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default $config({
description: "API for LTA Cars Datasets",
environment: {
MONGODB_URI: process.env.MONGODB_URI,
SG_CARS_TRENDS_API_TOKEN: process.env.SG_CARS_TRENDS_API_TOKEN,
},
handler: "src/index.handler",
url: {
Expand Down

0 comments on commit 2ececc3

Please sign in to comment.