Skip to content

Commit

Permalink
build: pwa setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungJL committed May 11, 2024
1 parent 7df1b70 commit f993e31
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
25 changes: 25 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"background_color": "#ffffff",
"description": "카공 및 친목 동아리",
"dir": "ltr",
"display": "standalone",
"name": "ABOUT",
"orientation": "any",
"scope": "/",
"short_name": "ABOUT",
"start_url": "https://studyabout.herokuapp.com/",
"theme_color": "#ffffff",
"icons": [
{
"src": "/ogImage.png",
"type": "image/png",
"sizes": "977x498"
},
{
"src": "/favicon.ico",
"type": "image/png",
"sizes": "512x512"
}
],
"lang": "ko"
}
7 changes: 6 additions & 1 deletion pageTemplates/layout/BaseScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ function BaseScript() {
strategy="afterInteractive"
/>
<Script src="https://kit.fontawesome.com/4071928605.js" crossOrigin="anonymous" />
<Script src="https://developers.kakao.com/sdk/js/kakao.js" strategy="lazyOnload" />
<Script src="https://developers.kakao.com/sdk/js/kakao.js" strategy="lazyOnload" />{" "}
<Script
src="https://cdn.jsdelivr.net/npm/@pwabuilder/pwaupdate"
type="module"
strategy="afterInteractive"
/>
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion pageTemplates/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { config } from "@fortawesome/fontawesome-svg-core";
import { GoogleAnalytics } from "@next/third-parties/google";
import axios from "axios";
import { usePathname, useRouter } from "next/navigation";
import { signOut, useSession } from "next-auth/react";
import { usePathname, useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { useSetRecoilState } from "recoil";

Expand Down
1 change: 1 addition & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class MyDocument extends Document {
<meta property="og:image" content="/ogImage.png" />
<meta property="og:locale" content="ko_KR" />
<meta property="og:site_name" content="https://studyabout.herokuapp.com" />
<link rel="manifest" href="manifest.json" />
<meta charSet="utf-8" key="charset" />{" "}
<Script src="https://kit.fontawesome.com/4071928605.js" crossOrigin="anonymous"></Script>
</Head>
Expand Down
5 changes: 5 additions & 0 deletions pages/offline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Offline() {
return <>오프라인 연결 안됨</>;
}

export default Offline;
52 changes: 52 additions & 0 deletions pwabuilder-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This is the service worker with the combined offline experience (Offline page + Offline copy of pages)

const CACHE = "pwabuilder-offline-page";

importScripts("https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js");

// TODO: replace the following with the correct offline fallback page i.e.: const offlineFallbackPage = "offline.html";
const offlineFallbackPage = "offline.tsx";

self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});

self.addEventListener("install", async (event) => {
event.waitUntil(caches.open(CACHE).then((cache) => cache.add(offlineFallbackPage)));
});

if (workbox.navigationPreload.isSupported()) {
workbox.navigationPreload.enable();
}

workbox.routing.registerRoute(
new RegExp("/*"),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE,
}),
);

self.addEventListener("fetch", (event) => {
if (event.request.mode === "navigate") {
event.respondWith(
(async () => {
try {
const preloadResp = await event.preloadResponse;

if (preloadResp) {
return preloadResp;
}

const networkResp = await fetch(event.request);
return networkResp;
} catch (error) {
const cache = await caches.open(CACHE);
const cachedResp = await cache.match(offlineFallbackPage);
return cachedResp;
}
})(),
);
}
});

0 comments on commit f993e31

Please sign in to comment.