feat: support pwa

This commit is contained in:
DIYgod
2023-01-20 23:20:07 +00:00
parent 74fd41a88b
commit 1e28fb9e12
13 changed files with 4839 additions and 109 deletions
+1
View File
@@ -46,6 +46,7 @@ export const SEOHead: React.FC<{
type="application/feed+json"
></link>
<link rel="icon" href={icon || `${SITE_URL}/logo.svg`}></link>
<link rel="manifest" href="/manifest.json" />
</Head>
)
}
+2
View File
@@ -9,6 +9,8 @@ const slugReservedWords = [
"dashboard",
"robots.txt",
"nft",
"sw.js",
"manifest.json",
]
export const checkSlugReservedWords = (word: string) => {
+6 -3
View File
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from "next/server"
import { IS_PROD } from "~/lib/constants"
import { DISCORD_LINK } from "~/lib/env"
import { DISCORD_LINK, IPFS_GATEWAY } from "~/lib/env"
export default async function middleware(req: NextRequest) {
const { pathname } = req.nextUrl
@@ -29,8 +29,11 @@ export default async function middleware(req: NextRequest) {
if (
pathname.startsWith("/api/") ||
pathname.startsWith("/dashboard") ||
pathname.startsWith("/_next") ||
pathname === "/ipfs-gateway-sw.js"
pathname.startsWith("/_next/") ||
pathname.match(/^\/(workbox|worker|fallback)-\w+\.js(\.map)?$/) ||
pathname === "/sw.js" ||
pathname === "/sw.js.map" ||
pathname === "/logo.png"
) {
return NextResponse.next()
}
-12
View File
@@ -42,18 +42,6 @@ const queryClient = new QueryClient({
const persister = createIDBPersister()
try {
if (typeof window !== "undefined") {
navigator.serviceWorker?.getRegistrations?.().then((registrations) => {
registrations?.forEach((registration) => {
registration.unregister()
})
})
}
} catch (error) {
console.warn(error)
}
function MyApp({ Component, pageProps }: any) {
const getLayout = Component.getLayout ?? ((page: any) => page)
const connectModal = useConnectModal()
+40
View File
@@ -0,0 +1,40 @@
import { GetServerSideProps } from "next"
import { fetchGetSite } from "~/queries/site.server"
import { QueryClient } from "@tanstack/react-query"
export const getServerSideProps: GetServerSideProps = async (ctx) => {
ctx.res.setHeader("Content-Type", "application/json")
const queryClient = new QueryClient()
const domainOrSubdomain = ctx.params!.site as string
const site = await fetchGetSite(domainOrSubdomain, queryClient)
ctx.res.write(
JSON.stringify({
name: site.name,
short_name: site.name,
description: site.description,
icons: [
{
src: site.avatars?.[0] || "logo.png",
type: "image/png",
sizes: "any",
},
],
theme_color: "#ffffff",
background_color: "#ffffff",
start_url: "/",
display: "standalone",
orientation: "portrait",
}),
)
ctx.res.end()
return {
props: {},
}
}
const ManifestJson: React.FC = () => null
export default ManifestJson