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

[v2] Properly serve static files #7952

Merged
merged 1 commit into from
Sep 8, 2018
Merged

[v2] Properly serve static files #7952

merged 1 commit into from
Sep 8, 2018

Conversation

Yurickh
Copy link
Contributor

@Yurickh Yurickh commented Sep 7, 2018

Issue #2352 brought to my attention that express.static wasn't serving any static files, leaving all the heavy lifting to lines 161-187.

This is due to the fact that __dirname is the local filename, not the project root.

Actually, express uses the place from where the node process is called (usually the project root) as the actual root for serving static files, so I just went ahead and removed it.

Before, having a public folder like:

static/
  my-custom-folder/
    - index.html

Would raise 404 for /my-custom-folder, but not for /my-custom-folder/index.html or /my-custom-folder/.

Now, when accessing /my-custom-folder, we're getting redirected to /my-custom-folder/, as one might expect.

Edit: this was originally intended to go with v2, but I guess we can hotfix it down to v1 as well?

Closes #2352
Closes freeCodeCamp/freeCodeCamp#18093

@Yurickh Yurickh changed the title Properly serve static files [v2] Properly serve static files Sep 7, 2018
Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

🤦‍♂️ oh wow! Not sure why we didn't notice that express.static wasn't doing it's job and that we thought we had to recreate it haha :-)

@KyleAMathews KyleAMathews merged commit 680618b into gatsbyjs:master Sep 8, 2018
@gatsbot
Copy link

gatsbot bot commented Sep 8, 2018

Holy buckets, @Yurickh — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@simoneb
Copy link

simoneb commented Apr 2, 2019

any idea why this doesn't seem to work? a regression perhaps?

storing an html page in /static/login/index.html leads to the 404 page when trying to navigate to /login, /login/ or /login/index.html

@patriziosotgiu
Copy link

I'm having the same issue.
I was able to troubleshoot and it seems to be working fine until Gatsby v2.1.23.
Starting from v2.1.24 it doesn't work anymore and I get the 404.

As a temporary solution I'm using this plugin: https://www.gatsbyjs.org/packages/gatsby-plugin-static-folders/

@Yurickh
Copy link
Contributor Author

Yurickh commented Apr 2, 2019

I'll take a look at it. 🎉
In the meantime, could either @patriziosotgiu or @simoneb open a new issue? This doesn't seem related to this PR even though it's a similar issue.

@patriziosotgiu
Copy link

Thanks @Yurickh, sounds good, I'll open a new issue in the morning (Unless @simoneb gets on it earlier).

@simoneb
Copy link

simoneb commented Apr 3, 2019

Reported new issue #13072

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants