mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Allow calls to Khoj server from Obsidian mobile app to fix CORS issue
- Obsidian mobile uses capacitor js. Requests from it have origin as http://localhost on Android and capacitor://localhost on iOS - Allow those Obsidian mobile origins in CORS middleware of server
This commit is contained in:
@@ -253,10 +253,13 @@ export class KhojChatModal extends Modal {
|
|||||||
async getChatHistory(chatBodyEl: Element): Promise<boolean> {
|
async getChatHistory(chatBodyEl: Element): Promise<boolean> {
|
||||||
// Get chat history from Khoj backend
|
// Get chat history from Khoj backend
|
||||||
let chatUrl = `${this.setting.khojUrl}/api/chat/history?client=obsidian`;
|
let chatUrl = `${this.setting.khojUrl}/api/chat/history?client=obsidian`;
|
||||||
let headers = { "Authorization": `Bearer ${this.setting.khojApiKey}` };
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await fetch(chatUrl, { method: "GET", headers: headers });
|
let response = await fetch(chatUrl, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Authorization": `Bearer ${this.setting.khojApiKey}` },
|
||||||
|
});
|
||||||
|
|
||||||
let responseJson: any = await response.json();
|
let responseJson: any = await response.json();
|
||||||
|
|
||||||
if (responseJson.detail) {
|
if (responseJson.detail) {
|
||||||
@@ -361,7 +364,6 @@ export class KhojChatModal extends Modal {
|
|||||||
let response = await fetch(chatUrl, {
|
let response = await fetch(chatUrl, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
|
||||||
"Content-Type": "text/event-stream",
|
"Content-Type": "text/event-stream",
|
||||||
"Authorization": `Bearer ${this.setting.khojApiKey}`,
|
"Authorization": `Bearer ${this.setting.khojApiKey}`,
|
||||||
},
|
},
|
||||||
@@ -422,7 +424,7 @@ export class KhojChatModal extends Modal {
|
|||||||
let chatBody = this.contentEl.getElementsByClassName("khoj-chat-body")[0];
|
let chatBody = this.contentEl.getElementsByClassName("khoj-chat-body")[0];
|
||||||
|
|
||||||
let response = await request({
|
let response = await request({
|
||||||
url: `${this.setting.khojUrl}/api/chat/history?client=web`,
|
url: `${this.setting.khojUrl}/api/chat/history?client=obsidian`,
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: { "Authorization": `Bearer ${this.setting.khojApiKey}` },
|
headers: { "Authorization": `Bearer ${this.setting.khojApiKey}` },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ app.add_middleware(
|
|||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[
|
allow_origins=[
|
||||||
"app://obsidian.md",
|
"app://obsidian.md",
|
||||||
|
"capacitor://localhost", # To allow access from Obsidian iOS app using Capacitor.JS
|
||||||
|
"http://localhost", # To allow access from Obsidian Android app
|
||||||
"http://localhost:*",
|
"http://localhost:*",
|
||||||
"http://127.0.0.1:*",
|
"http://127.0.0.1:*",
|
||||||
f"https://{KHOJ_DOMAIN}",
|
f"https://{KHOJ_DOMAIN}",
|
||||||
|
|||||||
Reference in New Issue
Block a user