Hosting a frontend
Keep using your favorite frontend hosting provider
Encore is not opinionated about where you host your frontend, pick the platform that suits your situation best.
Related example
encoredev/examples/nextjs-starter
Next.js + Encore TS Web App Starter. Frontend hosted on Vercel, backend on Encore.
$ encore app create --example=ts/nextjs-starter
Hosting a frontend using Encore
Encore is primarily designed for backend development. It is possible to serve a frontend using Encore but for production we recommend that you deploy your frontend using Vercel, Netlify, or a similar service.
Template engines
You can make use of template engines like Handlebars, Pug, or EJS to render HTML files on the server. Learn more about in the Template Engine docs.
Serving static assets
You can create a api.static
endpoint that serves static frontend assets, including HTML files.
import { api } from "encore.dev/api";
// Using fallback route to serve all files in the ./assets directory under the root path.
export const rootAssets = api.static({
expose: true,
path: "/!path",
dir: "./assets",
// When a file matching the request isn't found, Encore automatically serves a 404 Not Found response.
// You can customize the response by setting the notFound option to specify a file that should be served instead:
notFound: "./assets/not_found.html",
});
Keep in mind that this approach will not work if you have a Single-Page Application (SPA) that uses client-side routing.
Related example
encoredev/examples/static-files
Static files example, sercing HTML files from a directory.
$ encore app create --example=ts/static-files