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

Add createRedirects action and Netlify support #2185

Merged
merged 7 commits into from
Sep 20, 2017

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Sep 20, 2017

This is done in support of the new React website.

Example usage

Temporary redirect

createRedirect({
  fromPath: '/some/old/path',
  toPath: '/some/new/path',
});

Permanent redirect

createRedirect({
  fromPath: '/some/old/path',
  toPath: '/some/new/path',
  isPermanent: true,
});

@KyleAMathews
Copy link
Contributor

@pk-nb hey! we added support for redirects to your netlify plugin. In so doing, the "netlify-headers" title didn't make as much sense so we renamed it to gatsby-plugin-netlify to reflect its more generic nature.

@KyleAMathews KyleAMathews merged commit ec6838a into gatsbyjs:master Sep 20, 2017
@bvaughn bvaughn deleted the create-redirects branch September 20, 2017 22:32
@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit 9020566

https://deploy-preview-2185--gatsbygram.netlify.com

@KyleAMathews
Copy link
Contributor

Hmm just realized we will need to do client side redirects still in production. E.g. handling your blog redirect use case.

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 21, 2017

Hmm just realized we will need to do client side redirects still in production.

You mean for non-Netlify use cases?

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 21, 2017

Rats! I tried integrating with the new plugin in facebook/react/pull/10771 and the redirect doesn't seem to work.

https://deploy-preview-10771--reactjs.netlify.com/blog.html

I'll look into it. 😦

Edit 1: Looks like public/_redirects isn't actually being written on a clean test. Whoops! I know we both saw this working yesterday so I'm not sure what's up yet. Will continue digging.

Edit 2: Based on my console logging, it looks like gatsby-plugin-netlify isn't actually running. I think that's because only the source is published (no build) so there's nothing to execute. (eg there should be a gatsby-node.js file in the root here, right? https://unpkg.com/gatsby-plugin-netlify@1.0.2/)

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 21, 2017

Looks like a bad version of gatsby-plugin-netlify was published (without any build source). Confirmed that running yarn install & yarn build in node_modules/gatsby-plugin-netlify resolves the issue for me locally.

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 21, 2017

Maybe you can re-publish after building- let me know and I'll update the version and confirm the fix on my end.

Copy link
Contributor

@pk-nb pk-nb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for letting me know!

const { redirects } = store.getState()

await buildHeadersProgram(pluginData, pluginOptions)
await createRedirects(pluginData, redirects)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:neckbeard: Maybe this could be a promise.all, so they can run in parallel instead of series?

})

return writeFile(publicFolder(`_redirects`), data.join(`\n`))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add a plugin option to disable this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any harm in writing an empty _redirects file? Or are you concerned that we might override an existing one? (Guess it would be worth checking to see if we should append vs write.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right—someone might want to make one by hand through the static folder rather than go through generation in this plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in PR #2191

@KyleAMathews
Copy link
Contributor

Looks like a bad version of gatsby-plugin-netlify was published

Yeah, it's missing a .npmignore file. Adding and publishing.

@KyleAMathews
Copy link
Contributor

@bvaughn
Copy link
Contributor Author

bvaughn commented Sep 21, 2017

Thanks Kyle!

@sebastienfi
Copy link
Contributor

Thanks @bvaughn for this feature, we can now create plugins for every hosting software.

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

Successfully merging this pull request may close these issues.

5 participants