-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support for CORS #13
Comments
It's probably possible I guess but I'm not sure how to do it either |
Will you accept a PR for it? I might be able to implement it, but no promise on any deadlines of course. |
Yeah sure |
I was actually playing around with this earlier to see if I could get it work with my Anki template within Ankidroid. I believe this is what you're looking for: diff --git a/app/src/main/java/com/kamwithk/ankiconnectandroid/routing/RouteHandler.java b/app/src/main/java/com/kamwithk/ankiconnectandroid/routing/RouteHandler.java
index 908622e..fd3e2c1 100644
--- a/app/src/main/java/com/kamwithk/ankiconnectandroid/routing/RouteHandler.java
+++ b/app/src/main/java/com/kamwithk/ankiconnectandroid/routing/RouteHandler.java
@@ -52,6 +52,14 @@ public class RouteHandler extends RouterNanoHTTPD.DefaultHandler {
e.printStackTrace();
}
- return apiHandler.chooseAPI(files.get("postData"), session.getParameters());
+ NanoHTTPD.Response rep = null;
+ if (files.get("postData") == null) {
+ rep = newFixedLengthResponse("Ankiconnect Android is running.");
+ } else {
+ rep = apiHandler.chooseAPI(files.get("postData"), session.getParameters());
+ }
+
+ rep.addHeader("Access-Control-Allow-Origin", "http://localhost");
+ return rep;
} This hard codes the localhost header into the program, but I never looked into how to make a GUI for it. I'll let you pick it up from here if you're interested! @sp3ctum |
I should also mention @sp3ctum that the most recent PR I made (#16) implements a basic settings section on the toolbar if you want to work from there. |
Cool, that looks great @Aquafina-water-bottle , should be a nice place to add some kind of "Allowed hosts/sites" setting section. I played around with your code snippet and was able to get it to work with the headers below. There are still some issues with some requests that I haven't solved so this shouldn't be considered a final solution by any means. rep.addHeader("Access-Control-Allow-Origin", "*"); // will need configuration, probably not good to allow all origins
rep.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
rep.addHeader("Access-Control-Allow-Methods ", "GET, POST, PUT, OPTIONS"); Also I opened some issues for some minor things here in this repo. I am in the process of changing jobs in the coming weeks and don't have the means to finish this right now.. But I still need it done later for my app, so I think I'll take a look at this once things become somewhat settled down. |
It's been a while since the last message was sent here so I'm going to close it for now |
Hi, I'm working on my hobby project which is a Japanese web dictionary called hare: https://github.com/sp3ctum/hare
It's nothing special but I use it in my own workflow. I'd like to add support for anki connect as well as anki connect android in order to quickly add cards when I'm reading.
Anki connect allows customizing the CORS origin list in its config, here is an example:
https://sakura-paris.org is where I run my dictionary. Without the added configuration, all requests are blocked by chrome because they target another host. This is what it looks like:
But after this configuration has been saved, I can access the service from chrome.
I'll start by working on anki connect desktop but I understand AnkiConnectAndroid uses the same api (roughly) so I think I might be able to support both. This, I imagine, is what yomichan does as well.
Do you think it could be possible to add support for configurable CORS origins? I could maybe submit a PR for this but I'm not exactly sure how to do it yet.
The text was updated successfully, but these errors were encountered: