我在Vercel上部署了一个测试应用程序,以便向planetscale数据库提交POST请求。
该应用程序在本地环境下运行良好,但在部署后,在提交到/api/add时,它导致找不到404。你知道问题出在哪里吗?我有一种感觉,这可能是我的vercel.json
,但我无法完全弄清楚文档上的问题,vercel-php
的运行时函数也阻止了用404部署app.css和app.js,所以我将vercel-php
重新分配给了";构建";相反
https://laravelverceldeployment.vercel.app/
这是我的包.json:
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"autoprefixer": "^10.4.2",
"axios": "^0.21",
"browser-sync": "^2.27.7",
"browser-sync-webpack-plugin": "^2.3.0",
"laravel-mix": "^6.0.39",
"lodash": "^4.17.19",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.12",
"vue-loader": "^16.8.3"
},
"dependencies": {
"@inertiajs/inertia": "^0.11.0",
"@inertiajs/inertia-vue3": "^0.6.0",
"@inertiajs/progress": "^0.2.7",
"alpinejs": "^3.7.1",
"vue": "^3.2.26"
}
}
这是我的vercel.json:
{
"version": 2,
"builds": [
{ "src": "/api/index.php", "use": "vercel-php@0.4.0" },
{ "src": "/public/**", "use": "@vercel/static" }
],
"routes": [
{
"src": "/(css|js|images)/(.*)",
"dest": "public/$1/$2"
},
{
"src": "/(.*)",
"dest": "/api/index.php"
}
],
"env": {
"APP_NAME": "laravelverceldeployment",
"APP_ENV": "production",
"APP_DEBUG": "false",
"APP_URL": "https://laravelverceldeployment.vercel.app",
"APP_CONFIG_CACHE": "/tmp/config.php",
"APP_EVENTS_CACHE": "/tmp/events.php",
"APP_PACKAGES_CACHE": "/tmp/packages.php",
"APP_ROUTES_CACHE": "/tmp/routes.php",
"APP_SERVICES_CACHE": "/tmp/services.php",
"VIEW_COMPILED_PATH": "/tmp",
"CACHE_DRIVER": "array",
"LOG_CHANNEL": "stderr",
"SESSION_DRIVER": "cookie",
"VIEW_COMPILED_PATH": "/tmp/views",
"SSR_TEMP_PATH": "/tmp/ssr",
"NODE_PATH": "node"
}
}
在vercel.json中,路由dest被映射到api/index.php。
那么url-api/将通过index.php进行映射?尝试使用just/add-url
使用双api前缀
https://<yourapp>.vercel.app/api/api
以上终点将指向
routes/api.php with prefix('api')