Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access-Control-Allow-Origin #2

Closed
ddsky opened this issue Oct 8, 2011 · 8 comments
Closed

Access-Control-Allow-Origin #2

ddsky opened this issue Oct 8, 2011 · 8 comments

Comments

@ddsky
Copy link

ddsky commented Oct 8, 2011

Hello,

I wonder where I have to deploy the UI in order to access the API. apparently I get an Access-Control-Allow-Origin because the ports are not the same but I would rather want to host the UI over the apache and run the api on another tomcat/jetty port. Is that possible?

Javascript:
XMLHttpRequest cannot load http://localhost:8081/slc/pet/resources.json. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Also, is there any more documentation available? I can't quite figure out how the UI gets its information from the api, for example, where does this lead to:

swagger.api.basepath
http://localhost:8002/api

I mean, the UI asks for a resources.json file, but in the sample application I cannot find where path "/api" is defined and where a resources.json is returned.

Thanks for any help.
david

@fehguy
Copy link
Contributor

fehguy commented Oct 8, 2011

Hi, that's possible. What server did you deploy? The java version or scala one? Or did you roll your own? There was a bug in our ApiOriginFilter which caused the allow orgin to not work.

I can tell you about your last question after you tell me what language/sample app you're working with.

Tony

@ddsky
Copy link
Author

ddsky commented Oct 8, 2011

Hey Tony,

thanks for the reply. I wanted to run the sample app (https://github.com/wordnik/swagger-java-sample-app) but there is no run script that is mentioned in the description and I can't figure out how to start the server using the start.jar (any ideas on that?).

So I have my own Java (Java 1.6) server project using tomcat. I copied the web.xml settings and modified them to fit my project. My server (mvn:tomcat run) runs on localhost:8081. I put the ui project on my localhost apache (port 80) and wanted to explore "http://localhost:8081" and I get "GET http://localhost:8081/resources.json 404 (Not Found)". Where does this resources.json file come from? Which class has to serve that?

I thank your for your help Tony!

David

@fehguy
Copy link
Contributor

fehguy commented Oct 8, 2011

OK got it. I'd follow these instructions for compiling and running the sample app. There are instructions in the readme.md file, but you basically you need to do this:

In the swagger-core project run:

ant deploy

Then in the swagger-java-sample-app project you run:

ant dist

This builds the application in the "dist" folder. To start it, you do this:

cd dist
./bin/run-dev.sh

That will start the app. Can you try that before porting the code into your tomcat container?

The gist of how it finds the resources.json is that it uses java jersey, which is a servlet mapped to /. The webapp is created as "api" so it will respond to /api/. If you built your own tomcat container with swagger, it depends on where you put your webapp. If it's in ROOT then you can access localhost:8081/resources.json. If you name it "foo", then it'll respond to localhost:8081/foo/resources.json. Make sense?

@ddsky
Copy link
Author

ddsky commented Oct 8, 2011

I should probably mention that I am on Windows...maybe that is why there is no "bin/run-dev.sh" file. If there was one I could not run it but I could read it and I guess it is just a command that starts the start.jar somehow which I could write a .bat file for...can you please post the contents of the run-dev.sh file if it is not too much?

Second anser, yes that makes sense and it really tries to pull the resources.json from ROOT but the question is who is responsible for creating this resources.json? Me? Because I would not not what to write in there and for now, it is not automatically generated...I probably see more if I could get the demo server running.

Thanks again!

@fehguy
Copy link
Contributor

fehguy commented Oct 8, 2011

Hi, I just pushed a bin\run-dev.bat script. You can follow the instructions as above, with this change:

ant dist

cd dist
bin\run-dev.bat

The resources.json is automatically generated by the swagger framework. Please try the sample app and then we can work on getting your own app to run!

Tony

@ddsky
Copy link
Author

ddsky commented Oct 8, 2011

Tony, thanks, the sample app runs now and I can also access the server annotations using the UI.

So now I just need one more hint on what to setup so that the root serves the resources.json. I have been looking all over the sample app code but I can't find the right spot. I guess it must be something in the configuration that I am not aware of? This is my web.xml for the Jersey project, am I missing an entry or is something wrong?

Jersey Web Application com.sun.jersey.spi.container.servlet.ServletContainer com.sun.jersey.config.property.packages com.test.services com.sun.jersey.api.json.POJOMappingFeature true api.version 0.1 swagger.version 1.0 swagger.api.basepath http://localhost:8081 swagger.security.filter com.wordnik.swagger.sample.util.ApiAuthorizationFilterImpl 1 Jersey Web Application /_ ApiOriginFilter com.wordnik.swagger.sample.util.ApiOriginFilter ApiOriginFilter /_

Again, I appreciate your help and time!

@ddsky
Copy link
Author

ddsky commented Oct 8, 2011

oops, html tags gone missing

<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>de.schottenland.services</param-value> </init-param> <init-param> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>api.version</param-name> <param-value>0.1</param-value> </init-param> <init-param> <param-name>swagger.version</param-name> <param-value>1.0</param-value> </init-param> <init-param> <param-name>swagger.api.basepath</param-name> <param-value>http://localhost:8081</param-value> </init-param> <init-param> <param-name>swagger.security.filter</param-name> <param-value>com.wordnik.swagger.sample.util.ApiAuthorizationFilterImpl</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey Web Application</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <filter> <filter-name>ApiOriginFilter</filter-name> <filter-class>com.wordnik.swagger.sample.util.ApiOriginFilter</filter-class> </filter> <filter-mapping> <filter-name>ApiOriginFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>

@ddsky
Copy link
Author

ddsky commented Oct 8, 2011

I finally could reproduce the output from the sample app. Thanks again for all your help Tony!

@ddsky ddsky closed this as completed Oct 8, 2011
fehguy pushed a commit that referenced this issue Jun 4, 2015
mkrufky pushed a commit to mkrufky/swagger-ui that referenced this issue Feb 26, 2016
vincent-zurczak pushed a commit to roboconf/swagger-ui that referenced this issue Aug 19, 2016
dwasyluk pushed a commit to syscoin/swagger-ui that referenced this issue Oct 4, 2017
suwa-sh added a commit to in-house-swagger/swagger-ui that referenced this issue Nov 4, 2017
suwa-sh added a commit to in-house-swagger/swagger-ui that referenced this issue Nov 4, 2017
lshaw-sb referenced this issue in SmartBear/swagger-ui May 10, 2019
eLvErDe pushed a commit to eLvErDe/swagger-ui that referenced this issue Dec 3, 2019
blortfish pushed a commit to blortfish/swagger-ui that referenced this issue Jan 15, 2020
AndrewCeM pushed a commit to AndrewCeM/swagger-ui that referenced this issue Oct 8, 2021
# This is the 1st commit message:

add support of filter prop to swagger-ui-react

# This is the commit message swagger-api#2:

#`null` replaced with `false`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants