-
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
fix(gatsby): Vendor express-static so we can avoid loading html files from public during development #12336
Conversation
var path = parseUrl(req).pathname | ||
const parsedPath = sysPath.parse(path) | ||
|
||
// Ignore html files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I added
We have some development server tests? This would be easy to test. Write out a html file to public and then request it and a regular path from the Dev server and verify the two html files are the same. |
How do we feel about the following code? const sysPath = require(`path`)
const express = require(`express`)
const parseUrl = require(`parseurl`)
/**
* Module exports.
* @public
*/
module.exports = serveStatic
/**
* @param {string} root
* @param {object} [options]
* @return {function}
* @public
*/
function serveStatic(root, options) {
const expressStatic = express.static(root, options)
return function(req, res, next) {
if ([`GET`, `HEAD`].includes(req.method)) {
const path = parseUrl(req).pathname
const parsedPath = sysPath.parse(path)
if ([`.htm`, `.html`].includes(parsedPath.ext)) {
return next()
}
}
return expressStatic(req, res, next)
}
} I tested it, seems to work. |
@KyleAMathews @wardpeet that seems like a really good solution! It’s nice to not have to patch and maintain things—so if that works the same we should definitely go that route! |
Yeah that'd be much better 👌 |
Want to just take over the PR? |
Went ahead and made Ward's changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - let's get this merged! 💪
Successfully published:
|
Fixes #12243 (review)
Works locally for reactjs.org which is a site that uses paths like
/something/about-us.html