diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 16d1be1..0995296 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,9 +4,11 @@ on: push: branches: - main + - feat/pipable-stream pull_request: branches: - main + - feat/pipable-stream jobs: yarn: diff --git a/README.md b/README.md index 450a780..673d5f4 100644 --- a/README.md +++ b/README.md @@ -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://:PORT` +3. finally add your CLIENT_HOST variable to .env file as `https://:PORT` ### Step 2. Environment variables diff --git a/package.json b/package.json index c5d939d..cae2b6e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pwa/sw.ts b/pwa/sw.ts index 9b87c59..963922d 100644 --- a/pwa/sw.ts +++ b/pwa/sw.ts @@ -1,3 +1,4 @@ +import join from 'url-join' import { precacheAndRoute } from 'workbox-precaching' import { googleFontsCache, imageCache, offlineFallback, staticResourceCache } from 'workbox-recipes' import { setDefaultHandler } from 'workbox-routing' @@ -5,15 +6,28 @@ 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 = { + * "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() diff --git a/src/common/env/env.util.ts b/src/common/env/env.util.ts index 66fd647..c4051e0 100644 --- a/src/common/env/env.util.ts +++ b/src/common/env/env.util.ts @@ -12,7 +12,7 @@ export function createEnv({ clientPrefix = 'CLIENT_' }: Props) { const client = schema.pick(Object.keys(schema.shape).filter(k => k.startsWith(clientPrefix))) - const { data, error } = parse((IS_SERVER ? schema : client) as ObjectSchema, envs) + const { data, error } = parse((IS_SERVER || IS_SPA ? schema : client) as ObjectSchema, envs) if (error) { console.error('❌ Invalid environment variables:', error.errors) diff --git a/yarn.lock b/yarn.lock index 904dab9..c4e4d6c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"