One more CORS question

57 views
Skip to first unread message

er...@fulminatus.com

unread,
May 8, 2014, 12:10:40 AM5/8/14
to swagger-sw...@googlegroups.com
So, all my development so far has been local. I've got swagger-ui's index.html inside my web application, and calls to localhost haven't resulted in any issues. I just dumped my war to the dev server, and now I'm seeing CORS issues when I try to access the server's webapp swagger-ui from my machine. I thought that embedding swagger-ui was supposed to make CORS a non-issue?

Eric

er...@fulminatus.com

unread,
May 8, 2014, 8:26:02 AM5/8/14
to swagger-sw...@googlegroups.com
Ok, I think I can answer this. index.html has this:

  <script type="text/javascript">
    $(function () {
      window.swaggerUi = new SwaggerUi({
      url: "http://localhost:8080/eim-query/api-docs",


That URL needs to be http://my.server:8080/eim-query/api-docs, right?

Eric

er...@fulminatus.com

unread,
May 8, 2014, 8:41:19 AM5/8/14
to swagger-sw...@googlegroups.com
Ok, so I confirmed that was the problem. I guess my question then becomes "how are we supposed to manage this"? Specifically, what's the best practice for making that value correct when the webapp can be deployed in multiple locations?

Thanks,
Eric

tony tam

unread,
May 8, 2014, 11:05:49 AM5/8/14
to swagger-sw...@googlegroups.com
Hi, there are a couple ways to handle this--the easiest being, if you're loading the ui from the same host as the API (please note, that protocol changes between HTTP and HTTPS require CORS support) is to grab info from the browser:

var host = window.location.protocol + "//" + window.location.host;

and configure swagger with that:

<script type="text/javascript">
    $(function () {
      window.swaggerUi = new SwaggerUi({
      url: host,

er...@fulminatus.com

unread,
May 8, 2014, 11:41:00 AM5/8/14
to swagger-sw...@googlegroups.com
Perfect. That's exactly what I was looking for. Thanks, Tony!

Sajith Vijesekara

unread,
Apr 23, 2015, 7:19:31 AM4/23/15
to swagger-sw...@googlegroups.com
Hi This is for regarding tony answer. What we want to when we deployed server and UI separately ?? 
Reply all
Reply to author
Forward
0 new messages