添加Swagger到应用程序

huangapple go评论46阅读模式
英文:

Adding Swagger to application

问题

我正在尝试为我们的应用程序添加Swagger,并在后端代码库上进行更改。我已安装了NuGet包Swashbuck.AspNetCore。

在Startup.cs文件中,我进行了以下更改:

在ConfigureServices方法中,我添加了

services.AddSwaggerGen();

在Configure方法中,我添加了:

app.UseSwagger();
app.UseSwaggerUI();

现在从我所看到的,似乎应该足够让我能够重定向到应用程序上的Swagger页面。但是,当我尝试访问http://localhost:4200/swagger时
,我只是被重定向到http://localhost:4200。所以我在想我漏掉了什么?后端是否还需要添加其他内容?还是前端可能有什么东西导致重定向离开它?

英文:

I am looking to add swagger to our application and making the changes on our backend codebase.
I have installed the nuget package Swashbuck.AspNetCore.

In the Startup.cs file I have made the following changes:

In the ConfigureServices method I have added

        services.AddSwaggerGen();

and in the Configure method I have added:

            app.UseSwagger();
            app.UseSwaggerUI();

Now from what I've looked at, it seems that should enough to then be able to redirect to the swagger page on the application. However, when I try to go to http://localhost:4200/swagger
I'm just redirected to http://localhost:4200. So I am wondering what I am missing here? Is there something else I need to add to the backend? Or is it possible there is something in the frontend that's causing the redirect away from it?

答案1

得分: 0

所以这是一个令人挠头的时刻。我一直试图从错误的端口号访问,因为我不知何故假定它会是前端使用的同一个端口,但事实并非如此。加载Swagger UI 还存在一些其他问题,但至少我现在可以进入页面。

英文:

So face palm moment. I had been trying to access from the wrong port number, I for some reason assumed it would be the same port that the front end uses but it is not. There are some other issues with loading the swagger UI but I can at least get to the page now

huangapple
  • 本文由 发表于 2023年3月15日 20:00:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定