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

CORS support #77

Open
pbsds opened this issue Apr 21, 2020 · 0 comments
Open

CORS support #77

pbsds opened this issue Apr 21, 2020 · 0 comments

Comments

@pbsds
Copy link
Contributor

pbsds commented Apr 21, 2020

Preflighted requests in for CORS send a HTTP OPTIONS requests to the server to ask for permission to use the resource cross origins. Polaris does not currently seem to handle OPTIONS requests, nor provide any of the CORS headers.

Use case: Develop polaris-web while using a remotely hosted polaris api instance

If the API is meant to be public, then enabling CORS should not be an issue. At least as an optional flag.

It seems like the default behavior for Rocket on this topic have been debated for some years and the current situation is that they don't handle it at all. But there exist a nice crate called rocket_cors which might be the solution.

For the curious, here is my dirty patch to make polaris-web use a remote endpoint
diff --git a/src/api.js b/src/api.js
--- a/src/api.js
+++ b/src/api.js
@@ -17,7 +17,7 @@ let request = function(endpoint, options) {
 		options = {};
 	}
 	options.credentials = "same-origin";
-	return fetch("api" + endpoint, options)
+	return fetch("http://192.168.0.x:5050/api" + endpoint, options)
 		.then(res => {
 			if (res.status == 401) {
 				Router.push("/auth").catch(err => { });
@@ -29,11 +29,11 @@ let request = function(endpoint, options) {
 
 export default {
 	makeAudioURL(path) {
-		return "api/audio/" + encodeURIComponent(path);
+		return "http://192.169.0.x:5050/api/audio/" + encodeURIComponent(path);
 	},
 
 	makeThumbnailURL(path) {
-		return "api/thumbnail/" + encodeURIComponent(path) + "?pad=false";
+		return "http://192.169.0.x:5050/api/thumbnail/" + encodeURIComponent(path) + "?pad=false";
 	},
 
 	initialSetup() {
@@ -42,7 +42,7 @@ export default {
 	},
 
 	login(username, password) {
-		return fetch("api/auth", {
+		return fetch("http://192.168.0.x:5050/api/auth", {
 			method: "POST",
 			body: JSON.stringify({ username: username, password: password }),
 			headers: {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants