Skip to content

Commit

Permalink
Add useRemoteUrl hook
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Oct 1, 2023
1 parent 1d2b980 commit 57e35ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions components/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -41,6 +42,9 @@ const Drawer = ({
const maxInputWidth = useBreakpointValue({ base: 'initial', md: '280px' })
const selectedWebName = useSelectedWebName()

const remoteUrl = useRemoteUrl()
console.log({ remoteUrl })

return (
<chakra.div
position="fixed"
Expand Down
1 change: 1 addition & 0 deletions hooks/application/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as useMediaQuerySSR } from './useMediaQuerySSR'
export { default as useRemoteUrl } from './useRemoteUrl'
20 changes: 20 additions & 0 deletions hooks/application/useRemoteUrl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useRouter } from 'next/router'

const useRemoteUrl = () => {
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

18 changes: 14 additions & 4 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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, {
status: 404,
})
}

if (!pathname.includes('.') && !pathname.startsWith('/api')) {
if (!pathname.includes('.')) {
if (currentHost == 'app') {
if (
pathname === '/login' &&
Expand All @@ -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)
}
Expand All @@ -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).*)'],
}



0 comments on commit 57e35ae

Please sign in to comment.