Skip to content

Commit cdbf7ed

Browse files
committed
Use env flag for maintenance, remove SSR helpers
Switch maintenance handling from server-side helpers to a runtime env flag. Adds redirects in next.config.mjs to send key routes to /maintenance when IS_IN_MAINTENANCE_MODE is set, removes src/lib/server/maintenance.ts and its getServerSideProps usages across pages, and replaces SSR checks with client-side NEXT_PUBLIC_IS_IN_MAINTENANCE_MODE checks in overlay, widget, login, index and verify pages. Also deletes the now-playing Last.fm API route (src/pages/api/lastfm/now-playing.ts). Minor cleanup: simplify overlay scaling logic and effect dependencies, remove unused imports.
1 parent 17f4a3d commit cdbf7ed

9 files changed

Lines changed: 33 additions & 211 deletions

File tree

next.config.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const nextConfig = {
1818
NEXT_PUBLIC_LASTFM_API_KEY: process.env.LASTFM_API_KEY,
1919
},
2020
async redirects() {
21-
return [
21+
const redirects = [
2222
{
2323
source: '/install',
2424
destination: '/api/install',
@@ -30,6 +30,16 @@ const nextConfig = {
3030
permanent: false,
3131
},
3232
]
33+
34+
if (process.env.IS_IN_MAINTENANCE_MODE === 'true') {
35+
redirects.push(
36+
{ source: '/', destination: '/maintenance', permanent: false },
37+
{ source: '/login', destination: '/maintenance', permanent: false },
38+
{ source: '/verify', destination: '/maintenance', permanent: false },
39+
)
40+
}
41+
42+
return redirects
3343
},
3444
async rewrites() {
3545
return [

src/lib/server/maintenance.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/pages/api/lastfm/now-playing.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/pages/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import type { GetServerSideProps } from 'next'
21
import type { ReactElement } from 'react'
32
import { Faqs } from '@/components/Homepage/Faqs'
43
import { Hero } from '@/components/Homepage/Hero'
54
import HomepageShell from '@/components/Homepage/HomepageShell'
65
import { PrimaryFeatures } from '@/components/Homepage/PrimaryFeatures'
76
import { SecondaryFeatures } from '@/components/Homepage/SecondaryFeatures'
87
import { Pricing } from '@/components/Pricing'
9-
import { getMaintenanceRedirect } from '@/lib/server/maintenance'
108
import type { NextPageWithLayout } from '@/pages/_app'
119

1210
const Index: NextPageWithLayout = () => (
@@ -40,5 +38,3 @@ Index.getLayout = function getLayout(page: ReactElement) {
4038
}
4139

4240
export default Index
43-
44-
export const getServerSideProps: GetServerSideProps = async (ctx) => getMaintenanceRedirect(ctx)

src/pages/login.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import * as Sentry from '@sentry/nextjs'
22
import { App, Typography } from 'antd'
3-
import type { GetServerSideProps } from 'next'
43
import Link from 'next/link'
54
import { useRouter } from 'next/router'
65
import { useSession } from 'next-auth/react'
76
import { type ReactElement, useCallback, useEffect } from 'react'
87
import { Container } from '@/components/Container'
98
import { UserAuthForm } from '@/components/Homepage/AuthForm'
109
import HomepageShell from '@/components/Homepage/HomepageShell'
11-
import { getMaintenanceRedirect } from '@/lib/server/maintenance'
1210
import type { NextPageWithLayout } from '@/pages/_app'
1311

1412
const Login: NextPageWithLayout = () => {
@@ -124,5 +122,3 @@ Login.getLayout = function getLayout(page: ReactElement) {
124122
}
125123

126124
export default Login
127-
128-
export const getServerSideProps: GetServerSideProps = async (ctx) => getMaintenanceRedirect(ctx)
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import type { GetServerSideProps } from 'next'
21
import MainOverlay from '@/components/Overlay'
3-
import { getOverlayMaintenanceProps } from '@/lib/server/maintenance'
42

5-
interface OverlayUserPageProps {
6-
maintenanceBlank: boolean
7-
}
8-
9-
const OverlayUserPage = ({ maintenanceBlank }: OverlayUserPageProps) => {
10-
if (maintenanceBlank) {
3+
const OverlayUserPage = () => {
4+
if (process.env.NEXT_PUBLIC_IS_IN_MAINTENANCE_MODE === 'true') {
115
return null
126
}
137

148
return <MainOverlay />
159
}
1610

1711
export default OverlayUserPage
18-
19-
export const getServerSideProps: GetServerSideProps<OverlayUserPageProps> = async () =>
20-
getOverlayMaintenanceProps({})

src/pages/overlay/[userId]/widget.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { clsx } from 'clsx'
2-
import type { GetServerSideProps } from 'next'
32
import { useRouter } from 'next/router'
43
import { useEffect, useState } from 'react'
54
import type { Socket } from 'socket.io-client'
@@ -14,14 +13,12 @@ import type { wlType } from '@/lib/hooks/useSocket'
1413
import { useTransformRes } from '@/lib/hooks/useTransformRes'
1514
import { useUpdateSetting } from '@/lib/hooks/useUpdateSetting'
1615
import { getRankDetail, getRankImage, type RankType } from '@/lib/ranks'
17-
import { getOverlayMaintenanceProps } from '@/lib/server/maintenance'
16+
17+
const isMaintenanceMode = process.env.NEXT_PUBLIC_IS_IN_MAINTENANCE_MODE === 'true'
1818

1919
let socket: Socket | null = null
20-
interface WidgetPageProps {
21-
maintenanceBlank: boolean
22-
}
2320

24-
function WidgetPage({ maintenanceBlank }: WidgetPageProps) {
21+
function WidgetPage() {
2522
const { mutate } = useUpdateSetting(Settings.commandWL)
2623
const router = useRouter()
2724
const { userId } = router.query
@@ -49,7 +46,7 @@ function WidgetPage({ maintenanceBlank }: WidgetPageProps) {
4946
})
5047

5148
useEffect(() => {
52-
if (maintenanceBlank) return
49+
if (isMaintenanceMode) return
5350
if (!userId) return
5451

5552
console.log('Connecting to socket init...')
@@ -77,20 +74,20 @@ function WidgetPage({ maintenanceBlank }: WidgetPageProps) {
7774
notLoaded: false,
7875
})
7976
})
80-
}, [maintenanceBlank, userId])
77+
}, [userId])
8178

8279
useEffect(() => {
83-
if (maintenanceBlank) return
80+
if (isMaintenanceMode) return
8481

8582
return () => {
8683
socket?.off('update-wl')
8784
socket?.off('refresh-settings')
8885
socket?.off('update-medal')
8986
}
90-
}, [maintenanceBlank])
87+
}, [])
9188

9289
useEffect(() => {
93-
if (maintenanceBlank) return
90+
if (isMaintenanceMode) return
9491
if (!original) return
9592

9693
const steamAccount = original.SteamAccount?.[0]
@@ -106,9 +103,9 @@ function WidgetPage({ maintenanceBlank }: WidgetPageProps) {
106103
}
107104

108105
setRankImageDetails(rankDetails)
109-
}, [maintenanceBlank, original])
106+
}, [original])
110107

111-
if (maintenanceBlank) {
108+
if (isMaintenanceMode) {
112109
return null
113110
}
114111

@@ -147,6 +144,3 @@ function WidgetPage({ maintenanceBlank }: WidgetPageProps) {
147144
}
148145

149146
export default WidgetPage
150-
151-
export const getServerSideProps: GetServerSideProps<WidgetPageProps> = async () =>
152-
getOverlayMaintenanceProps({})

src/pages/overlay/index.tsx

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
11
import { Spin } from 'antd'
2-
import type { GetServerSideProps } from 'next'
32
import Head from 'next/head'
43
import { useSession } from 'next-auth/react'
54
import type { ReactElement } from 'react'
65
import { useEffect, useState } from 'react'
76
import DashboardShell from '@/components/Dashboard/DashboardShell'
87
import Header from '@/components/Dashboard/Header'
9-
import { getOverlayMaintenanceProps } from '@/lib/server/maintenance'
108

11-
interface OverlayPageProps {
12-
maintenanceBlank: boolean
13-
}
9+
const isMaintenanceMode = process.env.NEXT_PUBLIC_IS_IN_MAINTENANCE_MODE === 'true'
1410

15-
const OverlayPage = ({ maintenanceBlank }: OverlayPageProps) => {
11+
const OverlayPage = () => {
1612
const { data } = useSession()
17-
const [scale, setScale] = useState(1) // Initial scale is 1
18-
const [isLoading, setIsLoading] = useState(true) // Initial state is loading
13+
const [scale, setScale] = useState(1)
14+
const [isLoading, setIsLoading] = useState(true)
1915

2016
useEffect(() => {
21-
if (maintenanceBlank) return
17+
if (isMaintenanceMode) return
2218

2319
const resizeListener = () => {
24-
// Assuming headerHeight and sideNavWidth are known or can be dynamically calculated
25-
const headerHeight = 309 // Example height of the header
26-
const sideNavWidth = 380 // Example width of the side navigation
20+
const headerHeight = 309
21+
const sideNavWidth = 380
2722

28-
// Adjust window dimensions by subtracting the sizes of header and side navigation
2923
const adjustedWidth = window.innerWidth - sideNavWidth
3024
const adjustedHeight = window.innerHeight - headerHeight
3125

32-
// Calculate the scale ratio based on adjusted window size and content size (1920x1080)
3326
const scaleX = adjustedWidth / 1920
3427
const scaleY = adjustedHeight / 1080
35-
const newScale = Math.min(scaleX, scaleY) // Use the smaller scale to ensure content fits in both dimensions
28+
const newScale = Math.min(scaleX, scaleY)
3629

3730
setScale(newScale)
3831
}
3932

40-
// Set initial scale
4133
resizeListener()
4234

43-
// Add event listener
4435
window.addEventListener('resize', resizeListener)
4536

46-
// Cleanup function to remove event listener
4737
return () => window.removeEventListener('resize', resizeListener)
48-
}, [maintenanceBlank])
38+
}, [])
4939

50-
if (maintenanceBlank) {
40+
if (isMaintenanceMode) {
5141
return null
5242
}
5343

@@ -96,6 +86,3 @@ OverlayPage.getLayout = function getLayout(page: ReactElement) {
9686
}
9787

9888
export default OverlayPage
99-
100-
export const getServerSideProps: GetServerSideProps<OverlayPageProps> = async () =>
101-
getOverlayMaintenanceProps({})

0 commit comments

Comments
 (0)