I am integrating a websocket microservice with api gateway using express-gateway package and I am facing issue in proxying request from client to server via express-gateway. All the microservices including api-gateway are running inside docker container hosted on same bridge network that I defined as some-net.
I have tried how to integrate the websocket server with api-gateway from express-gateway documentation https://www.express-gateway.io/docs/plugins/plugin-development/ where we need to write a plugin and implement websocket proxying in the plugin. This setup is working fine when running on the local machine without containerizing the solution but when I am using the same solution in containers I am not able to connect to websocket.
this is my docker compose file
api_gateway:
build: ./api_gateway2/
ports:
- "3289:3289"
environment:
port: "8080"
HOST_EMAIL_SERVICE: 192.168.64.1
HOST_TICKET_SERVICE: 192.168.64.1
volumes:
- ./api_gateway2:/usr/src/app
- /usr/src/app/node_modules
networks:
- some-net
notification_service:
build: ./notification_service
container_name: notification_service
# command: npm start
volumes:
- ./notification_service:/usr/src/app
# restart: on-failure
ports:
- "8083:8083"
# network_mode: "host"
environment:
PORT: "8083"
DB_URI: mongodb://mongo-server:27017/service
depends_on:
- mongo
# links:
# - mongo
networks:
- some-net```
This my gateway config file
```http:
port: 3289
admin:
port: 9876
host: localhost
apiEndpoints:
notifications:
methods: "GET"
host: localhost
paths:""
serviceEndpoints:
notificationService:
url: "http://notification_service:8083"
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
- jwt
pipelines:
default:
notification:
apiEndpoints:
- notifications
policies:
- rate-limit:
- action:
max: 10
windowMs: 1000
# - jwt:
# - action:
# jwtExtractor: ['authBearer', 'authScheme', 'header', 'query']
# secretOrPublicKeyFile:
# checkCredentialExistence: false
- proxy:
- action:
serviceEndpoint: notificationService
ws: true```
So when I am hitting http://localhost:3289/notifcation this should ideally connect with my notification service that is running on port 8083 where I am running web sockets but this is giving me 404 not found error
This is my websocket plugin
```module.exports = {
version: '1.2.0',
name: "socket",
schema: {
"$id": "https://express-gateway.io/schemas/plugins/socket.json"
},
init: function (pluginContext) {
pluginContext.eventBus.on('hot-reload', function ({ type, newConfig }) {
});
pluginContext.eventBus.on('http-ready', function ({ httpServer }) {
try {
const httpProxy = require('http-proxy')
const proxy = new httpProxy.createProxyServer({
target: {
host: 'notification_service',
port: 8083
}
});
//const proxy = new httpProxy.createProxyServer({target: 'http://notification_service:8083'})
httpServer.on('upgrade', (req, socket, head) => {
proxy.ws(req, socket, head);
})
} catch (err) {
throw new Error('proxy error')
}
});
}
};```
I have mentioned localhost in the host but did not work later I thought Since all the containers are running on same network called some-net in my case as mentioned in the docker-compose file I thought of specifying container name in the host field that too did not work. please help me how to solve this problem