-
Notifications
You must be signed in to change notification settings - Fork 149
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
Adding support for serving multiple folders from a single HTTPD server #16
base: master
Are you sure you want to change the base?
Conversation
… from a single server.
…gical, the NPE was due to the method being null. Reversing the order of the equality check covers this.
…m path pointing to http://... or https://... it will internally redirect the request to the remote server, and serve the response back to the user from the local server. For example: cordova.plugins.CorHttpd.startServer({ 'www_root': '', 'port': 8080, 'localhost_only': false, 'custom_paths': { '/imgur/': 'http://i.imgur.com/' } }, function(){console.log("SUCCESS");}, function(){console.log("FAILURE");}); When you then fetch http://localhost:8080/imgur/TNZYux0.jpg, you will fetch the content from imgur, and serve it as if it came from your own domain. The reason for doing this... CrossDomain issues on image content served from an off device domain, and not wanting to apply unrestricted CORS access to all domains. NOTE: On iOS, this will download the entire contents of the response into memory before sending it on to the calling client. On Android, this is chunked in up to 16kb segments. Someone with more iOS experience than myself can probably make the iOS side of this behave more efficiently.
Recently added to my fork, is the ability to define a custom path as a proxy... 'custom_paths': { We needed to do this because we have a mixed mode of operation... serving content from our on device server, and content from our CDN, but we were coming up against CORS issues. Unfortunately, due to the nature of CORS... you can't specify specific domains to allow requests from, so normally we would achieve this server side by internally redirecting/proxying the request across. In CorHTTPD's instance, this is achieved similarly. |
…/local/ can point to a local file based URL, but /local/game/ can point to a HTTP reference)
Is there any hope of getting this merged? |
I would love for it to get merged. I've moved away from this space, but would love to see the loop closed. |
I tried to use your PR however the custom_paths just seemed to redirect to the root folder. Is there anything I'm missing? |
I came across a problem whereby I needed to serve cordova.file.dataDirectory from one path and cordova.file.applicationDirectory from another path, but from the same server. This PR solves this by being able to specify custom_paths in the options of the startServer call, which are then used to provide overridden paths to serve from at runtime.