Skip to content

Commit

Permalink
feat: basic config for pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
jw-r committed Dec 1, 2024
1 parent b99ece7 commit 28122e6
Show file tree
Hide file tree
Showing 9 changed files with 1,323 additions and 263 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ next-env.d.ts

# Storybook
storybook-static

# Auto Generated PWA files
**/public/sw.js
**/public/workbox-*.js
**/public/sw.js.map
**/public/workbox-*.js.map
13 changes: 12 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import withPWA from 'next-pwa'

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true, // Enable React strict mode for improved error handling
compiler: {
removeConsole: process.env.NODE_ENV !== 'development', // Remove console.log in production
},
images: {
remotePatterns: [
{
Expand Down Expand Up @@ -29,4 +35,9 @@ const nextConfig = {
},
}

export default nextConfig
export default withPWA({
dest: 'public', // destination directory for the PWA files
disable: process.env.NODE_ENV === 'development', // disable PWA in the development environment
register: true, // register the PWA service worker
skipWaiting: true, // skip waiting for service worker activation
})(nextConfig)
1,490 changes: 1,228 additions & 262 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"lucide-react": "^0.367.0",
"next": "14.1.4",
"next-auth": "^5.0.0-beta.17",
"next-pwa": "^5.6.0",
"prettier": "^2.8.8",
"qs": "^6.12.1",
"react": "^18",
Expand Down
Binary file added public/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "PWA Next.js",
"short_name": "pwa-nextjs",
"theme_color": "#35155D",
"background_color": "#ffffff",
"display": "standalone",
"orientation": "portrait",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "icons/icon.png",
"sizes": "48x48",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "72x72",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "144x144",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "152x152",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "maskable any"
},
{
"src": "icons/icon.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable any"
}
],
"splash_pages": null
}
1 change: 1 addition & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const viewport: Viewport = {
userScalable: false,
maximumScale: 1.0,
minimumScale: 1.0,
viewportFit: 'cover',
}

export default function RootLayout({
Expand Down
1 change: 1 addition & 0 deletions src/features/common/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const Metadatas = {
return {
metadataBase: new URL(`https://www.picktoss.com`),
title: '픽토스 | 나만의 AI 퀴즈',
manifest: '/manifest.json',
description: 'AI로 생성하는 나만의 퀴즈',
icons: {
icon: '/images/picktoss-logo.png',
Expand Down
7 changes: 7 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ const publicOnlyUrls: Routes = {
'/sign-in': true,
}

const PUBLIC_FILE = /\.(.*)$/

export async function middleware(request: NextRequest) {
const isPublicFiles = PUBLIC_FILE.test(request.nextUrl.pathname)
if (isPublicFiles) {
return
}

const session = await auth()
const publicExists = publicUrls[request.nextUrl.pathname]
const exists = publicOnlyUrls[request.nextUrl.pathname]
Expand Down

0 comments on commit 28122e6

Please sign in to comment.