First I’m not 100% sure if this is a bug with Netlify (the Netlify CLI itself) or if it’s related to this plugin. So hopefully someone with more insights can help here: when there is already a _redirects file defined in the static/ directory this plugin indeed does create correctly the following entry at the end of the file
## Created with gatsby-plugin-netlify
/foo/* / 301
# @netlify/plugin-gatsby redirects start
/api/* /.netlify/functions/gatsby 200
# @netlify/plugin-gatsby redirects end
but the Lambda function itself is not deployed. From the Netlify CLI I’m getting
(Netlify Build completed in 3m 26.6s)
Deploy path: /Users/me/Workspace/some-site/public
Configuration path: /Users/me/Workspace/some-site/netlify.toml
Deploying to draft URL...
✔ Finished hashing 4242 files
✔ CDN requesting 42 files
✔ Finished uploading 42 assets
✔ Deploy is live!
When I completely remove the static/_redirects file the Netlify CLI output is
(Netlify Build completed in 3m 31.2s)
Deploy path: /Users/me/Workspace/some-site/public
Functions path: /Users/me/Workspace/some-site/netlify/functions
Configuration path: /Users/me/Workspace/some-site/netlify.toml
Deploying to draft URL...
✔ Deploying functions from cache (use --skip-functions-cache to override)
✔ Finished hashing 4242 files and 1 functions
✔ CDN requesting 42 files and 0 functions
✔ Finished uploading 42 assets
✔ Deploy is live!
On the third line there is the indicator that the function is found and deployed. I’m using additionally gatsby-plugin-netlify in combination with @netlify/plugin-gatsby.
Steps to reproduce
- create a new Gatsby project
- create a Lambda function in
src/api/ - create a
static/_redirectsfile with one or more redirects. For example/foo/* / 301 - build the project with
npx netlify deploy --build
The same happens when a _redirects file is not present but created programatically in gatsby-node.js with
exports.createPages = async ({ actions }) => {
const { createRedirect } = actions;
createRedirect({
fromPath: '/foo/*',
toPath: '/',
statusCode: 301,
});
};
I already created a GitHub issue for that but unfortunately did not receive a feedback yet.
