CORS issue posting to Discourse from Obsidian

Right, Obsidian is an Electron app that’s running locally. It’s using local storage, so the API key stays on the user’s device.

It turns out there’s a solution for the CORS issue. I’ve only tested it on my desktop computer so far. Also, Discourse is great!

The code I posted above needed to be modified to:

import DiscoursePlugin from "./main";
import { requestUrl, TFile } from "obsidian";

//...
		const response = await requestUrl({
			url: url,
			method: "POST",
			contentType: "application/json",
			body,
			headers,
		});
//...

The next question will be about allowing users to request User API keys from the app, but that’s a separate issue.

3 Likes