Reputation: 93
I am trying to make an electron app where the user can choose "host a private server" or "Join a private server". With that, the user can trade messages with the host or other users, or create a room where others can join
when my code were on main.js (where the electron app runs), server is generated with no problems. But when i try to put the same code in a Server.js and refer to it in a html file (using <script src"">), this code stops working and shows this:
C:\Users\lages\Desktop\Pasta du apepe\electron-quick-start\node_modules\depd\index.js:413 Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'unsafe-inline'"
at Function.wrapfunction [as function] (C:\Users\lages\Desktop\Pasta du apepe\electron-quick-start\node_modules\depd\index.js:413)
at Object.<anonymous> (C:\Users\lages\Desktop\Pasta du apepe\electron-quick-start\node_modules\body-parser\index.js:37)
at Object.<anonymous> (C:\Users\lages\Desktop\Pasta du apepe\electron-quick-start\node_modules\body-parser\index.js:159)
at Module._compile (internal/modules/cjs/loader.js:1078)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1108)
at Module.load (internal/modules/cjs/loader.js:935)
at Module._load (internal/modules/cjs/loader.js:776)
at Function.f._load (electron/js2c/asar_bundle.js:5)
at Function.o._load (electron/js2c/renderer_init.js:33)
at Module.require (internal/modules/cjs/loader.js:959)
Any idea on how to solve this error?
My code
let ligar_desligar = document.getElementById("botao3")
let statusServer= false
const expresso= require("express")
var limpador = require("string-sanitizer");
const appe = expresso()
const httpServer = require("http").createServer(appe);
const options ={
}
const io = require("socket.io")(httpServer, options);
appe.use(expresso.static(__dirname+"/data"))
httpServer.listen(8889, ()=>console.log("adm online na porta http://localhost:8889"))
//SERVER EVENTS SECTION
io.on("connection", (socket) => {
console.log("nova conexao, o cara conectado e ID: ", socket.id)
socket.on("manda", (arg) => {
limpeza(arg)
console.log("recebi: ",arg); // world
socket.broadcast.emit("devolve", arg)
socket.emit("devolve", arg)
});
})
function limpeza(palavra){
limpador.sanitize.keepSpace(palavra); // abcdefgh123
}
Upvotes: 2
Views: 5356
Reputation: 93
Problem solved, I just needed to add
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self'; script-src 'self' 'unsafe-eval'">
in the meta tags in HTML.
Upvotes: 3