[gatsby develop] Properly serve HTML files in the static directory #31311
Replies: 35 comments 2 replies
-
This is difficult to do because of those change - #12243 and #12336 (as we will have lot of potentially stale .html files). Possibly we can create blacklist/whitelist for html files copied from |
Beta Was this translation helpful? Give feedback.
-
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Beta Was this translation helpful? Give feedback.
-
I have a use case where a transformer plugin creates some html pages in the This works fine for production builds but the contents of the iframes are not displayed with the develop server which is a bit of a bummer. A whitelist would work fine for my use case. I'd be happy to contribute this if you point me to the best place where it should go. |
Beta Was this translation helpful? Give feedback.
-
I'm currently working on a project with a similar use case. |
Beta Was this translation helpful? Give feedback.
-
At https://playchap.io/ we serve games with static html files via iframe and we bound to use Gatsby 2.0.65 due to the aforementioned issue |
Beta Was this translation helpful? Give feedback.
-
Would be great to have this bug fixed so people can serve their previous projects. Many thanks! |
Beta Was this translation helpful? Give feedback.
-
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks again for being part of the Gatsby community! |
Beta Was this translation helpful? Give feedback.
-
#12336 is killing this for me. I've just dropped a reference site in static/ so that I can link to it in Gatsby but because of #12336 everything but the html files are server. I can kinda work around it by |
Beta Was this translation helpful? Give feedback.
-
Same issue here. A whitelist would be fine for me. |
Beta Was this translation helpful? Give feedback.
-
Same issue here. Not serving properly in develop. |
Beta Was this translation helpful? Give feedback.
-
Anyone interested in taking on a PR? It should be possible to track which HTML files are generated by Gatsby and then do serve other ones e.g. from the |
Beta Was this translation helpful? Give feedback.
-
Gatsby develop still won't serve static files, but gatsby build/gatsby serve works for now |
Beta Was this translation helpful? Give feedback.
-
+1 In the meantime, Ive been serving my static html files with another server and then using Gatsby develop middleware to proxy them: // package.json
{
"scripts": {
"serve-static": "cd static && python -m SimpleHTTPServer 9000"
}
}
// gatsby-config.js
var proxy = require("http-proxy-middleware")
module.exports = {
developMiddleware: app => {
app.use(
"/some-static-dir",
proxy({
target: "http://localhost:9000/" // other server is running on port 9000
})
);
}
} Then, in an iframe for example, im accessing the file like so: <iframe src='/some-static-dir/index.html' /> This way my code works in both develop and production. Would be nice to just have them served by default though :) |
Beta Was this translation helpful? Give feedback.
-
We also have the same use case as @krischer. We would like to use Gatsby Preview with Contentful but with this issue, the preview won't work properly. 😞 |
Beta Was this translation helpful? Give feedback.
-
+1 on the issue. Have a similar need to serve |
Beta Was this translation helpful? Give feedback.
-
For those that may encounter this: Gatbsy seems happy to serve non <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<script>alert('hi')</script>
</head>
<body>
<p>
<b>Hello</b>
</p>
</body>
</html> The browser treats it like an html file, and Gatsby serves it statically. There may be a better way to structure that file, we didn't care about the actual markup much. We just took it from the first thing we found. Seems to work for our particular use case, at least. |
Beta Was this translation helpful? Give feedback.
-
Hey just an other comment to adds up :) Thanks for your work anyway! EDIT: I've found a super nice workaround #17761 (comment) from @jonniebigodes, tested and it works nicely! |
Beta Was this translation helpful? Give feedback.
-
Same issue here. A whitelist would be fine for me. |
Beta Was this translation helpful? Give feedback.
-
I too prefer a whitelist. I need to add my silent token renew html for oidc token refresh. |
Beta Was this translation helpful? Give feedback.
-
Hacky fix: Add this code in
same here. pdftron can't be used in dev mode https://www.pdftron.com/documentation/web/get-started/npm/ |
Beta Was this translation helpful? Give feedback.
-
Having similar issue. Store fonts in /static/ folder, which are not available when run 'develop' command. Works fine for build & serve. Any ideas? |
Beta Was this translation helpful? Give feedback.
-
@turistua As noted above, you can work around this by including the following in your const express = require(`express`)
// Enable development support for serving HTML from `./static` folder
exports.onCreateDevServer = ({ app }) => {
app.use(express.static(`static`))
} This will only run in |
Beta Was this translation helpful? Give feedback.
-
@coreyward that's true. If you use themes and want to serve some content from theme folder, the code should be like
|
Beta Was this translation helpful? Give feedback.
-
@coreyward Thanks for the workaround. However, I'm finding that this interferes with the dev environment's ability to accept code changes. As in, if I change some simple UI code I don't see that reflected in the browser until I shut the |
Beta Was this translation helpful? Give feedback.
-
@joeldbirch Hmm, I haven't experienced that. I have had a bunch of hot reloading issues where I have to save a file repeatedly before Gatsby picks up the change since the swap to the new file watching setup, though, even when I'm not using the snippet shared above. Is that maybe what you're experiencing? |
Beta Was this translation helpful? Give feedback.
-
@coreyward I tried to set up the express middleware with the |
Beta Was this translation helpful? Give feedback.
-
Yeah personnaly i did a hack in the core of gatsby
If somebody can add this feature to add exception for some path to avoid gatsby to serve the index.html |
Beta Was this translation helpful? Give feedback.
-
surprised this is an issue. need to serve static html so remote services can id site |
Beta Was this translation helpful? Give feedback.
-
Quick update on my earlier comment. Using the above workaround, in development I'm serving HTML from an app or theme's |
Beta Was this translation helpful? Give feedback.
-
@joeldbirch Oh shit, I could have totally been more careful in reviewing what was going on and saved you some time there. I found the same, and I always just use the // Serve files from `static` in development
exports.onCreateDevServer = ({ app }) => {
app.use(express.static("static"))
} |
Beta Was this translation helpful? Give feedback.
-
Description
This is addressing an issue already reported in #2352 . The issue has reappeared, probably a regression, in even a worse fashion, because files cannot be accessed altogether, as opposed to having to specify the file name as reported in the original issue.
Storing static html files in the static folder causes gatsby to not serve them properly in development mode.
Steps to reproduce
If the file system structure is this:
Running
gatsby develop
Expected result
Browsing to
http://localhost:8000/test
,http://localhost:8000/test/
orhttp://localhost:8000/test/index.html
should serve the aboveindex.html
.Actual result
The 404 page is served instead.
Environment
Beta Was this translation helpful? Give feedback.
All reactions