Compare commits
2 Commits
8dbdfbdb3f
...
b6c7c76900
Author | SHA1 | Date | |
---|---|---|---|
b6c7c76900 | |||
75e8d2b7b2 |
@ -26,6 +26,12 @@ Prerequisite: golang installed
|
|||||||
|
|
||||||
Prerequisite: bun installed
|
Prerequisite: bun installed
|
||||||
|
|
||||||
|
The environment variable `API_HOST` will need to be set for the middleware.
|
||||||
|
Example `.env` in web's root:
|
||||||
|
```
|
||||||
|
API_HOST="http://localhost:8082/v1/"
|
||||||
|
```
|
||||||
|
|
||||||
1. `cd web`
|
1. `cd web`
|
||||||
2. `bun install`
|
2. `bun install`
|
||||||
|
|
||||||
|
@ -3,15 +3,7 @@ import type { NextConfig } from "next";
|
|||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
distDir: "build",
|
distDir: "build",
|
||||||
output: "standalone",
|
output: "standalone",
|
||||||
rewrites: async () => {
|
images: {
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: "/api/:path*",
|
|
||||||
destination: "http://localhost:8082/v1/:path*"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
images: {
|
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
protocol: 'https',
|
protocol: 'https',
|
||||||
|
13
web/src/app/middleware.ts
Normal file
13
web/src/app/middleware.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server"
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: ["/api/:path*"],
|
||||||
|
}
|
||||||
|
|
||||||
|
export function middleware(request: NextRequest) {
|
||||||
|
if (!process.env.API_HOST) {
|
||||||
|
throw new Error("env variable \"API_HOST\" is not set")
|
||||||
|
}
|
||||||
|
const url = new URL(process.env.API_HOST + request.nextUrl.pathname + request.nextUrl.search)
|
||||||
|
return NextResponse.rewrite(url, { request })
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user