Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): @nrwl/web:file-server throws 404 after refresh #9839

Merged
merged 1 commit into from Jun 10, 2022

Conversation

imhuytq
Copy link
Contributor

@imhuytq imhuytq commented Apr 14, 2022

As reported in #5118, using @nrwl/web:file-server will get a 404 code on browser refresh for any route other than the root.

Current Behavior

Expected Behavior

Added spa option to allow handling of routes other than root.

{
    "buildTarget": "app:build:production",
    "spa": true
}

Related Issue(s)

Fixes #5118

@nx-cloud
Copy link

nx-cloud bot commented Apr 14, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f64cacc. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 12 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented Apr 14, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nrwl/nx-dev/GGsGfJdiq4ZaNi7ZB9SUE1Tt9RKk
✅ Preview: Ignored

[Deployment for 132cca1 canceled]

Copy link
Member

@AgentEnder AgentEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!


if (options.spa) {
const src = join(outputPath, 'index.html');
const dst = join(outputPath, '494.html');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be 404.html, rather than 494.html

},
"spa": {
"type": "boolean",
"description": "Serve `SPA` app.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably detail the differences, rather than just reiterating the option name. Something like: Redirect not-found errors to index.html (useful for SPAs).

@jaysoo jaysoo assigned AgentEnder and unassigned jaysoo Jun 2, 2022
@AgentEnder
Copy link
Member

@imhuytq There are some conflicts now as well, as soon as those are addressed and the comments taken care of this should be ready to go.

@vercel
Copy link

vercel bot commented Jun 10, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview Jun 10, 2022 at 6:16PM (UTC)

@imhuytq
Copy link
Contributor Author

imhuytq commented Jun 10, 2022

Hi @AgentEnder , Thanks for your review. Please check my updates.

Copy link
Member

@AgentEnder AgentEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now, I'll rebase it to remove the husky changes and then work on getting it merged. Thanks for the contribution 🎉

Comment on lines 1 to 30
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}

readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi

exit 0
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be in this PR 🤔

fix(web): add `spa` option

fix(web): delete the 404.html file after shutting down the server

docs(web): update docs
@joewIST
Copy link

joewIST commented Aug 23, 2022

Is anyone else still getting 404s on browser refresh, even with "spa": true in the serve options?

@el-davo
Copy link

el-davo commented Sep 28, 2022

@joewIST Yes I am still getting 404s when my url contains query parameters like so /home/123?snack=cake

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refresh throws 404 when using @nrwl/web:file-server
5 participants