NestJs socket Io works on a different port but not the same port - sockets

I am trying to implement socket Io into an application. However nestjs WebSocketGateway doesnt seem to get triggered when the port isnt defined. However when using a different port for WebSocketGateway the frontend connects succesfully.
This works
#WebSocketGateway(8001, {
path: '/socket-chat',
cors: {
origin: '*',
},
})
This doesnt work
#WebSocketGateway({
path: '/socket-chat',
cors: {
origin: '*',
},
})
When using the same port as the API, the middleware gets triggered however it seems to be working and sucessfully passing the request. I would like to use the same port but not sure how. Thank you :)

Related

How to make a SOAP request with axios the right way

Here is how I make it:
this.http.get<string>(url, config).toPromise();
Where the config object looks like this:
const config: AxiosRequestConfig = {
headers: {'Content-Type': 'text/xml'},
data: this.getRequestBodyFor(date)
}
However it errors out with [ExceptionsHandler] connect ECONNREFUSED 127.0.0.1:80. It does seem like the client is trying to make the request to the localhost, port 80 which is not what it is supposed to be doing. There must be some problem with the configuration.

How to redirect using webpack proxy the dependencies of the redirected website?

I have two projects, one with documentation and one as the actual app.
When I access http://localhost:3000/docs my webpack setup is redirecting me to another server which is on http://localhost:4000 and where the documentation lives.
The redirect is happening but when it tries to load dependencies (.js, .css) the request is made on the original port (3000) and not the port 4000.
How can I redirect the server requests for the second website?
My webpack setup:
proxy: {
"/docs/**": {
target: "http://localhost:8080",
pathRewrite: { "^/docs": "" },
changeOrigin: true,
secure: false,
}
}

Kubernetes API using websocket from NodeJS

I am writing a NodeJS application which is supposed to get deploymentstatuses from the Kubernetes API using the websocket transport layer.
For this I use the socket.io-client module and I connect with the following snippet:
var url = 'wss://myurl:8443?watch=true&access_token=myaccesstoken';
var socket = ioClient.connect(url, {
reconnect: true,
transports : ['websocket'],
path : "/api/v1/namespaces/mynamespace/replicationcontrollers",
secure : true,
rejectUnauthorized: false,
verify : false});
This however gives me an unexpected error, 403. Testing this in extensions like Websocket Client to Chrome works perfectly fine. Also I receive a 200 if I try a path with less sensetive data, but not an upgrade to websocket.
I read somewhere the Kubernetes API doesn't treat the WebSocket-protocol correctly, perhaps this is related? I have also tried with other more native libraries to Node such as websocket and ws with the same result.
When adding a ?watch=true in a Kubernetes API call, the request does not use WebSocket's but instead will stream / chunk the response over the HTTP connection.

Frisby.js Error: tunneling socket could not be established

I am trying to test an REST API on my local machine using frisby.js . It throws the following error.
Error: tunneling socket could not be established.
The machine address is something like 'https://machine_name:8443'
It seems that you are behind a proxy. Then, to make your frisby test working, you need to apply proxy configuration as follows:
var frisby = require('frisby');
frisby.globalSetup({
request: {
proxy: 'http://xx.xx.xx.xx:yyyy' // Provide proxy info (host, port) here
}
});
frisby.create('Your spec description here')
.get('https://machine_name:8443')
.expectStatus(200)
.toss();
Note also that you are using HTTPS protocol. Then you may find useful my answer in this post in case you have problems with SSL certificates

Loading store data with rest proxy from server in Sencha Touch 2

I have searched around on the forums and read some other posts. However, I'm not sure how exactly to go about this. I have a store with a proxy that I'm trying to load with data from a server. I have tried both jsonp and rest for the type of proxy without luck. In both cases I get a 403 forbidden error. followed by an XMLHTTPRequest cannot load error.
Here's the error that I see in the Chrome console:
Here's my code:
Ext.define('EventsTest.store.Venues', {
extend: 'Ext.data.Store',
requires: [
'Ext.data.proxy.Rest',
],
config: {
storeId: 'venuesStore',
model: 'EventsTest.model.Venue',
proxy: {
type: 'rest',
url: 'http://leo.web/pages/api/',
headers: {
'x-api-key': 'senchaleotestkey'
},
limitParam: false,
pageParam: false,
enablePagingParams: false
/*
extraParams: {
latitude: 45.250157,
longitude: -75.800257,
radius: 5000
}
*/
}
}
});
Security policy in browser and desktop is different so even if it fails in browser it can work in phone. But now the question is how to manage while you are developing the app, for that have a look at this similar question :
How to use json proxy to access remote services during development
Regarding that OPTION request which is getting 403 response, try setting withCredentials : false and useDefaultHeader : false. Details here
http://docs.sencha.com/touch/2-1/#!/api/Ext.data.Operation-cfg-withCredentials
http://docs.sencha.com/touch/2-1/#!/api/Ext.data.Connection-cfg-useDefaultHeader
I would suggest you to read more about CORS if you want to use remote services, you may choose to enable CORS on your server.
You're running your app on a local domain "sencha.test", but you're trying to access data on "leo.web" - the error is that you're trying to load data across domains, which isn't allowed via AJAX.
You say that JSONP doesn't work... why not? Does your server return valid JSONP?