Can't enable POST requests for api route
khromov opened this issue · comments
Bug report
- Version: 0.1.1
- URL: No
- Repository: No
Description
When I try to POST
to /submit-form
, I get a 405 Method not allowed
from Vercel, even though I specified the methods
in the config. This makes it impossible to submit forms.
Here is my vercel.json
:
{
"functions": {
"api/index.php": {
"runtime": "vercel-php@0.1.0"
}
},
"routes": [
{
"src": "/(.*)\\.(.*)$",
"dest": "src/$1.$2"
},
{
"src": "/(.*)",
"methods": ["POST", "GET"],
"dest": "/api/index.php"
}
]
}
To repro, you can use something like curl
:
https://your-app.vercel.app/submit -X POST
...
<html> <head> <title>Method not allowed</title>
<style>
body{
margin:0;
padding:30px;
font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;
}
h1{
margin:0;
font-size:48px;
font-weight:normal;
line-height:48px;
}
</style>
</head>
<body>
<h1>Method not allowed</h1>
<p>Method not allowed. Must be one of: <strong>GET</strong></p>
</body>
Hi, could you please create MVP repo? I guess the problem is in first route.
@f3l1x It turns out that the problem wasn't Vercel but that the Slim router doesn't seem to work any more in the vercel-php
environment. I deployed the official Slim example and it doesn't work - all URLs resolve to the index route:
Code: https://github.com/khromov/vercel-php-repro/tree/official-version
Non-working path example: https://vercel-php-repro-git-official-version.khromovweb.vercel.app/hello/world
I tried upgrading the default example to Slim 4 and it does seem to work, so maybe we should just update the dependencies in the example repo?
Slim 4 version repo: https://github.com/khromov/vercel-php-repro/tree/master
Slim 4 version: https://vercel-php-repro.vercel.app/
Hi, I have update slim to latest v4 and it seems to me it's working.
demo
repo
Thanks for verifying! 🏆