From 57e35aedf6bdc7384d48b8a79633b771d5d02a1b Mon Sep 17 00:00:00 2001 From: Diner Date: Sun, 1 Oct 2023 19:18:03 +0100 Subject: [PATCH] Add useRemoteUrl hook --- components/drawer/Drawer.tsx | 4 ++++ hooks/application/index.ts | 1 + hooks/application/useRemoteUrl.tsx | 20 ++++++++++++++++++++ middleware.ts | 18 ++++++++++++++---- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 hooks/application/useRemoteUrl.tsx diff --git a/components/drawer/Drawer.tsx b/components/drawer/Drawer.tsx index f2663012..548e0dc9 100644 --- a/components/drawer/Drawer.tsx +++ b/components/drawer/Drawer.tsx @@ -23,6 +23,7 @@ import { HiOutlineSearch, HiOutlineX } from 'react-icons/hi' import VolunteerSwitch from '@components/volunteer-switch' import customMultiSelectStyles from '@styles/select-styles' import { REMOTE_URL } from '@helpers/config' +import { useRemoteUrl } from '@hooks/application' import { useSelectedWebName } from '@hooks/webs' import LogoImage from '../../public/logo.png' @@ -41,6 +42,9 @@ const Drawer = ({ const maxInputWidth = useBreakpointValue({ base: 'initial', md: '280px' }) const selectedWebName = useSelectedWebName() + const remoteUrl = useRemoteUrl() + console.log({ remoteUrl }) + return ( { + const router = useRouter() + + const { pathname, isPreview, basePath, asPath } = router + + console.log({ pathname, isPreview, basePath, asPath }) + + // if (isPreview) { + // return basePath + // } + + return process.env.NODE_ENV === 'development' + ? 'http://localhost:3000' + : 'https://resilienceweb.org.uk' +} + +export default useRemoteUrl + diff --git a/middleware.ts b/middleware.ts index a579ce6e..6033ceef 100644 --- a/middleware.ts +++ b/middleware.ts @@ -26,7 +26,7 @@ export default function middleware(req: NextRequest) { .replace('.vercel.app', '') : hostname.replace(`.localhost:3000`, '') - console.log('DINER', { hostname, currentHost, pathname }) + console.log('DINER', { hostname, currentHost, pathname, url }) if (pathname.startsWith(`/_webs`)) { return new Response(null, { @@ -34,7 +34,7 @@ export default function middleware(req: NextRequest) { }) } - if (!pathname.includes('.') && !pathname.startsWith('/api')) { + if (!pathname.includes('.')) { if (currentHost == 'app') { if ( pathname === '/login' && @@ -52,8 +52,7 @@ export default function middleware(req: NextRequest) { if ( hostname === 'localhost:3000' || hostname === 'cambridgeresilienceweb.org.uk' || - hostname === 'resilienceweb.org.uk' || - hostname === 'vercel.app' + hostname === 'resilienceweb.org.uk' ) { return NextResponse.rewrite(url) } @@ -63,5 +62,16 @@ export default function middleware(req: NextRequest) { } } +/* + * Match all request paths except for the ones starting with: + * - api (API routes) + * - _next/static (static files) + * - _next/image (image optimization files) + * - favicon.ico (favicon file) + */ +export const config = { + matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'], +} +