我正在使用NestJS
版7.1.0
和serverless
,并使用nestjs swagger
创建api文档。在本地,它像冠军一样工作,但是部署后出现错误。
swagger-ui-express package is missing
我在这里看到了一些问题,但仍无法解决。 https://github.com/nestjs/swagger/issues/277
这是我的package.json
"dependencies": {
"@nestjs/common": "^7.1.0",
"@nestjs/core": "^7.1.0",
"@nestjs/passport": "^7.0.0",
"@nestjs/platform-express": "^7.0.7",
"@nestjs/swagger": "^4.5.8",
"aws-serverless-express-binary": "^1.0.1",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.1",
"dayjs": "^1.8.24",
"dotenv": "^8.2.0",
"dynamodb-data-types": "^3.0.1",
"express": "^4.17.1",
"faker": "^4.1.0",
"jest": "^24.9.0",
"jwks-rsa": "^1.6.0",
"latinize": "^0.4.1",
"lodash": "^4.17.15",
"mime-types": "^2.1.26",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"rxjs": "^6.5.3",
"serverless-dynamodb-local": "^0.2.39",
"swagger-ui-express": "^4.1.4",
"tslint-loader": "^3.5.4",
"uuid": "^3.3.3",
"winston": "^3.2.1"
},
这是配置:
const options = new DocumentBuilder()
.setTitle("My APIs")
.setDescription("APIs description")
.setVersion("1.0")
.addTag("cats")
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup("api", app, document);
任何帮助!
答案 0 :(得分:0)
我想出了解决方案,希望对您有所帮助。
我添加了一个伪造的终结点,以确保swagger-ui-express
运行后不会删除webpack
。
if (event.path === "/api") {
event.path = "/api/";
} else if (event.path.includes("/swagger-ui")) {
event.path = event.path.replace("/swagger-ui", "/api/swagger-ui");
}
// Fake to keep swagger-ui-express work after deploy
if (event.path === "/fake-swagger-ui-express") {
swaggerUi.setup(null);
}
答案 1 :(得分:-1)
您碰巧正在使用纱线工作区吗?我现在遇到了同样的问题,在本地一切正常,但是在我们的集群上崩溃了。
如果是,那么尝试将其添加到使用swagger模块的API的package.json中:
"workspaces": { "nohoist": ["swagger-ui-express"] }