如何在Vercel Laravel应用程序上集成Swagger UI

xn1cxnb4  于 2024-01-08  发布在  其他
关注(0)|答案(1)|浏览(223)

我已经在vercel上部署了我的laravel应用程序,我正在使用swagger来记录我的API。Swagger在我的本地服务器上运行良好“http://localhost:8000/api/documentation”我需要这个swagger在vercel上在线。请帮助我这个过程。
我在laravel应用的public目录下创建了一个名为“swagger”的文件夹,并将swagger-ui包文件放在里面。
已创建并添加包含此内容的.vercel.json文件

  1. {
  2. "version": 2,
  3. "builds": [
  4. { "src": "/api/index.php", "use": "[email protected]" },
  5. { "src": "/public/**", "use": "@vercel/static" }
  6. ],
  7. "routes": [
  8. {
  9. "src": "/(css|js|images)/(.*)",
  10. "dest": "public/$1/$2"
  11. },
  12. {
  13. "src": "/swagger/(.*)",
  14. "dest": "/public/swagger/$1"
  15. },
  16. {
  17. "src": "/(.*)",
  18. "dest": "/api/index.php"
  19. }
  20. ],
  21. "env": {
  22. "APP_CONFIG_CACHE": "/tmp/config.php",
  23. "APP_EVENTS_CACHE": "/tmp/events.php",
  24. "APP_PACKAGES_CACHE": "/tmp/packages.php",
  25. "APP_ROUTES_CACHE": "/tmp/routes.php",
  26. "APP_SERVICES_CACHE": "/tmp/services.php",
  27. "VIEW_COMPILED_PATH": "/tmp",
  28. "CACHE_DRIVER": "array",
  29. "LOG_CHANNEL": "stderr",
  30. "SESSION_DRIVER": "cookie"
  31. }
  32. }

字符串
现在,当我检查swagger在链接“https://your-vercel-project.vercel.app/swagger“,它给了我一个404错误,没有找到。
我希望它能给予我的REST API的详细资料,显示在我的本地服务器,如登录,注册,忘记密码等

ve7v8dk2

ve7v8dk21#

它通过编辑一些文件来工作。
. versel.json文件

  1. {
  2. "version": 2,
  3. "builds": [
  4. { "src": "/api/index.php", "use": "[email protected]" },
  5. { "src": "/public/**", "use": "@vercel/static" }
  6. ],
  7. "routes": [
  8. {
  9. "src": "/(css|js|images)/(.*)",
  10. "dest": "public/$1/$2"
  11. },
  12. {
  13. "src": "/swagger/(.*)",
  14. "dest": "/public/swagger/$1"
  15. },
  16. {
  17. "src": "/(.*)",
  18. "dest": "/api/index.php"
  19. }
  20. ],
  21. "env": {
  22. "APP_CONFIG_CACHE": "/tmp/config.php",
  23. "APP_EVENTS_CACHE": "/tmp/events.php",
  24. "APP_PACKAGES_CACHE": "/tmp/packages.php",
  25. "APP_ROUTES_CACHE": "/tmp/routes.php",
  26. "APP_SERVICES_CACHE": "/tmp/services.php",
  27. "VIEW_COMPILED_PATH": "/tmp",
  28. "L5_SWAGGER_GENERATE_ALWAYS": "false",
  29. "CACHE_DRIVER": "array",
  30. "LOG_CHANNEL": "stderr",
  31. "SESSION_DRIVER": "cookie"
  32. }
  33. }

字符串
路由/API

  1. Route::get("/stuff", function() {
  2. return ["a" => 1];
  3. });


config/swagger.php

  1. 'routes' => [
  2. 'api' => 'documentation',
  3. ],


Swagger现在在Vercel下使用Laravel API在线,路径为https://your_url for_vercel.app/documentation

展开查看全部

相关问题