Skip to content

vite/spa: npm run start using http-server does not support SPA routes #8623

Closed
@ngbrown

Description

@ngbrown

Reproduction

Run this script (PowerShell):

npx create-remix@latest remix-spa-test -y --template remix-run/remix/templates/spa
cd .\remix-spa-test
echo "export default function Hello() { return <>Hello</>; }" | Out-File ./app/routes/hello.tsx -Encoding utf8
echo "import { Link } from `"@remix-run/react`";`n`nexport default function Index() { return <Link to=`"/hello`">Navigate</Link>; }" | Out-File ./app/routes/_index.tsx  -Encoding utf8
npm run build
npm run start

Open browser directly to http://127.0.0.1:8080/hello (change port if needed). Also try reloading the browser (F5) after navigating to the /hello route from the root (/) path.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i7-12850HX
    Memory: 31.75 GB / 63.67 GB
  Binaries:
    Node: 18.17.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.6.7 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.83)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    @remix-run/dev: ^2.5.1 => 2.5.1
    @remix-run/node: ^2.5.1 => 2.5.1
    @remix-run/react: ^2.5.1 => 2.5.1
    vite: ^5.0.12 => 5.0.12

Used Package Manager

npm

Expected Behavior

When previewing a build, the server should support SPA fallback mode (serving multiple paths from a single index.html file) when using the SPA template. Use vite preview or sirv-cli --single as alternatives. (vite preview is powered by sirv).

No simple solutions that I found are especially production ready as they don't set the cache-control header for ./assets files separately from other files.

Actual Behavior

Navigating directly to a sub-route such as http://127.0.0.1:8080/hello fails with an HTTP ERROR 404.

Navigating to the page when starting at http://127.0.0.1:8080/ works correctly, but reloading once navigated to http://127.0.0.1:8080/hello also fails with an HTTP ERROR 404.

http-server does not support SPA mode. (it has been much discussed, but left unresolved, see http-party/http-server#772).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions