Skip to content

Commit

Permalink
#139 | Use reverse proxy in local-staging mode for development
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Jul 28, 2023
1 parent 75192e5 commit f00a69b
Show file tree
Hide file tree
Showing 6 changed files with 1,947 additions and 1,292 deletions.
24 changes: 18 additions & 6 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@ clean:
deps:
npm install --legacy-peer-deps

define _create_env
cp ./env-templates/$1.template .env
endef

start:
$(call _create_env,development)
npm run dev

start-local-staging:
$(call _create_env,local.staging)
npm run dev

_build-app:
cp ./env-templates/$(template) .env
$(call _create_env,)
npm run build

build-app:
make _build-app template=development.template
$(call _create_env,development)
npm run build

build-app-prod:
make _build-app template=production.template
$(call _create_env,production)
npm run build

build-app-staging:
make _build-app template=staging.template
$(call _create_env,staging)
npm run build

build-app-prerelease:
make _build-app template=prerelease.template

$(call _create_env,prerelease)
npm run build
7 changes: 7 additions & 0 deletions client/env-templates/local.staging.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NEXT_PUBLIC_IMAGE_LIST_URL=/etl/media
NEXT_PUBLIC_DOWNLOAD_REQUEST_URL=/media-viewer/requestDownload
NEXT_PUBLIC_DOWNLOAD_LIST_URL=/media-viewer/allData
NEXT_PUBLIC_OPERATIONAL_MODULE=/web/operationalModules
NEXT_PUBLIC_FORMS=/web/form/
NEXT_PUBLIC_TOP_ADDRESS=/locations/search/find
NEXT_PUBLIC_WEBAPP_BASE_URL=http://localhost:6010
27 changes: 27 additions & 0 deletions client/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mediaViewerService = "http://localhost:8023/media-viewer";
const etlService = "http://localhost:8022/";
const mainService = "http://localhost:8021/";

import {NextResponse} from 'next/server'

// console.log("Middleware used");

export function middleware(request) {
const pathname = request.nextUrl.pathname;
// console.log("Path:", pathname);

if (pathname.startsWith('/web') || pathname.startsWith("/location")) {
const url = new URL(pathname, mainService);
// console.log("Rewriting to ", JSON.stringify(url));
return NextResponse.rewrite(url);
}
if (pathname.startsWith('/etl')) {
// console.log(request.nextUrl);
const url = new URL(pathname.replace("/etl", "")+request.nextUrl.search, etlService);
// console.log("Rewriting to ", JSON.stringify(url));
return NextResponse.rewrite(url);
}
if (pathname.startsWith('/media-viewer')) {
return NextResponse.rewrite(new URL(pathname, mediaViewerService))
}
}
Loading

0 comments on commit f00a69b

Please sign in to comment.