Skip to content

Commit

Permalink
feat: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
denchiklut authored Sep 29, 2024
1 parent a1ac5d9 commit 0a4a93d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- feat/pipable-stream
pull_request:
branches:
- main
- feat/pipable-stream

jobs:
yarn:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ If you need to use https, follow these steps:

1. in `setup.sh` change the `domain` variable to your domain
2. run the command `yarn setup`
3. finally add your HOST variable to .env file as `https://<YOUR-domain>:PORT`
3. finally add your CLIENT_HOST variable to .env file as `https://<YOUR-domain>:PORT`

### Step 2. Environment variables

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"react-router": "^6.26.2",
"react-router-dom": "^6.26.2",
"reflect-metadata": "^0.2.2",
"url-join": "^5.0.0",
"uuid": "^10.0.0",
"winston": "^3.14.2",
"workbox-window": "^7.1.0",
Expand Down
24 changes: 19 additions & 5 deletions pwa/sw.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import join from 'url-join'
import { precacheAndRoute } from 'workbox-precaching'
import { googleFontsCache, imageCache, offlineFallback, staticResourceCache } from 'workbox-recipes'
import { setDefaultHandler } from 'workbox-routing'
import { NetworkOnly } from 'workbox-strategies'

declare const self: ServiceWorkerGlobalScope

const publicPath = (process.env.PUBLIC_PATH ?? '/').replace(/\/$/, '')
/**
* const CDN = "https://cdn.example.com"
* const paths: Collection<string, string> = {
* "www.example.com": join(CDN, "prod/app"),
* "staging.example.com": join(CDN, "dev/app"),
* "local-app.example.com:3000": "/",
* }
* const publicPath = paths[self.location.host] ?? join(CDN, "staging/app")
*/

precacheAndRoute(self.__WB_MANIFEST)
const publicPath = '/'

precacheAndRoute(
self.__WB_MANIFEST.map(item => {
if (typeof item === 'string') return join(publicPath, item)
return { ...item, url: join(publicPath, item.url) }
})
)
staticResourceCache()
googleFontsCache()
imageCache({ maxEntries: 60 })
offlineFallback({
pageFallback: `${publicPath}/pwa/offline.html`
})
offlineFallback({ pageFallback: join(publicPath, 'pwa/offline.html') })
setDefaultHandler(new NetworkOnly())
addEventListener('message', ({ data }) => {
if (data.type === 'SKIP_WAITING') self.skipWaiting()
Expand Down
2 changes: 1 addition & 1 deletion src/common/env/env.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function createEnv<S extends AnyObject>({
clientPrefix = 'CLIENT_'
}: Props<S>) {
const client = schema.pick(Object.keys(schema.shape).filter(k => k.startsWith(clientPrefix)))
const { data, error } = parse((IS_SERVER ? schema : client) as ObjectSchema<S>, envs)
const { data, error } = parse((IS_SERVER || IS_SPA ? schema : client) as ObjectSchema<S>, envs)

if (error) {
console.error('❌ Invalid environment variables:', error.errors)
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9560,6 +9560,11 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

url-join@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/url-join/-/url-join-5.0.0.tgz#c2f1e5cbd95fa91082a93b58a1f42fecb4bdbcf1"
integrity sha512-n2huDr9h9yzd6exQVnH/jU5mr+Pfx08LRXXZhkLLetAMESRj+anQsTAh940iMrIetKAmry9coFuZQ2jY8/p3WA==

url-parse@^1.5.3:
version "1.5.10"
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
Expand Down

0 comments on commit 0a4a93d

Please sign in to comment.