-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Comments
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 |
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 |
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 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? |
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! |
Hi, I just pushed a bin\run-dev.bat script. You can follow the instructions as above, with this change: ant dist cd dist 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 |
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! |
oops, html tags gone missing
|
I finally could reproduce the output from the sample app. Thanks again for all your help Tony! |
Config changes
…board changes for copy-to-clipboard
# 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`
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
The text was updated successfully, but these errors were encountered: