Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5a7272f
create initial `offline.html`
DevlinRocha Mar 31, 2025
702f7a2
add `/offline.html` to `routesToCache`
DevlinRocha Mar 31, 2025
d6e2ef0
return cached offline page
DevlinRocha Mar 31, 2025
8eb35fb
improve offline page
DevlinRocha Mar 31, 2025
f7172b7
Merge branch 'main' into staging
DevlinRocha Mar 31, 2025
336753a
wrap offline page in response
DevlinRocha Mar 31, 2025
cb8fc49
fix usage of cache
DevlinRocha Mar 31, 2025
5a1e5b7
embed HTML in service worker
DevlinRocha Mar 31, 2025
d4595c1
temporarily include page in allowed origins
DevlinRocha Mar 31, 2025
0c8e93f
return cached offline page
DevlinRocha Mar 31, 2025
5af99d4
wrap offline in response
DevlinRocha Mar 31, 2025
f4bc9aa
convert response to text
DevlinRocha Mar 31, 2025
7339c78
use `await`
DevlinRocha Mar 31, 2025
73c5e89
move `offline.html`
DevlinRocha Mar 31, 2025
4995f8f
fix cached offline page
DevlinRocha Mar 31, 2025
77756b0
move `offline.html`
DevlinRocha Mar 31, 2025
b271099
add html tags
DevlinRocha Mar 31, 2025
1edf61f
set `charset=UTF-8`
DevlinRocha Apr 1, 2025
8384e06
adjust `offline.html` output
DevlinRocha Apr 1, 2025
6fb1d7d
lowercase utf
DevlinRocha Apr 1, 2025
5c78902
update `vite` to version `6.2.4`
DevlinRocha Apr 1, 2025
0f67625
remove wrapping tags
DevlinRocha Apr 1, 2025
90cb975
don't copy `offline.html` to `dist` directory
DevlinRocha Apr 1, 2025
82dd119
remove `charset=utf-8`
DevlinRocha Apr 1, 2025
2ad5c13
remove offline cache from service worker
DevlinRocha Apr 1, 2025
04dd410
fetch and cache offline page during service worker install
DevlinRocha Apr 1, 2025
a660c52
take in a `message` to display
DevlinRocha Apr 1, 2025
6ab8463
use custom not found messages
DevlinRocha Apr 1, 2025
30157f7
remove cached offline page
DevlinRocha Apr 2, 2025
291e49a
send response when network is offline
DevlinRocha Apr 2, 2025
41015a4
fix typecheck error
DevlinRocha Apr 2, 2025
a4eb62b
send `undefined` response
DevlinRocha Apr 2, 2025
da05704
`throw notFound()`
DevlinRocha Apr 2, 2025
b2a88a6
respond with `offline`
DevlinRocha Apr 2, 2025
e24728b
respond with `offlineBody` from cache
DevlinRocha Apr 2, 2025
74b697e
cache offline response
DevlinRocha Apr 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"postcss": "^8.5.3",
"prettier-plugin-tailwindcss": "^0.6.11",
"tailwindcss": "^3.4.17",
"vite": "^6.2.3"
"vite": "^6.2.4"
}
}
15 changes: 14 additions & 1 deletion apps/frontend/public/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,20 @@ addEventListener('fetch', (event) => {
return cachedResponse
}

return await handleFetch(event.request, cache)
try {
return await handleFetch(event.request, cache)
} catch (error) {
console.error(
`Failed to fetch from network for ${event.request.url}:`,
error
)

return new Response(undefined, {
status: 503,
statusText: 'Service Unavailable',
headers: { 'Content-Type': 'text/html' },
})
}
})()
)
})
3 changes: 0 additions & 3 deletions apps/frontend/scripts/generate-resource-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ const assetPaths = Object.values(manifest).flatMap((entry) => [
])

const favicons = ['icon.svg', 'icon-512.png', 'icon-192.png', '/favicon.ico']

const resourcesToCache = [...routesToCache, ...assetPaths, ...favicons]

const resourceList = `const RESOURCE_LIST = ${JSON.stringify(resourcesToCache, null, 2)};`

fs.writeFileSync(outputPath, resourceList)

console.log('Resource list generated:', outputPath)
2 changes: 1 addition & 1 deletion apps/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import './index.css'
const router = createRouter({
scrollRestoration: true,
defaultHashScrollIntoView: { behavior: 'smooth' },
defaultNotFoundComponent: DefaultNotFound,
defaultNotFoundComponent: () => <DefaultNotFound />,
routeTree,
})

Expand Down
10 changes: 8 additions & 2 deletions apps/frontend/src/components/DefaultNotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useRouter, Link } from '@tanstack/react-router'

export default function DefaultNotFound() {
type DefaultNotFoundProps = {
message?: string
}

export default function DefaultNotFound({
message = 'page not found',
}: DefaultNotFoundProps) {
const router = useRouter()

const faces = [
Expand Down Expand Up @@ -59,7 +65,7 @@ export default function DefaultNotFound() {
</pre>

<h1 className="text-center text-3xl font-semibold md:text-4xl lg:text-5xl">
page not found
{message}
</h1>
</div>

Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/routes/blog.$blogId.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function BlogPost() {
</h2>
)

if (error) return <DefaultNotFound />
if (!post) return <DefaultNotFound />
if (error) return <DefaultNotFound message="error loading post" />
if (!post) return <DefaultNotFound message="post not found" />

return (
<main className="flex flex-col">
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend/src/routes/blog.index.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ function Blog() {
Loading...
</h2>
)
if (error) return <DefaultNotFound />
if (!data || !data.length) return <DefaultNotFound />
if (error) return <DefaultNotFound message="error loading blog" />
if (!data || !data.length)
return <DefaultNotFound message="blog not found" />

const firstPost = data[0]

Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/routes/blog.search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function BlogSearch() {
Loading...
</h2>
)
if (error) return <DefaultNotFound />
if (!posts) return <DefaultNotFound />
if (error) return <DefaultNotFound message="error searching" />
if (!posts) return <DefaultNotFound message="no posts found" />

return (
<main
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/server/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const allowedOrigins =
'https://devlinrocha.com',
'https://www.devlinrocha.com',
'https://staging.devlinrocha.com',
'https://staging.devlinrocha.pages.dev',
'https://www.staging.devlinrocha.com',
]
: ['http://localhost:4173', 'http://localhost:5173']
Expand Down
Loading