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

xn1cxnb4  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(174)

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

{
    "version": 2,
    "builds": [
        { "src": "/api/index.php", "use": "[email protected]" },
        { "src": "/public/**", "use": "@vercel/static" }
    ],
    "routes": [
        {
            "src": "/(css|js|images)/(.*)",
            "dest": "public/$1/$2"
        },
        { 
            "src": "/swagger/(.*)", 
            "dest": "/public/swagger/$1" 
        },
        {
            "src": "/(.*)",
            "dest": "/api/index.php"
        }
    ],
    "env": {
        "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"
    }
}

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

ve7v8dk2

ve7v8dk21#

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

{
    "version": 2,
    "builds": [
        { "src": "/api/index.php", "use": "[email protected]" },
        { "src": "/public/**", "use": "@vercel/static" }
    ],
    "routes": [
        {
            "src": "/(css|js|images)/(.*)",
            "dest": "public/$1/$2"
        },
        { 
            "src": "/swagger/(.*)", 
            "dest": "/public/swagger/$1" 
        },
        {
            "src": "/(.*)",
            "dest": "/api/index.php"
        }
    ],
    "env": {
        "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",
        "L5_SWAGGER_GENERATE_ALWAYS": "false",

        "CACHE_DRIVER": "array",
        "LOG_CHANNEL": "stderr",
        "SESSION_DRIVER": "cookie"
    }
}

字符串
路由/API

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


config/swagger.php

'routes' => [
     'api' => 'documentation',
],


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

相关问题