diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cd762b2..6e213b7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,6 +3,12 @@ name: Deploy GitHub Pages on: push: branches: [main] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write concurrency: group: "pages" @@ -14,39 +20,42 @@ jobs: defaults: run: working-directory: ./app + env: + BASE_PATH: /SpotMicroESP32-Leika steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: pnpm/action-setup@v2 with: version: 9 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 20 - cache: pnpm + cache: "pnpm" + cache-dependency-path: "./app/pnpm-lock.yaml" - run: pnpm install - run: pnpm run build - name: Setup Pages - uses: actions/configure-pages@v3 + uses: actions/configure-pages@v4 with: static_site_generator: "sveltekit" - name: Upload artifact - uses: actions/upload-pages-artifact@v1 + uses: actions/upload-pages-artifact@v3 with: - path: build/ + path: app/build/ deploy: runs-on: ubuntu-latest needs: build environment: name: github-pages - url: ${{ steps.deployment.outputs.page_url }} steps: - - uses: actions/deploy-pages@v2 + - name: Deploy id: deployment + uses: actions/deploy-pages@v4 diff --git a/app/src/routes/+layout.ts b/app/src/routes/+layout.ts index b0fd523..9f306b8 100644 --- a/app/src/routes/+layout.ts +++ b/app/src/routes/+layout.ts @@ -1,22 +1,22 @@ -export const prerender = false; -export const ssr = false; +export const prerender = true +export const ssr = false const registerFetchIntercept = async () => { - const { fetch: originalFetch } = window; - const fileService = (await import('$lib/services/file-service')).default; + const { fetch: originalFetch } = window + const fileService = (await import('$lib/services/file-service')).default window.fetch = async (resource, config) => { - let url = resource instanceof Request ? resource.url : resource.toString(); - let file = await fileService?.getFile(url); - return file?.isOk() ? new Response(file.inner) : originalFetch(resource, config); - }; -}; + const url = resource instanceof Request ? resource.url : resource.toString() + const file = await fileService?.getFile(url) + return file?.isOk() ? new Response(file.inner) : originalFetch(resource, config) + } +} export const load = async () => { - await registerFetchIntercept(); + await registerFetchIntercept() return { title: 'Spot micro controller', github: 'runeharlyk/SpotMicroESP32-Leika', app_name: 'Spot Micro Controller', - copyright: '2025 Rune Harlyk', - }; -}; + copyright: '2025 Rune Harlyk' + } +} diff --git a/app/svelte.config.js b/app/svelte.config.js index 6fd9bac..d748139 100644 --- a/app/svelte.config.js +++ b/app/svelte.config.js @@ -1,10 +1,10 @@ import adapter from '@sveltejs/adapter-static' import { vitePreprocess } from '@sveltejs/vite-plugin-svelte' +const basePath = process.env.BASE_PATH ?? '' + /** @type {import('@sveltejs/kit').Config} */ const config = { - // Consult https://kit.svelte.dev/docs/integrations#preprocessors - // for more information about preprocessors preprocess: vitePreprocess(), kit: { @@ -14,7 +14,10 @@ const config = { fallback: 'index.html', precompress: false, strict: true - }) + }), + paths: { + base: basePath + } } } diff --git a/app/vite.config.ts b/app/vite.config.ts index a5155a9..d1c77b9 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -1,27 +1,30 @@ -import { sveltekit } from '@sveltejs/kit/vite'; -import { defineConfig } from 'vite'; -import Icons from 'unplugin-icons/vite'; -import viteLittleFS from './vite-plugin-littlefs'; -import EnvCaster from '@niku/vite-env-caster'; -import tailwindcss from '@tailwindcss/vite'; +import { sveltekit } from '@sveltejs/kit/vite' +import { defineConfig } from 'vite' +import Icons from 'unplugin-icons/vite' +import viteLittleFS from './vite-plugin-littlefs' +import EnvCaster from '@niku/vite-env-caster' +import tailwindcss from '@tailwindcss/vite' + +const basePath = process.env.BASE_PATH ?? '' export default defineConfig({ + base: basePath, plugins: [ tailwindcss(), sveltekit(), Icons({ - compiler: 'svelte', + compiler: 'svelte' }), viteLittleFS(), - EnvCaster(), + EnvCaster() ], server: { proxy: { '/api': { target: 'http://spot-micro.local/', changeOrigin: true, - ws: true, - }, - }, - }, -}); + ws: true + } + } + } +})