Mod Portal API - CORS error in Electron app

Enhance your gameplay with these tools. This category is also the right place for tools useful for modders.
Mod databases, calculators, cheatsheets, multiplayer, scripts, libs and other useful stuff that is not strictly in-game mods.
IzaacJ
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Dec 10, 2020 7:29 pm
Contact:

Mod Portal API - CORS error in Electron app

Post by IzaacJ »

Hello.

I'm building an app using Electron+React to manage mods on my headless servers, however, when sending a request (using node-fetch) I'm getting a CORS error.

Is this a bug or is it intended? Seems to be a lot of tools out there using the API, and the same request works perfectly when made in the browser.
Containerize everything! | Automate everything! | Optimize everything!
User avatar
Sanqui
Factorio Staff
Factorio Staff
Posts: 324
Joined: Mon May 07, 2018 7:22 pm
Contact:

Re: Mod Portal API - CORS error in Electron app

Post by Sanqui »

As far as I'm concerned this is not a bug: we don't want random websites to be able to interact with these APIs from the browser. If you are developing a local application using Electron, I believe there are ways to override CORS.

I am open to arguments to convince me otherwise though :)
ovo
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Mod Portal API - CORS error in Electron app

Post by eradicator »

56jldt.jpg
56jldt.jpg (92.11 KiB) Viewed 3340 times
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
IzaacJ
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Dec 10, 2020 7:29 pm
Contact:

Re: Mod Portal API - CORS error in Electron app

Post by IzaacJ »

Sanqui wrote: Wed Apr 21, 2021 9:59 am As far as I'm concerned this is not a bug: we don't want random websites to be able to interact with these APIs from the browser. If you are developing a local application using Electron, I believe there are ways to override CORS.

I am open to arguments to convince me otherwise though :)
Good to know 🙂 Pretty new to React and Electron so I’ll definitely look up on how to do that.

So, no arguments from me 😁
Containerize everything! | Automate everything! | Optimize everything!
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Mod Portal API - CORS error in Electron app

Post by ptx0 »

IzaacJ wrote: Wed Apr 21, 2021 4:31 pm
Sanqui wrote: Wed Apr 21, 2021 9:59 am As far as I'm concerned this is not a bug: we don't want random websites to be able to interact with these APIs from the browser. If you are developing a local application using Electron, I believe there are ways to override CORS.

I am open to arguments to convince me otherwise though :)
Good to know 🙂 Pretty new to React and Electron so I’ll definitely look up on how to do that.

So, no arguments from me 😁
use Access-Control-Allow-Origin: *

another method would be to have a local PHP script that you call, which solely acts as a proxy to the remote API. then CORS is preserved.
Post Reply

Return to “Tools”