Answer the question
In order to leave comments, you need to log in
How to set socket io connection in Angular?
Good afternoon!
Faced such a problem, I created socket io on a Linux server and I write an application in angular, I try to connect but I get such an error
Request from foreign origin blocked: Single origin policy prohibits reading remote resource on https://dev.telecomis.ru/socket.io/?EIO=3&transpor... (Reason: Missing "Access-Control-Allow-Origin" CORS header )
var express = require('express'),
http = require('http');
var app = express(),
server = http.createServer(app),
io = require('socket.io')(server, {"path": "/connect"}).listen(httpsPort);
...
// Ну тут все по стандарту
// Это в app.modul.ts
const config: SocketIoConfig = { url: 'https://XXXXXXXX/connect/', options: {} };
// Это в app.component.ts
import { Injectable } from '@angular/core'
import { Socket } from 'ngx-socket-io'
this.socket.emit("data", JSON.stringify({ 'index': 'angular' }))
Answer the question
In order to leave comments, you need to log in
The error was in the post, fixed it with const config: SocketIoConfig = { url: ' https://XXXXXXX ', options: { path: '/connect/' } } and everything worked
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question