Skip to content
App
Markdown

Deploy Nuxt

Deploy a Nuxt app on Pilvia App with server rendering — a two-file Nitro preset turns Nuxt's server into the platform's fetch handler. Static generation works as-is.

Nuxt runs on Pilvia App both ways: nuxt generate output deploys as a static site, and a server-rendered Nuxt app runs in an EU-hosted isolate through a small Nitro custom preset. The preset is two files in your project. It extends Nitro's own base-worker preset, which bundles everything into one module with no Node.js, and emits the platform's export default { fetch }.

Tested with Nuxt 4.6 (nitropack 2.13, Vue 3.5) on 2026-11-20.

Static: nuxt generate

bunx nuxt generate
pilvia.app.json
{ "name": "my-site", "auth": "public", "assets": ".output/public" }

Pages are rendered at build time, so anything per-request (the date, the visitor, server routes under server/) is absent. For that, render on the server.

Server rendering

pilvia-preset/nitro.config.ts
// A Nitro custom preset: Nitro's own `base-worker` (no Node, everything
// bundled, one file), emitted as an ES module whose default export is the
// platform's `{ fetch }`. Client assets stay in `.output/public`.
import { fileURLToPath } from "node:url";

export default {
  extends: "base-worker",
  entry: fileURLToPath(new URL("./entry.ts", import.meta.url)),
  rollupConfig: {
    output: { format: "esm", entryFileNames: "index.mjs" },
  },
};
pilvia-preset/entry.ts
import { useNitroApp } from "nitropack/runtime";

const nitroApp = useNitroApp();

export default {
  async fetch(request: Request, env: unknown, ctx: unknown) {
    const url = new URL(request.url);
    const body =
      request.method === "GET" || request.method === "HEAD" ? undefined : await request.arrayBuffer();
    return nitroApp.localFetch(url.pathname + url.search, {
      host: url.host,
      // "https", not "https:", so h3's getRequestURL reports https.
      protocol: url.protocol.replace(/:$/, ""),
      method: request.method,
      headers: request.headers,
      body,
      // Nitro spreads `_platform` into event.context.
      context: { _platform: { pilvia: { env, ctx } } },
    });
  },
};
nuxt.config.ts
export default defineNuxtConfig({
  nitro: { preset: "./pilvia-preset" },
});
pilvia.app.json
{
  "name": "my-app",
  "auth": "public",
  "kv": true,
  "bundle": ".output/server/index.mjs",
  "assets": ".output/public"
}
bunx nuxt build
pilvia app deploy

The host serves .output/public first: prerendered routes, the client bundle and your public/ files. Every other request reaches Nitro, which renders pages, runs server/ routes and answers its own 404s. Hashed files under /_nuxt/ are cached for a year (caching).

The platform in server routes

The preset puts the platform's env in the h3 event's context, where every server route, middleware and plugin can read it: env.kv and env.cache, env.user and the data bindings. A small auto-imported helper keeps it typed:

server/utils/platform.ts
import type { H3Event } from "h3";

export function usePilviaEnv(event: H3Event): any {
  const env = (event.context as any).pilvia?.env;
  if (!env) throw createError({ statusCode: 500, statusMessage: "no platform env" });
  return env;
}
server/api/guestbook.post.ts
export default defineEventHandler(async (event) => {
  const env = usePilviaEnv(event);
  const form = await readFormData(event);
  const name = String(form.get("name") ?? "").slice(0, 40) || "anon";
  const entries = (await env.kv.get("guestbook", "json")) ?? [];
  await env.kv.put("guestbook", [...entries, { name }].slice(-20));
  return sendRedirect(event, "/guestbook", 303);
});

A plain <form method="post" action="/api/guestbook"> reaches it with no client JavaScript. Pages that call useFetch("/api/…") during server rendering go through Nitro in-process, with the same context, so they see env too.

What was tested

Feature Result
Server rendering, Intl in fi-FI, useRequestHeader("x-pilvia-request-id") ✓
Dynamic page posts/[slug].vue with useFetch; createError({ statusCode: 404 }) ✓ 200 / 404
Unknown path ✓ Nuxt's 404
Server route returning JSON ✓
Form POST (urlencoded and multipart) writing env.kv, read back by an SSR page ✓ 303, then the new row
routeRules prerender ✓ served by the host, no isolate
Hashed client files under /_nuxt/ ✓ max-age=31536000, immutable
Hydration, client state and NuxtLink navigation in a browser ✓ no console errors
nuxt generate as a static site ✓

Responses are buffered rather than streamed, which is how nitropack 2 renders.

Type to search. ↑↓ to move, Enter to open, Esc to close.