-
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
Can I prefix generated assets path with a different hostname? #11305
Comments
Hi All, Here's something really hacky but seems to work. // gatsby-ssr.js
const modifyPrefix = comp => {
if (comp.props && comp.props.href) {
return {
...comp,
props: {
...comp.props,
href: `${HOSTNAME}${comp.props.href}`,
},
}
} else if (comp.props && comp.props.src) {
return {
...comp,
props: {
...comp.props,
src: `${HOSTNAME}${comp.props.src}`,
},
}
} else {
return comp
}
}
export const onPreRenderHTML = ({
getHeadComponents,
replaceHeadComponents,
getPreBodyComponents,
replacePreBodyComponents,
getPostBodyComponents,
replacePostBodyComponents,
}) => {
replaceHeadComponents(getHeadComponents().map(modifyPrefix))
replacePreBodyComponents(getPreBodyComponents().map(modifyPrefix))
replacePostBodyComponents(getPostBodyComponents().map(modifyPrefix))
} and exports.onCreateWebpackConfig = ({ actions, getConfig, stage }) => {
if (stage === 'build-html' || stage === 'build-javascript') {
const config = getConfig()
actions.replaceWebpackConfig({
...config,
output: {
...(config.output || {}),
publicPath: `${HOSTNAME}/`,
},
})
}
} Is this something ok to do? |
Hi All, Reporting back. So the above code (at least the gist is right) mostly works... except 1 file so far:
Does this file look familiar to you? It's the After reading some more, it seems in order to get this to really work, we need to get Finally, as a bit of proposal, if we were to add this bit of functionality, I think perhaps, in the This way, one could host the generated site somewhere and be able to proxy the site under some other domain (of course with CORS properly setup), while taking advantage of the assets being served from the origin, which would likely be much faster. With the combination of The biggest issue I am trying to solve is to allow people with an old school app (Rails/Django) to introduce gatsby into the mix, starting with blog or doc pages. |
Hi All,
Is there a way to prefix generated assets path with a different hostname? For example, in one of my generated html page:
I would like to make it:
Is this possible? I tried
prefixPath
, but it doesn't work. The reason I want to do this is I have a rails app. For certain pages I am using reverse proxy to host the pages. For example:While the html part of the page works, all the assets in the html, without the hostname prefix, will be coming from
www.example.com
. This is a lot less than ideal as I would like to directly fetch it from cloudfront.In rails, for assets, we can configure the asset host to be something other than the main site. Can this be done in Gatsby?
The text was updated successfully, but these errors were encountered: