Sails.js support both web-socket and http-request api call.
I have some route for my rest api like
get /api/v1/userController/fetch
but I can't call this route from socket, there is any way to bind this route in socket.io and call this route from both web-socket and http-request?
I found an android library here:
http://joshuamarquez.me/2016/06/12/how-to-use-sails.io.js-in-java/
This library is an wrapper around socket.io and connect to sails project in both socket and http way.
don't know why they don't mention this library in sails documentation :|
Related
I`m wondering if it is possible to implement following:
I have some service in GO (used for Firebase Cloud Messaging) it uses go package from firebase (firebase.google.com/go/v4) to send messages. This packge sends https requests. And One of them is to https://oauth2.googleapis.com/token to get token.
I can't change code in Firebase go-package, but I need to use proxy, that is why before sending message I need to set HTTPS_PROXY environment variable to my proxy address. It works fine.
Now I need to do some automatic tests and I have an emulator that has /token endpoint and return a valid token as response. Is it possible to use some kind of proxy that can redirect https requests to my emulators endpoint so that all requests to https://oauth2.googleapis.com/token should be redirected to my emulators endpoint /token?
And another question is there are any possible problems because of HTTPS ?
Is it possible to get rid of https and use only http after the proxy?
Found following solution:
Firebase Cloud Messaging package uses clone default transport to create http.client under the hood.
So we can configure http.DefaultTransport before calling app.Messaging(ctx) and set up any parameters we need (proxy, insecureSkipVerify ...).
So no problems at all.
I am try to implement a basic web socket app by following this tutorial:https://spring.io/guides/gs/messaging-stomp-websocket/
However, in that tutorial there was a client UI implementation. I don't want to use UI. Instead of the UI, I want to use a websocket client extension in Chrome for sending and seeing messages.
All codes same with the tutorial(except the UI part since I'dont want UI), so I don't rewrite all codes here.
I am able to connect and send message to the url: ws://localhost:8081/gs-guide-websocket for example,
However, I can't get response with this url: ws://localhost:8081/topic/greetings. (I use this URL for getting responses by subscribing it. Because this topic/greetings path used in the UI side of that tutorial for subscription)
The Chrome extension that I used is Simple WebSocket Client.
Why I couldn't subscribe the ws://localhost:8081/topic/greetings url? and How can I get messages from the server by using the Chrome client websocket extensions?
Your application works with STOMP and SockJs, this plugin does not support that. It only works with ws. In this example, you can write a simple ws endpoint for your application:
example simple ws endpoint
I want to use websocket to access Kubernetes API, and so it is more convenient to send token like wss://example.com" + url + "&access_token=blahblahblah. The official API doc sends token in header. Where can I find such a token and send it with url?
What I want to do is to exec pods via a web page through websocket:
Container-Terminal via Websocket
Support exec and pod logging over WebSockets
Bearer token authentication in the URL is not supported in Kubernetes currently, only as an Authorization header.
After searching over the Internet and reading many discussion on Kubernetes, I post my own answer about accessing kubernetes API with password in url, not header:
wss://username:myPassword#Address.To.Kubernetes/api/v1/namespaces/default/pods/YourPodName/exec?stdout=1&stdin=1&stderr=1&tty=1&command=%2Fbin%2Fsh
The username and password is in ~/.kube/config
Welcome answers for sending bearer token.
There is currently no way to send Authorization headers using native javascript WebSockets.
All third-party websocket libraries depend on the in-browser WebSocket class, which currently does not support custom headers. I tried a bunch of different libraries, but no luck :(
See Stack Overflow thread here: https://stackoverflow.com/a/4361358
The reason that this is not implemented is that Chromium/Chrome implementors are opposed to it. See the full discussion here: https://github.com/whatwg/websockets/issues/16#issuecomment-332065542
My workaround
Currently I'm working around this by using the #kubernetes/client-node in NodeJS to open a WebSocket connection.
The ws WebSocket library in NodeJS does support Authorization headers.
Then forwarding the NodeJS WebSocket messages to the front-end using Socket.io: https://stackoverflow.com/a/62547135.
I want to do place on server application which can be called by Go APP and Java app both.
for some reason ,there's a cookie authentication and oAuth mechanism ,so I want to set one Go app as Auth Micro-service for the authentication purpose.
As GRPC is built on the HTTP2 ,so The headers and cookies are on the protocol.but I did not find out how to carry on header and cookie when the rpc occurs,implemented by Go, on GitHub I only found the JAVA-Implementation for headers at :
https://github.com/grpc/grpc-java/tree/master/examples/src/main/java/io/grpc/examples/header
Can anybody give me some direction of Go implementation for this purpose?
Headers in gRPC are called "Metadata." Clients can only send "headers". Servers can send both "headers" and "trailers."
You want to:
Use the google.golang.org/grpc/metadata package and metadata.NewContext() to send metadata from the client-side.
Use grpc.SendHeader() and grpc.SetTrailer() to send metadata from the server-side.
Use the grpc.Header() and grpc.Trailer() CallOptions for receiving the Metadata on the client-side.
Use metadata.FromContext() for receiving metadata on the server-side.
I have a cordova app running on angular that uses a sails server as its API endpoint. It is set up to use CORS and everything is working with ajax calls.
I am attempting to connect to the sails server using socket.io. I copied the sails.io.s file from the sails server's assets folder to the cordova app. I modified it so that it connects to 127.0.0.1:1337 and does so successfully. It does not use cookies on the front end and the sails end does not use socket authorization (set in config/sockets.js).
When I call:
io.socket.get('/controller/action', function callback(return){
});
The return object looks something like this:
{
message: "TypeError: Object #<Object> has no method 'get'",
status: 500
}
The sails server log doesn't show that it is hitting /controller/action. Does anyone have any experience with using the custom sails io library on a JS client that isn't sails?