From 0bf449a466d58069879d21505bf616a2c3e4119f Mon Sep 17 00:00:00 2001 From: MytsV Date: Mon, 12 Aug 2024 19:47:13 +0300 Subject: [PATCH 1/2] Fix login page redirection --- src/middleware.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middleware.ts b/src/middleware.ts index 1a7c02963..e4d225bfd 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -30,12 +30,12 @@ export const config = { } async function reLogin(request: NextRequest) { - const logoutPage = new URL(`/api/auth/logout?callbackUrl=${request.url}`, request.url) + const logoutPage = new URL(`/api/auth/logout?callbackUrl=${request.nextUrl.pathname}`, request.url) return NextResponse.redirect(logoutPage) } async function initiateLogin(request: NextRequest){ - const loginPage = new URL(`/api/auth/login?callbackUrl=${request.url}`, request.url) + const loginPage = new URL(`/api/auth/login?callbackUrl=${request.nextUrl.pathname}`, request.url) return NextResponse.redirect(loginPage) } From c08091be101ea52c826c059d880cb5e03b056d23 Mon Sep 17 00:00:00 2001 From: MytsV Date: Tue, 13 Aug 2024 17:58:17 +0300 Subject: [PATCH 2/2] Fix requests that failed with a different hostname/with a reverse proxy --- src/app/(rucio)/did/list/page.tsx | 2 +- .../(rucio)/did/page/[scope]/[name]/page.tsx | 12 ++++++------ src/app/(rucio)/did/queries.ts | 4 ++-- src/app/(rucio)/queries.ts | 19 +------------------ src/app/(rucio)/rse/list/page.tsx | 2 +- src/app/(rucio)/rse/page/[name]/page.tsx | 6 +++--- src/app/(rucio)/rucio-app-layout.tsx | 2 +- src/app/(rucio)/rule/create/page.tsx | 4 ++-- src/app/(rucio)/rule/page/[id]/page.tsx | 4 ++-- src/app/(rucio)/subscription/list/page.tsx | 2 +- .../page/[account]/[name]/page.tsx | 4 ++-- src/app/moncomdom/page.tsx | 2 +- .../Pages/Rule/1_DIDs/CreateRuleDIDsPage.tsx | 2 +- .../Pages/Rule/2_RSEs/CreateRuleRSEsPage.tsx | 2 +- 14 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/app/(rucio)/did/list/page.tsx b/src/app/(rucio)/did/list/page.tsx index d4a96b907..fc7543dc7 100644 --- a/src/app/(rucio)/did/list/page.tsx +++ b/src/app/(rucio)/did/list/page.tsx @@ -15,7 +15,7 @@ export default function Page() { } const didQuery = async (query: string, type: DIDType) => { const request: any = { - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-dids`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-dids`), method: 'GET', headers: new Headers({ 'Content-Type': 'application/json', diff --git a/src/app/(rucio)/did/page/[scope]/[name]/page.tsx b/src/app/(rucio)/did/page/[scope]/[name]/page.tsx index 28176fc89..eb07eafa5 100644 --- a/src/app/(rucio)/did/page/[scope]/[name]/page.tsx +++ b/src/app/(rucio)/did/page/[scope]/[name]/page.tsx @@ -30,7 +30,7 @@ export default function Page({ params }: { params: { scope: string, name: string ) const didFileReplicasDOnChange = (scope: string, name: string) => { didFileReplicasComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-file-replicas`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-file-replicas`), method: 'GET', params: { scope: scope, @@ -52,7 +52,7 @@ export default function Page({ params }: { params: { scope: string, name: string useEffect(() => { const setRequests = async () => { await didContentsComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-did-contents`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-did-contents`), method: 'GET', params: { scope: params.scope, @@ -64,7 +64,7 @@ export default function Page({ params }: { params: { scope: string, name: string body: null, } as HTTPRequest) await didParentsComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-did-parents`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-did-parents`), method: 'GET', params: { scope: params.scope, @@ -76,7 +76,7 @@ export default function Page({ params }: { params: { scope: string, name: string body: null, } as HTTPRequest) await didFileReplicasComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-file-replicas`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-file-replicas`), method: 'GET', params: { scope: params.scope, @@ -88,7 +88,7 @@ export default function Page({ params }: { params: { scope: string, name: string body: null, } as HTTPRequest) await didRulesComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-did-rules`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-did-rules`), method: 'GET', params: { scope: params.scope, @@ -100,7 +100,7 @@ export default function Page({ params }: { params: { scope: string, name: string body: null, } as HTTPRequest) await didDatasetReplicasComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-dataset-replicas`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-dataset-replicas`), method: 'GET', params: { scope: params.scope, diff --git a/src/app/(rucio)/did/queries.ts b/src/app/(rucio)/did/queries.ts index d8dfc926f..18954c963 100644 --- a/src/app/(rucio)/did/queries.ts +++ b/src/app/(rucio)/did/queries.ts @@ -1,13 +1,13 @@ import { DIDKeyValuePairsDataViewModel, DIDMetaViewModel } from "@/lib/infrastructure/data/view-model/did"; export async function didMetaQueryBase(scope: string, name: string): Promise { - const url = `${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-did-meta?` + new URLSearchParams({scope, name}) + const url = '/api/feature/get-did-meta?' + new URLSearchParams({scope, name}) const res = await fetch(url) return await res.json() } export async function didKeyValuePairsDataQuery(scope: string, name: string): Promise { - const url = `${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-did-keyvaluepairs?` + new URLSearchParams({scope, name}) + const url = '/api/feature/get-did-keyvaluepairs?' + new URLSearchParams({scope, name}) const res = await fetch(url) return await res.json() } \ No newline at end of file diff --git a/src/app/(rucio)/queries.ts b/src/app/(rucio)/queries.ts index 3ecca2d80..2e141c09d 100644 --- a/src/app/(rucio)/queries.ts +++ b/src/app/(rucio)/queries.ts @@ -1,23 +1,6 @@ import { SiteHeaderViewModel } from '@/lib/infrastructure/data/view-model/site-header' export async function getSiteHeader(): Promise { - const req: any = { - method: 'GET', - url: new URL( - `${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-site-header`, - ), - headers: { - 'Content-Type': 'application/json', - }, - params: {}, - } - - const res = await fetch(req.url, { - method: 'GET', - headers: new Headers({ - 'Content-Type': 'application/json', - } as HeadersInit), - }) - + const res = await fetch('/api/feature/get-site-header') return await res.json() } diff --git a/src/app/(rucio)/rse/list/page.tsx b/src/app/(rucio)/rse/list/page.tsx index 3b09a3ab0..86665d454 100644 --- a/src/app/(rucio)/rse/list/page.tsx +++ b/src/app/(rucio)/rse/list/page.tsx @@ -8,7 +8,7 @@ export default function Page() { const setRSEQuery = async (rseExpression: string) => { await RSESearchComDOM.setRequest({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-rses`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-rses`), method: 'GET', headers: new Headers({ 'Content-Type': 'application/json', diff --git a/src/app/(rucio)/rse/page/[name]/page.tsx b/src/app/(rucio)/rse/page/[name]/page.tsx index eeb014889..2c53f6a9a 100644 --- a/src/app/(rucio)/rse/page/[name]/page.tsx +++ b/src/app/(rucio)/rse/page/[name]/page.tsx @@ -6,19 +6,19 @@ import { RSEAttributeViewModel, RSEProtocolViewModel, RSEViewModel } from "@/lib import { useEffect, useState } from "react"; async function getRSE(rseName: string): Promise { - const url = `${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-rse?` + new URLSearchParams({rseName}) + const url = '/api/feature/get-rse?' + new URLSearchParams({rseName}) const res = await fetch(url) return await res.json() } async function getProtocols(rseName: string): Promise { - const url = `${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-rse-protocols?` + new URLSearchParams({rseName}) + const url = '/api/feature/get-rse-protocols?' + new URLSearchParams({rseName}) const res = await fetch(url) return await res.json() } async function getAttributes(rseName:string): Promise { - const url = `${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-rse-attributes?` + new URLSearchParams({rseName}) + const url = '/api/feature/get-rse-attributes?' + new URLSearchParams({rseName}) const res = await fetch(url) return await res.json() } diff --git a/src/app/(rucio)/rucio-app-layout.tsx b/src/app/(rucio)/rucio-app-layout.tsx index 89fee66ca..1067d3101 100644 --- a/src/app/(rucio)/rucio-app-layout.tsx +++ b/src/app/(rucio)/rucio-app-layout.tsx @@ -14,7 +14,7 @@ export const RucioAppLayout = (props: QueryContextLayoutProps) => { homeUrl: "" }) const fetchAccounts = async () => { - await fetch(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-site-header`) + await fetch('/api/feature/get-site-header') .then(res => { if (res.ok) { return res.json() diff --git a/src/app/(rucio)/rule/create/page.tsx b/src/app/(rucio)/rule/create/page.tsx index 560bba0c8..9bd5c64a1 100644 --- a/src/app/(rucio)/rule/create/page.tsx +++ b/src/app/(rucio)/rule/create/page.tsx @@ -22,7 +22,7 @@ export default function CreateRule() { viewModel.status = 'pending' try { - const response = await fetch(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/create-rule`, { + const response = await fetch(`/api/feature/create-rule`, { method: "POST", headers: new Headers({ 'Content-Type': 'application/json' @@ -100,7 +100,7 @@ export default function CreateRule() { const [accountInfo, setAccountInfo] = useState(generateEmptyAccountInfoViewModel()) useEffect(() => { - fetch(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/account-info`) + fetch(`${window.location.protocol}//${window.location.host}/api/feature/account-info`) .then((response) => { if(response.ok) { return response.json() diff --git a/src/app/(rucio)/rule/page/[id]/page.tsx b/src/app/(rucio)/rule/page/[id]/page.tsx index 393b75c73..56f587ac7 100644 --- a/src/app/(rucio)/rule/page/[id]/page.tsx +++ b/src/app/(rucio)/rule/page/[id]/page.tsx @@ -27,7 +27,7 @@ export default function PageRule({ params }: { params: { id: string } }) { useEffect(() => { // TODO get from mock endpoint - fetch(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/mock-get-rule-meta`) + fetch('/api/feature/mock-get-rule-meta') .then(res => { if (res.ok) { return res.json() @@ -46,7 +46,7 @@ export default function PageRule({ params }: { params: { id: string } }) { useEffect(() => { const runQuery = async () => { const request: HTTPRequest = { - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/mock-list-rule-page-lock`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/mock-list-rule-page-lock`), method: "GET", headers: new Headers({ 'Content-Type': 'application/json' diff --git a/src/app/(rucio)/subscription/list/page.tsx b/src/app/(rucio)/subscription/list/page.tsx index 9ef759405..0e4210293 100644 --- a/src/app/(rucio)/subscription/list/page.tsx +++ b/src/app/(rucio)/subscription/list/page.tsx @@ -28,7 +28,7 @@ export default function ListSubscription({ params }: { params: { account: string useEffect(() => { const runQuery = async () => { await ComDOM.start({ - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/list-subscription-rule-states`), + url: new URL(`${window.location.protocol}//${window.location.host}/api/feature/list-subscription-rule-states`), method: "GET", headers: new Headers({ 'Content-Type': 'application/json' diff --git a/src/app/(rucio)/subscription/page/[account]/[name]/page.tsx b/src/app/(rucio)/subscription/page/[account]/[name]/page.tsx index 7bf35d4ac..35ab2b0bf 100644 --- a/src/app/(rucio)/subscription/page/[account]/[name]/page.tsx +++ b/src/app/(rucio)/subscription/page/[account]/[name]/page.tsx @@ -12,7 +12,7 @@ async function updateSubscription( ) { const req: any = { method: "PUT", - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/mock-update-subscription`), + url: new URL(`/api/feature/mock-update-subscription`), headers: { 'Content-Type': 'application/json', }, @@ -43,7 +43,7 @@ export default function PageSubscription({ params }: { params: { account: string async function subscriptionQuery(account: string, name: string): Promise { const req: any = { method: "GET", - url: new URL(`${process.env.NEXT_PUBLIC_WEBUI_HOST}/api/feature/get-subscription`), + url: new URL(`/api/feature/get-subscription`), params: { "account": account, "name": name diff --git a/src/app/moncomdom/page.tsx b/src/app/moncomdom/page.tsx index 8e8e996a1..cb5b68920 100644 --- a/src/app/moncomdom/page.tsx +++ b/src/app/moncomdom/page.tsx @@ -79,7 +79,7 @@ export default function RSETable() {