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

The development server returns HTML instead of static files if you try to load one directly #255

Closed
cutemachine opened this issue Apr 24, 2016 · 4 comments

Comments

@cutemachine
Copy link

In my markdown files I link to some zip files a reader can download. But these links do not work, because they get handled by React Router and then result in a 404 error.

What is the best approach to handle file download links with markdown in Gatsby?

@MoOx
Copy link

MoOx commented Apr 27, 2016

You can probably take a look how Phenomic handle this use case. We have solved this issue a few weeks ago ;)

@KyleAMathews
Copy link
Contributor

@cutemachine have you tried testing this after building the site? It should work there as by default, Gatsby doesn't catch link clicks in markdown files so the browser will return to the server to grab the file. I just tested this quickly and that worked.

But you are correct that this is broken when running gatsby develop. If you look at this code in develop.js https://github.com/gatsbyjs/gatsby/blob/master/lib/utils/develop.js#L100-L112 the development server is just looking to see if a request has text/html in the header. This should instead look to see if there's a non-page/non-template file at that path and serve it instead of returning html. #208 would need fixed before this.

@KyleAMathews KyleAMathews changed the title Download links The development server returns HTML instead of static files if you try to load one directly Apr 27, 2016
@cutemachine
Copy link
Author

I have assets like Lua files and zip files, for the user to download. What I want to achieve is to hold the assets within my page structure where the Markdown files and the images are. For the images it works fine, but only for images. I think what I am really looking for is the whitelist for file types.

Thanks for the answer.

KyleAMathews added a commit that referenced this issue Apr 30, 2016
Previously it'd return HTML if the accept header had text/html in it
which when a browser requests an unknown file, it always does.

This caused trouble when someone developing a site would try to click on
a link to a static file and instead of the dev server then returning
that file, it'd return an html file.

Fixes #255
KyleAMathews added a commit that referenced this issue May 4, 2016
* The dev server now checks if path matches a file

Previously it'd return HTML if the accept header had text/html in it
which when a browser requests an unknown file, it always does.

This caused trouble when someone developing a site would try to click on
a link to a static file and instead of the dev server then returning
that file, it'd return an html file.

Fixes #255

* Fix some things so can run tests against development server
@KyleAMathews
Copy link
Contributor

@LukeSheard I was going to wait until this had some tests but... it's a
pretty simple change and we can add tests after the fact. #YOLO :-) I just
published 0.10.1. Let me know if it's working for ya.

Also the goal is you store assets inside /pages along with other page
files. Right now that's a bit tricky see
#243 and
#208 so either you can store
static non-page assets in an assets directory and copy them over on build
or you can add null-loaders for file-types not already covered here
https://github.com/gatsbyjs/gatsby/blob/master/lib/utils/webpack.config.js#L186-L208

On Wed, May 4, 2016 at 3:59 PM Luke Sheard notifications@github.com wrote:

I'm having this issue as well when trying to test if images load as well.
I can't see any recommended instructions on how to store static assets like
images / pdfs / etc. I'm just trying to load a simple images, but as
described above I think it's still returning an HTML page. Any ideas when
#268 #268 might be merged?

(For reference the repo is LukeSheard/lukesheard.com@v2)


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#255 (comment)

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

No branches or pull requests

3 participants