Server integration
To integrate Vike with a JavaScript server, we recommend using the vike-server
extension which automatically integrates Vike with JavaScript servers (Express.js, Hono, Fastify, ...) and deployment providers (Cloudflare, Vercel, ...) in a seamless fashion.
But you can also manually integrate Vike into your server for full control over your server and deployment.
Manual integration
From the perspective of a server, Vike is just a middleware:
// renderPage() doesn't depend on Node.js and can be used within any JavaScript environment:
// Node.js, AWS, Cloudflare, Vercel, Deno, Bun, Lagon, ...
import { renderPage } from 'vike/server'
// Any server: Express.js, Cloudflare Worker, AWS Lambda Function, Fastify, Hono, Nitro, ...
server.addMiddleware({
method: 'GET',
route: '*', // catch-all
async handler(request) {
const pageContextInit = { urlOriginal: request.url }
const pageContext = await renderPage(pageContextInit)
// `body` is the HTML of the page with a route matching pageContextInit.urlOriginal
const { body, statusCode, headers } = pageContext.httpResponse
const response = { body, statusCode, headers }
return response
}
})
You can embed renderPage()
into any server and any deployment environment.
Alternatively, instead of using
renderPage()
, you can pre-render your pages and remove the need for a production server (and deploy to a static host instead).
Your server code won't be transpiled by Vite out of the box, see #562 - Transpile server code for a list of tools to transpile server code (e.g. to support TypeScript).
If you want to use HTTPS in development, pass the HTTPS certificates to Vite's dev server.
You can use:
- Any server framework (Express, Fastify, Hono, Nitro, Hattip, Koa, Hapi, ...)
- Any authentication strategy/tool (email/password, OAuth, Auth.js, Passport.js, Grant, Keycloak, Auth0, ...).
- Any serverless/edge environment (Cloudflare Workers, Vercel, Firebase, AWS Lambda, Google Cloud Functions, Deno Deploy, ...)
- Any virtual private server (AWS EC2, Google Cloud, ...)
- Any static host (Cloudflare Pages, GitHub Pages, Netlify, ...)
- Any server utility (Docker, Nginx, PM2, ...)
Examples:
See also:
Feel free to reach out if you run into any issues integrating a tool.
Non-JavaScript Backend
You can use Vike with any non-JavaScript backend using the following setup:
- Your non-JavaScript backend implements all the backend business logic while exposing a REST/GraphQL API.
- Your Vike app uses that REST/GraphQL API to render your pages to HTML with SSR or SSG. (The client-side of your Vike app then hydrates the HTML into a rich interactive user interface.)
If want to use SSR then, in addition to your non-JavaScript server, you'll need to deploy a JavaScript SSR server (with Node.js/Deno/Bun, or with an edge worker). Since that JavaScript server is only responsible for server-side rendering your pages to HTML, you can simply deploy it to a serverless/edge platform such as Cloudflare which is inexpensive and scalable.
Alternatively, instead of using a JavaScript server, you can pre-render your pages (SSG) while disabling SSR. In other words: you generate empty HTML shells that you statically deploy (using a static host, or using your own static assets deployment).
The HTML must be generated by Vike because the UI is completely owned by React/Vue/Solid. You cannot generate the HTML using your non-JavaScript backend: React/Vue/Solid would otherwise throw a hydration mismatch.
That way, you can use Vike with any backend:
- Java (Spring, Grails, ...)
- PHP (Laravel, Symfony, CakePHP, ...)
- Ruby on Rails
- Python (Django, Flask, FastAPI, ...)
- Elixir (Phoenix, ...)
- Go (Gin, Echo, Fiber, ...)
- Rust (Actix Web, Rocket, ...)
- Backend-as-a-Service (Firebase, ..)
- ...
Example:
Feel free to reach out if you run into any issues integrating a tool.