2016-09-27 1 views
0

Web APIプロジェクトにSwagger UI用の[dist]フォルダを含めました。Swagger UI - 環境ベースのURIを渡すには?

しかし、私がこの場所に行くと、 http://localhost:1234/swagger が自動的にhttp://localhost:1234/swagger/index.htmlに向かない。だから、

、私は直接、私は空のテキストボックスに、このページを取得していますhttp://localhost:1234/swagger/index.htmlにアクセスするとき:----

enter image description here

  1. 私はhttp://localhost:1234/swagger/docs/v1

  2. 移入するテキストボックスをしたいです
  3. 環境に基づいてこれを動的に実行したいと考えています。たとえば、http://test.abc.com/swaggerにアクセスすると、テキストには自動的にhttp://test.abc.com/swagger/docs/v1が入力されます。

答えて

1

あなたの最初の質問に答えるために:あなたのindex.htmlページで

を、あなたは以下を持つことができます。

限り動的にあなたは、あなたが訪問したウェブサイトによっては、URLを生成
<script type="text/javascript"> 

    $(function() { 
    window.swaggerUi = new SwaggerUi({ 
     url: "http://localhost:1234/swagger/docs/v1", 
     ... 
    }); 

</script> 

以下を行うことができます:

<script type="text/javascript"> 

    // Initialize the url variable 
    if (!window.location.origin) { 
    window.location.origin = window.location.protocol + "//" + 
     window.location.hostname + (window.location.port ? ':' + 
     window.location.port : ''); 
    } 

    $(function() { 
    // Create the generated url 
    var myUrl = window.location.origin + '/docs/v1'; 

    // Initialize the Swagger object 
    window.swaggerUi = new SwaggerUi({ 
     url: myUrl, 
     ... 
    }); 
    }); 

</script> 
関連する問題