Websocket error with catapult and typescript / angular

I’m getting 404 error, I’m trying to connect to a websocket in Typescript, the websocket is catapult, when opening the connection the output is http and not ws, even when in my url parameter I place ws: // my-ip.

import { Listener, BlockInfo } from "nem2-sdk/dist";
const listener = new Listener('ws://miIp:3000');
listener.open();

When doing what I did above, the output in the browser is as follows:

GET http://miIp:3000/ws 404 (Not Found)

Fetch API cannot load http://miIp:3000/ws. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

PLEASE HELP !!

This is the example that I am doing https://nemtech.github.io/guides/blockchain/listening-new-blocks.html

Node.js and the browser use different websockets. Try to inject a websocket if you use angular.

import { Listener, BlockInfo } from "nem2-sdk/dist";
const listener = new Listener('ws://miIp:3000', WebSocket);
listener.open().then...
1 Like

I had the same problem in SPA mode of Nuxt.js.
And I solved it in this way. It is really helpful information.