/** * @file SPA router * Routes all requests to index.html view. Index.html is a Vue.js single page application. * If in production, manifest.json is parsed and passed to index.html */ import express from "express"; import path from "path"; import fs from "fs/promises"; const router = express.Router(); const environment = process.env.NODE_ENV; router.get(/.*/, async (req, res) => { const manifest = await parseManifest() const data = { environment, manifest } res.render("index.html.ejs", data) }) const parseManifest = async () => { if (environment !== "production") return {} const manifestPath = path.join(path.resolve(), "dist", ".vite", "manifest.json"); const manifestFile = await fs.readFile(manifestPath); return JSON.parse(manifestFile) } export default router;