Reputation: 391
I'm feeling really stupid about that, but here's my problem.
I'm using Socket-Controller and routing-controller in the same NodeTS App. Therefore i needed to create two express servers. One is listening to port 3000 or whatever the env is, and the other on port 65080. Locally, this works perfect. Now on GAE, my HTTP Server for the normal requests is working, while my SocketServer always times out.
If it helps, here is my app.yaml:
runtime: nodejs
env: flex
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: .5
memory_gb: 0.5
disk_size_gb: 10
network:
session_affinity: true
forwarded_ports:
- 65080
env_variables:
APP_NAME: Backend
APP_SCHEMA: https
APP_HOST: localhost
APP_PORT: 3000
APP_ROUTE_PREFIX: /api
APP_BANNER: true
TYPEORM_CONNECTION: postgres
TYPEORM_USERNAME: postgres
TYPEORM_DATABASE: db
TYPEORM_SYNCHRONIZE: true
TYPEORM_LOGGING: error
TYPEORM_LOGGER: advanced-console
And i am creating the SocketServer with that:
import {MicroframeworkLoader, MicroframeworkSettings} from 'microframework-w3tec';
import {createSocketServer} from 'socket-controllers';
import {env} from '../env';
export const socketLoader: MicroframeworkLoader = (settings: MicroframeworkSettings | undefined) => {
if (!settings) {
return;
}
const io = createSocketServer(65080, {
controllers: env.app.dirs.controllers,
middlewares: env.app.dirs.middlewares,
});
settings.setData('socket_io', io);
};
By the way, i am using this boilerplate.
Help is appreciated, since this is getting me frustrated. :)
EDIT: Creating an second microservice is not really an option, since they are sharing too much to be isolated from each other. (Services, DB Models, Settings).
EDIT: I configured the firewall with this:
--allow tcp:65080 \
--target-tags websocket \
--description "Allow websocket traffic on port 65080"
Upvotes: 0
Views: 163
Reputation: 391
Well, the solution was rather easy.
I needed to bind the Socket Server to the same HTTP Server instance, which express is using. Below are my changes.
socketLoader.ts
const io = require('socket.io')(settings.getData('express_server'));
useSocketServer(io, {
controllers: env.app.dirs.controllers,
middlewares: env.app.dirs.middlewares,
});
Where express_server is the server instance returned by expressApp.listen(env.app.port).
Upvotes: 2