I have a situation where I have two servers, Server A and Server B. (Both are running on localhost
on different ports.)
Server A:
a/
index.html
index.js
Server B:
b/
library.js
font.ttf
Server B hosts an library.js
and font.ttf
. To load this font file, the library.js
file has a fetch
call with a relative path, like so:
fetch('./font.tff')
When loaded from it’s own origin, the Server B setup works fine.
However, when loaded a cross-origin request from Server A (with a/index.js
importing b/library.js
), Server B‘s code fails because now that relative './font.ttf'
path is relative to Server A instead (on a different port), which has no such file.
Is there a way to continue to use relative paths on Server B, while having code be isolated so that it can be requested from a different origin and still work?
(The nuances of why I have two servers running has to do with Electron, and how Server A is the renderer process itself, and Server B is my own extra server with a dynamic set of files that might get loaded.)