@codealpha/serve-spa

serve a SPA that uses url for routing

Usage no npm install needed!

<script type="module">
  import codealphaServeSpa from 'https://cdn.skypack.dev/@codealpha/serve-spa';
</script>

README

This module namespaces the Single Page App url's to prevent clashes with existing server url's.

Provide any token such as __REPLACE_BASEURL_HERE__ in the index.html to be replaced with the baseUrl to the SPA router.

<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="icon" href="__REPLACE_BASEURL_HERE__/favicon.ico" />
  </head>
  <body>
    <script>
      window.base_uri = "__REPLACE_BASEURL_HERE__";
    </script>
  </body>
</html>
    .Router()
    .use(
      "/ui",
      await serveSPA({
        indexPath: __dirname + "/public/index.html",
        publicPath: __dirname + "/public",
        replaceToken: "__REPLACE_BASEURL_HERE__",
      })
    )