Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#130 pwa #132

Merged
merged 12 commits into from
Aug 5, 2022
Binary file removed public/favicon.ico
Binary file not shown.
Binary file added public/images/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 17 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<html lang="ko">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="apple-touch-icon-precomposed" href="%PUBLIC_URL%/favicon.ico" />
<link rel="favicon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="manifest" href="./manifest.json" />

<link rel="icon" type="image/png" href="./images/logo.png" />
<link rel="apple-touch-icon" href="./images/logo.png" />
<link rel="apple-touch-icon-precomposed" href="./images/logo.png" />
<link rel="favicon" href="./images/logo.png" />

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="theme-color" content="#000000" />

Expand All @@ -29,15 +32,23 @@
<meta property="twitter:image" content="https://piiklebucket11.s3.ap-northeast-2.amazonaws.com/mainbanner01.jpg">

<link rel="canonical" href="www.piickle.link"/>

<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" />

</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>
if("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("./pwaServiceWorker.js")
.then((reg) => console.log("success: ", reg.scope))
.catch((err) => console.log("Failure: ", err));
Comment on lines +47 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 성공하면, 로컬호스트 뜨던데!! 연결이 됐는지 확인하는 용도의 console일까여??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요 !! 지워도 될 거 같으네요 !!!?

})
}
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"short_name": "Piickle",
"name": "Piickle",
"description": "지금 내게 필요한 대화주제 추천 서비스, Piickle",
"theme_color": "#000000",
"background_color": "#ffffff",
"dir": "ltr",
"display": "standalone",
"orientation": "any",
"scope": "/",
"start_url": ".",
"icons": [
{
"src": "images/logo.png",
"type": "image/x-icon",
"sizes": "512x512",
"purpose": "any maskable"
},
{
"src": "images/logo.png",
"type": "image/png",
"sizes": "512x512"
},
Comment on lines +13 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 두 칭구는 뭐가 다른건가욤??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NYeonK
type 이 달라서 그냥 중복된 이미지로 선언해서 적용했던 건데,
이후에 릴리즈 직전에 디자인 팀에 다시 이미지 요청해서 제대로 작성하려구 !!
날카롭네요⚡⚡

{
"src": "images/banner.jpg",
"type": "image/jpg",
"sizes": "480x288",
"purpose": "any maskable"
}
]
}
34 changes: 34 additions & 0 deletions public/offline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>No Internet Connection</title>
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" />
</head>
<body>
<main style="height: 100vh;
padding: 6.4rem 1.6rem 0;
background-color: #EEF5F3"
>
<h1 style="font-family: Pretendard;
font-weight: 600;
font-size: 20px;
line-height: 130%;
letter-spacing: -0.04rem;"
>인터넷 연결에 실패하였습니다</h1>
<p style="margin-top: 0.8rem;
font-family: Pretendard;
font-weight: 400;
font-size: 14px;
line-height: 140%;
letter-spacing: -0.03rem;
color: #606060;"
>인터넷 연결을 확인하고 다시 시도해주십시오</p>
</main>
</body>
</html>
68 changes: 68 additions & 0 deletions public/pwaServiceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable no-undef */
importScripts("https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js");

const CACHE = "pwabuilder-page";

const offlineFallbackPage = "offline.html";
const urlsToCache = ["index.html", offlineFallbackPage];

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

// SW 설치
self.addEventListener("install", async (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => {
console.log("Opened Cache");
return cache.addAll(urlsToCache);
}),
);
});

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

// Listen for requests
self.addEventListener("fetch", (event) => {
if (event.request.mode === "navigate") {
event.respondWith(
(async () => {
try {
// 만약 preload 된 response가 있으면 받는다
const preloadResp = await event.preloadResponse;
if (preloadResp) return preloadResp;

// 만약 없으면 network를 이용한다
const networkResp = await fetch(event.request);
return networkResp;
} catch (error) {
// 인터넷 연결이 불안정할 경우, offline 페이지를 보여준다
const cache = await caches.open(CACHE);
const cachedResp = await cache.match(offlineFallbackPage);
return cachedResp;
}
})(),
);
}
});

// SW 활성화
// 업데이트 할 때마다 caching 을 확인하고 promise 를 동작함
self.addEventListener("activate", (event) => {
const cacheWhiteList = [];
cacheWhiteList.push(CACHE);

event.waitUntil(
caches.keys().then((cachesNames) =>
Promise.all(
cachesNames.map((cacheName) => {
if (!cacheWhiteList.includes(cacheName)) return caches.delete(cacheName);
}),
),
),
);
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"include": [
"**/*.ts",
"**/*.tsx", "public/mockServiceWorker.js",
"**/*.tsx", "public/mockServiceWorker.js", "public/pwaServiceWorker.js",
],
"exclude": [
"node_modules"
Expand Down