File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ NEXT_PUBLIC_API_URL=http://localhost:3000/api/v1
2
2
NEXT_PUBLIC_STORAGE_URL = http://localhost:3000/api/assets
3
3
NEXT_PUBLIC_MIXPANEL_TOKEN = f2e8a71ab2bde33ebf346c5abf6ba9fa
4
4
NEXT_PUBLIC_ROLLBAR_ACCESS_TOKEN = 0df0bee895044430880278e2b2a5b2d2
5
+ # NEXT_PUBLIC_API_KEY=xxx-xxx-xxx-xxx # Uncomment this if you have an API key
6
+ # NEXT_PUBLIC_BACKEND_URL=http://backend:5328 # Uncomment this if you're working with a docker setup
Original file line number Diff line number Diff line change @@ -3,16 +3,24 @@ import type { NextRequest } from "next/server";
3
3
import localStorage from "@/lib/localStorage" ;
4
4
import { APIKeyData } from "./interfaces/user" ;
5
5
import axios from "axios" ;
6
+ import { GetAPIKey } from "./services/user" ;
6
7
7
8
export async function middleware ( request : NextRequest ) {
8
9
let apiKey = null ;
9
10
try {
10
- // Hardcoded for now for the docker
11
- const response = await axios . get < { data : APIKeyData } > (
12
- `http://backend:5328/v1/user/get-api-key`
13
- ) ;
11
+ const envApiKey = process . env . NEXT_PUBLIC_API_KEY ;
12
+ const dockerBackendUrl = process . env . NEXT_PUBLIC_BACKEND_URL ;
14
13
15
- apiKey = { data : { api_key : response . data . data . key } } ;
14
+ if ( envApiKey ) {
15
+ apiKey = { data : { api_key : envApiKey } } ;
16
+ } else if ( dockerBackendUrl ) {
17
+ const response = await axios . get < { data : APIKeyData } > (
18
+ `${ dockerBackendUrl } /v1/user/get-api-key`
19
+ ) ;
20
+ apiKey = { data : { api_key : response . data . data . key } } ;
21
+ } else {
22
+ apiKey = await GetAPIKey ( ) ;
23
+ }
16
24
} catch ( error ) {
17
25
console . error ( "Error fetching API key:" , error ) ;
18
26
return NextResponse . redirect ( new URL ( "/api-key-setup" , request . url ) ) ;
You can’t perform that action at this time.
0 commit comments