Skip to content

Commit b742e99

Browse files
committed
Isolate SPA build output from public files
1 parent 0d6284b commit b742e99

7 files changed

Lines changed: 14 additions & 15 deletions

File tree

.dockerignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@ renovate.json
2020
spec/
2121
tmp/
2222
work/
23-
public/assets/
24-
public/frontend/
25-
public/index.html
23+
frontend/dist/

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838

3939
# Ignore frontend build output and tooling caches
4040
/frontend/dist/
41-
/public/assets/
42-
/public/index.html
4341
/frontend/node_modules/
44-
/public/frontend
4542
/frontend/playwright-report/
4643
/frontend/test-results/
4744

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ COPY --chown=$USER:$USER Gemfile Gemfile.lock app.rb config.ru ./
9393
COPY --chown=$USER:$USER app ./app
9494
COPY --chown=$USER:$USER config ./config
9595
COPY --chown=$USER:$USER public ./public
96-
COPY --from=frontend-builder --chown=$USER:$USER /app/public/index.html ./public/index.html
97-
COPY --from=frontend-builder --chown=$USER:$USER /app/public/assets ./public/assets
96+
COPY --from=frontend-builder --chown=$USER:$USER /app/frontend/dist ./frontend/dist
9897

9998
CMD ["bundle", "exec", "puma", "-C", "./config/puma.rb"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ html2rss-web converts arbitrary websites into RSS 2.0 feeds with a slim Ruby bac
2020
## Architecture
2121

2222
- **Backend:** Ruby + Roda, backed by the `html2rss` gem for extraction.
23-
- **Frontend:** Preact app built with Vite into `public/`.
23+
- **Frontend:** Preact app built with Vite into `frontend/dist` and served at `/`.
2424
- **Distribution:** Docker Compose by default; other deployments require manual wiring.
2525
- [Project notes](docs/README.md)
2626

@@ -101,7 +101,7 @@ The OpenAPI file is generated from Ruby request specs only.
101101
| Command | Purpose |
102102
| ----------------------- | -------------------------------------------- |
103103
| `npm run dev` | Vite dev server with hot reload (port 4001). |
104-
| `npm run build` | Build static assets into `public/`. |
104+
| `npm run build` | Build static assets into `frontend/dist/`. |
105105
| `npm run test:run` | Unit tests (Vitest). |
106106
| `npm run test:contract` | Contract tests with MSW. |
107107

app.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class App < Roda
3131
</body>
3232
</html>
3333
HTML
34+
FRONTEND_DIST_PATH = 'frontend/dist'
35+
FRONTEND_INDEX_PATH = File.join(FRONTEND_DIST_PATH, 'index.html')
3436
def self.development? = EnvironmentValidator.development?
3537

3638
def development? = self.class.development?
@@ -80,6 +82,10 @@ def development? = self.class.development?
8082
}
8183

8284
plugin :json_parser
85+
plugin :static,
86+
['/assets'],
87+
root: FRONTEND_DIST_PATH,
88+
headers: { 'Cache-Control' => 'public, max-age=31536000, immutable' }
8389
plugin :public
8490
plugin :head
8591
plugin :not_allowed
@@ -100,9 +106,8 @@ def development? = self.class.development?
100106
private
101107

102108
def render_index_page(router)
103-
index_path = 'public/index.html'
104109
router.response['Content-Type'] = 'text/html'
105-
File.exist?(index_path) ? File.read(index_path) : FALLBACK_HTML
110+
File.exist?(FRONTEND_INDEX_PATH) ? File.read(FRONTEND_INDEX_PATH) : FALLBACK_HTML
106111
end
107112
end
108113
end

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The only other file that belongs in `docs/` is the generated OpenAPI contract at
99
## System Snapshot
1010

1111
- Backend: Ruby + Roda under the `Html2rss::Web` namespace.
12-
- Frontend: Preact + Vite, built into `public/`.
12+
- Frontend: Preact + Vite, built into `frontend/dist` and served at `/`.
1313
- Feed extraction: delegated to the `html2rss` gem.
1414
- Distribution: Docker Compose / Dev Container first.
1515

frontend/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineConfig({
2020
exclude: ['msw/node'],
2121
},
2222
build: {
23-
outDir: '../public',
24-
emptyOutDir: false,
23+
outDir: './dist',
24+
emptyOutDir: true,
2525
},
2626
});

0 commit comments

Comments
 (0)