Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse Swagger adaptation virtual directory and secondary directory

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian today takes you to understand how to parse Swagger adaptation virtual directory and secondary directory. The knowledge points introduced in this article are very detailed. Friends who feel helpful can browse the content of the article together with Xiaobian, hoping to help more friends who want to solve this problem find the answer to the question. Let's learn more about "how to parse Swagger adaptation virtual directory and secondary directory" together with Xiaobian.

preface

With the advent of front-end separation patterns and microservice architectures, Web APIs have become increasingly important and pervasive. Gateway technology, which emerged later, made developers more inclined to use secondary/multi-level directories to expose Web APIs, one is to expose fewer ports and facilitate management; the other is to handle some common transactions in the gateway, such as authentication. However, swagger is adapted to the root directory by default. To adapt to the secondary/multi-level directory, additional processing is required, and the development environment must be distinguished from other environments. One idea is to let the Web API be in the secondary directory in the development environment, which can be simulated locally through nginx and iis virtual directories, but this idea is obviously a little troublesome. Another idea is to configure multiple environments.

step

1. Install Swagger

Install-Package Swashbuckle.AspNetCore

2. Configuring Swagger Services

services.AddSwaggerGen(c =>{ c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });});

3. Configuring swagger middleware

4. Configure appsettings.json

Add virtualPath configuration to appsettings.json:

in appsettings. Add virtualpath configuration to Development.json:

test

1. Development environment testing

2. Simulated production environment test

Modify launchSettings.json to change environment variable parameters:

Prepare nginx.conf and start nginx.

Access to secondary directories

Thank you for reading, the above is "how to parse Swagger adaptation virtual directory and secondary directory" all the content, learn friends to quickly operate it. I believe that Xiaobian will definitely bring you better quality articles. Thank you for your support of the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report