So I'm making an electronjs application and I want to load an external html file in the page with jquery. So I tried to just load it (with the file path) and it worked but all the hrefs still redirect in the default location (ex : css/style.css). Resultat, the page think that we are the server and try to search my css file in my nodejs project. I told myself (since it's working if I'm trying to load an url) that for this I need to create a server and this is what I made :
var http = require('http');
var finalhandler = require('finalhandler');
var serveStatic = require('serve-static');
function server_build(folder){
var serve = serveStatic(folder);
var server = http.createServer((req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
var done = finalhandler(req, res);
serve(req, res, done);
});
server.listen(4433);
}
server_build("C:/Users/Admin/AppData/Roaming/project/builds/folder");
And it's working. The server is correctly loading the page... But on the electron app side... Still not showing my style and scripts... Any idea ?
Thank you :)
question from:
https://stackoverflow.com/questions/65888252/nodejs-load-with-jquery-a-running-http-server-on-an-electron-app 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…