Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
NodeJs y Apache No hay encabezado 'Access-Control-Allow-Origin' en el recurso solicitado

Implementé mi servidor de socket NodeJs con pm2 y apache, y obtuve el error No hay 'Access-Control-Allow-Origin' header is present on the requested resource. cuando se llama desde mi aplicación angular. Este problema aparece solo cuando uso el nombre de dominio que apunta al proceso. Cuando se usa http://<ip_address>:<port> , funciona.

código angular

 setupScheduleSocket(){ this.scheduleSocket = io.connect(environment.SCHEDULE_SOCKET); this.scheduleSocket.on('connect', ()=>{ console.log("connected", environment.SCHEDULE_SOCKET); }); this.scheduleSocket.on('connect_error', () => { console.log('connection error'); }); this.scheduleSocket.on('disconnect', () => { console.log('disconnected'); }); }

NodeJs

 const https = require('http'); //const server = https.createServer(); const socketIO = require('socket.io'); const server = https.createServer((req, res) => { const headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'OPTIONS, POST, GET', 'Access-Control-Max-Age': 2592000, 'Access-Control-Allow-Headers': 'X-Requested-With, Content-Type', 'Access-Control-Allow-Credentials': true }; if (req.method === 'OPTIONS') { res.writeHead(204, headers); res.end(); return; } if (['GET', 'POST'].indexOf(req.method) > -1) { res.writeHead(200, headers); res.end('Hello World'); return; } res.writeHead(405, headers); res.end(`${req.method} is not allowed for the request.`); }); /* socket */ io = socketIO(server); io.on('connection', (socket) => { console.log("connected"); socket.on('refresh-user', (data)=>{ io.emit('refresh-user', data); console.log(data); }); }); server.listen(6900, ()=> { console.log('listening on 6900'); });
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!