-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby develop
does not serve static index.html
files when directory is accessed
#2352
Comments
Hmmm this is perhaps either a limitation of the node server or a misconfiguration. Feel free to submit a PR if you can see ways to improve it. https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/develop.js |
I wonder why there is both of these:
gatsby/packages/gatsby/src/utils/develop.js Lines 108 to 112 in 392e7f2
|
Haha probably an oversight. |
Yeah we should be using the later. See if anything breaks when removing the first. |
Well, I think this bug is caused because the second (manual) one doesn't check for index files like the built-in middleware. I could try to implement it, it shouldn't be too hard. |
Great! Yeah would love a PR. |
I just had a thought for a simpler method (removing the custom code completely): app.use(express.static(__dirname + `/public`))
// Render an HTML page and serve it.
app.use((req, res, next) => {
const parsedPath = parsePath(req.originalUrl)
if (parsedPath.extname === `` || parsedPath.extname.startsWith(`.html`)) {
res.sendFile(directoryPath(`public/index.html`), err => {
if (err) {
res.status(500).end()
}
})
} else {
res.status(404).end()
}
}); What about just like this? Then we can use the built-in one, and we are still essentially doing the same checking. |
@KyleAMathews Do you see any obvious problems with that example? |
Oh… now that I think about it, we could probably just use the built-in static serving now. I added to the bootstrap process a step to delete all html files in public directory which I think was the only reason to have the custom file serving. So yeah, your code looks like what we want. |
Sounds good. I'm not going to be able to make a PR right away -- if you want to just do it that's fine with me. |
@tech4him1 probably won't get to this soon so would love a PR when you have time or anyone else who sees this issue and wants it solved! |
Hey, closing out old issues. Please re-open if you have additional questions, thanks! |
@KyleAMathews This issue is still relevant in [email protected], we @freeCodeCamp are trying to resolve this. Would you like a new issue or should I reopen this one? |
Let's reopen this one |
Thanks for implementing @Yurickh! |
Already commented in the linked PR, but this doesn't seem to work for me. |
I'm having the same issue, also commented on the PR. |
New issue created #13072 |
If my directory structure is this:
and I run
gatsby develop
, then I cannot access myindex.html
file by going tolocalhost:8000/test/
, I have to go tolocalhost:8000/test/index.html
.The text was updated successfully, but these errors were encountered: