G
G
Galdar Turin2020-03-11 19:36:27
Angular
Galdar Turin, 2020-03-11 19:36:27

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 )


server
var express    = require('express'),
    http       = require('http');
    
var app             = express(),
    server          = http.createServer(app),
    io              = require('socket.io')(server, {"path": "/connect"}).listen(httpsPort);
...
// Ну тут все по стандарту


client
// Это в 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' }))

Both there and there, a certificate for nginx is already installed, but still an error, if you work without angular with the socket io library, then everything works.
Maybe someone knows the solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Galdar Turin, 2020-03-12
@Galdar

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 question

Ask a Question

731 491 924 answers to any question