|
14 | 14 |
|
15 | 15 | package io.swagger.generator;
|
16 | 16 |
|
17 |
| -import org.apache.commons.io.IOUtils; |
18 |
| - |
| 17 | +import java.io.IOException; |
| 18 | +import java.io.InputStream; |
| 19 | +import java.net.URI; |
| 20 | +import java.net.URISyntaxException; |
19 | 21 | import javax.servlet.ServletConfig;
|
20 | 22 | import javax.servlet.ServletException;
|
21 | 23 | import javax.servlet.http.HttpServlet;
|
22 |
| -import java.io.IOException; |
23 |
| -import java.io.InputStream; |
| 24 | +import org.apache.commons.io.IOUtils; |
| 25 | +import org.apache.commons.lang3.StringUtils; |
24 | 26 |
|
25 | 27 | public class Bootstrap extends HttpServlet {
|
26 | 28 | private static final long serialVersionUID = 1400930071893332856L;
|
27 | 29 |
|
28 | 30 | @Override
|
29 | 31 | public void init(ServletConfig config) throws ServletException {
|
30 | 32 | DynamicSwaggerConfig bc = new DynamicSwaggerConfig();
|
31 |
| - bc.setBasePath("/api"); |
| 33 | + String hostString = System.getenv("GENERATOR_HOST"); |
| 34 | + if (!StringUtils.isBlank(hostString)) { |
| 35 | + try { |
| 36 | + URI hostURI = new URI(hostString); |
| 37 | + String scheme = hostURI.getScheme(); |
| 38 | + if (scheme != null) { |
| 39 | + bc.setSchemes(new String[] { scheme }); |
| 40 | + } |
| 41 | + String host = hostURI.getHost(); |
| 42 | + if (host != null) { |
| 43 | + bc.setHost(host); |
| 44 | + } |
| 45 | + bc.setBasePath(hostURI.getPath() + "/api"); |
| 46 | + } catch(URISyntaxException e) { |
| 47 | + System.out.println("Could not parse configured GENERATOR_HOST as URL: " + e.getMessage()); |
| 48 | + } |
| 49 | + } else { |
| 50 | + bc.setBasePath("/api"); |
| 51 | + } |
32 | 52 | bc.setTitle("Swagger Generator");
|
33 | 53 | bc.setDescription("This is an online swagger codegen server. You can find out more "
|
34 | 54 | + "at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).");
|
|
0 commit comments