-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
25 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// middleware.js | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
|
||
const { TEN_DEV_SERVER_URL } = process.env; | ||
|
||
// Check if environment variables are available | ||
if (!TEN_DEV_SERVER_URL) { | ||
throw "Environment variables TEN_DEV_SERVER_URL are not available"; | ||
} | ||
|
||
export function middleware(req: NextRequest) { | ||
const { pathname } = req.nextUrl; | ||
|
||
if (pathname.startsWith('/apix/dev-server/v1')) { | ||
const url = req.nextUrl.clone(); | ||
url.href = `${TEN_DEV_SERVER_URL}${pathname.replace('/apix/dev-server/v1', '/api/dev-server/v1')}`; | ||
|
||
// console.log(`Rewriting request to ${url.href}`); | ||
return NextResponse.rewrite(url); | ||
} | ||
} |