Svelte App¶
A Svelte single-page application deployed on AppMecca. This example demonstrates deploying a JavaScript framework application as a standalone service.
Overview¶
| Repository | git@gitlab.com:appmecca-sample-apps/svelte-app.git |
| Tech Stack | Svelte / SvelteKit / Node.js |
| Services | web (port 3000) |
| Database | None |
| Cache | None |
| URL Pattern | https://svelte-app-web.{env}.appmecca.net |
What This App Demonstrates¶
- Deploying a Svelte/SvelteKit application on AppMecca
- SvelteKit with
adapter-nodefor server-side rendering - Node.js runtime containers (as opposed to Nginx for static SPAs)
- Alternative JavaScript framework deployment alongside React and Vue
appmecca.yaml¶
containers:
- name: web
dockerfile: Dockerfile
context: .
deploy:
- name: web
container: web
port: 3000
health_check:
path: /health
The configuration is straightforward -- a single container running the SvelteKit Node.js server on port 3000.
Step-by-Step Deployment¶
1. Register the app¶
2. Build the container¶
Expected output
3. Deploy¶
Expected output
4. Verify¶
Test the health endpoint:
Key Concepts¶
SSR vs. static Svelte¶
SvelteKit supports multiple output modes through adapters. This sample app uses adapter-node, which runs a Node.js server and enables server-side rendering.
| Adapter | Output | Runtime | Use case |
|---|---|---|---|
adapter-node |
Node.js server | Node.js process (port 3000) | SSR, API routes, dynamic content |
adapter-static |
Static HTML/CSS/JS | Nginx (port 80) | Pre-rendered pages, pure SPAs |
Runs a live Node.js server. Pages are rendered on the server for each request. Supports API routes and dynamic server-side logic.
Generates static HTML files at build time. Serve them with Nginx using the same pattern as the Static Site example.
Choosing an adapter
Use adapter-node when you need server-side rendering, API routes in +server.js files, or dynamic content that changes per request. Use adapter-static for marketing sites, documentation, or apps where all content can be pre-rendered.
Multi-stage Dockerfile¶
The Dockerfile compiles the SvelteKit app and runs it with a minimal Node.js image:
FROM node:20-slim AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-slim
WORKDIR /app
COPY --from=builder /app/build/ ./build/
COPY --from=builder /app/package*.json ./
RUN npm ci --only=production
EXPOSE 3000
CMD ["node", "build"]
Unlike the React example (which serves static files with Nginx), the Svelte SSR app runs an actual Node.js process. The final image is larger (~200 MB) because it includes the Node.js runtime.
Health check endpoint¶
For SvelteKit apps, define a health endpoint as a server route:
// src/routes/health/+server.js
export function GET() {
return new Response(
JSON.stringify({ status: 'healthy' }),
{ headers: { 'Content-Type': 'application/json' } }
);
}
This is a SvelteKit API route -- it runs on the server and responds to GET requests at /health.
Viewing logs¶
Monitor your Svelte app's server-side output. The app name is the positional
argument; the service is selected with -s:
Useful filters:
# Container stdout/stderr only, last 24 hours
mecca logs svelte-app -s web --type container --since 24h -e dev
# Errors only
mecca logs svelte-app -s web --level error -e dev
# Full-text search
mecca logs svelte-app -s web --search "timeout" -e dev
What's Next?¶
- React Frontend -- compare with the SPA/Nginx deployment pattern
- Static Site -- the simplest frontend deployment
- Multi-Container App -- pair a frontend with a backend API
- Service Management -- restart, stop, and monitor your services