Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

javascript - Nodejs load with jquery a running http server on an electron app

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...