Serverless path wildcard breaks on Netlify
timonforrer opened this issue · comments
Describe the bug
I recently bumped eleventy from 1.0.0-canary.39 to 1.0.0-beta.3 which broke the preview functionality I implemented using the serverless plugin.
The preview works as follows:
There is a global data file, that holds all pages
. It exports an object and uses the full_slug
from the CMS (Storyblok) as the key of each page. Like this:
{
"pages/test": {
"id": "xyz"
}
}
Then, if a request to the serverless function is made, it extracts anything after /preview
and uses that string to get the page content.
So if a request to /preview/pages/test
is made, it would use pages/test
to get the corresponding content.
The frontmatter of the preview template file from version canary 39 looked like this:
---
pagination:
data: pages
size: 1
resolve: values
serverless: eleventy.serverless.path._
permalink:
dynamic: '/preview/*'
---
However, due to the transition to path-to-regexp, this breaks, as * wildcards are no longer supported.
So I changed the frontmatter to:
---
pagination:
data: pages
size: 1
resolve: values
serverless: eleventy.serverless.path["0"]
permalink:
dynamic: '/preview/(.*)'
---
The odd thing is that this works on my local machine, but not when deployed to netlify. If I change the new regex wildcard (.*) back to * it works again on netlify.
I already set NODE_VERSION to 14.15.1 for my netlify builds (same as on my computer) and AWS_LAMBDA_JS_RUNTIME to node14.x but that didn't work.
To Reproduce
Repo: Eleventy Bloks
If deployed to netlify, go to [subdomain].netlify.app/preview/pages/modular
and see the response:
{
"error": "No matching URL found for /preview/pages/modular/ in {\"/preview/(.*)\":\"./src/pages/preview/preview.njk\"}"
}
Expected behavior
Behaviour on computer and on netlify should be identical.
Environment:
- MacOS 11.5.2, node 14.15.1
- 1.0.0-canary.39 and 1.0.0-beta.3
Fixed this, it will ship with 2.0.0-canary.5.
If you’d like to see this included on 1.x, please make your case!