Skip to content

Conversation

@davyboyhayes
Copy link

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.

…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.
@davyboyhayes
Copy link
Author

Recently added to my fork, is the ability to define a custom path as a proxy...

'custom_paths': {
'/imgur/' : 'http://i.imgur.com/'
}

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)
@bknill
Copy link

bknill commented Dec 5, 2018

Is there any hope of getting this merged?

@davyboyhayes
Copy link
Author

I would love for it to get merged. I've moved away from this space, but would love to see the loop closed.

@bknill
Copy link

bknill commented Dec 5, 2018

I tried to use your PR however the custom_paths just seemed to redirect to the root folder. Is there anything I'm missing?

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

Successfully merging this pull request may close these issues.

2 participants