Serve SPA
Make frontend apps with Deno.
SYNOPSIS
deno run https://deno.land/x/serve_spa/main.ts [OPTION]... [ROOT]DESCRIPTION
Spins up a dev server for single-page applications (SPA). Serves static files
from ROOT or current directory if not specified. Compiles TypeScript on the
fly.
OPTIONS
-q,--quietSuppress logging.
-p,--port PORTPort to listen on. Default is 8123.
--index-fallbackRender root
index.htmlat every extension-less path that doesnât match a file or directory.--import-map-file IMPORT_MAP_FILEInject import map JSON file into HTML files. Use this to use your Deno import map in the browser.
--path-alias URL_PATH=FS_PATHRewrite URL_PATH to FS_PATH.
--corsEnable CORS.
--jsx MODEEnable JSX transformation. Available modes are âclassicâ and âautomaticâ.
--jsx-import-source IMPORT_SOURCESet the import source when JSX mode is âautomaticâ.
--jsx-factory FACTORYSet the JSX factory when JSX mode is âclassicâ.
--jsx-fragment-factory FACTORYSet the JSX fragment factory when JSX mode is âclassicâ.
JS API
Example:
import { serveSpa } from "https://deno.land/x/serve_spa/mod.ts";
Deno.serve({ port }, async (request) => {
return await serveSpa(request, {
fsRoot: "./web",
indexFallback: true,
pathAliasMap: {
"/favicon.png": "../logo.png",
"/utils/*": "../utils/",
},
importMapFile: "../deno.json",
});
});