Reputation: 272
I want to deploy a flask socketio server on app engine. This is the imports, and runs of the server:
from typing import List
from flask_socketio import SocketIO, join_room, leave_room, send, emit
from flask import Flask, render_template, request, session, url_for
import sys
import numpy as np
import random
import re
import itertools
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret-key'
socketio = SocketIO(app, cors_allowed_origins="*")
...
if __name__ == '__main__':
socketio.run(app, port='8080', debug=True)
This is my app.yaml:
runtime: python
env: flex
service: server
entrypoint: python3 main.py
runtime_config:
python_version: 3
automatic_scaling:
min_num_instances: 1
max_num_instances: 2
I am using angular as a client, and it is connecting with this line:
this.socket = io('https://my-server-url.appspot.com');
When I try to run the angular app it says
Access to XMLHttpRequest at 'https://server-url.appspot.com/socket.io/?EIO=3&transport=polling&t=NJu9Zq7' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I also tried setting the cors_allowed_origins option to [] but it didn't work either. I also tried setting session affinity to true and it didn't work either.
header is present on the requested resource.
I did not open the server url in another tab, and I want the server to run in the background.
Can you help? Thanks
Upvotes: 3
Views: 440
Reputation: 272
Fixed it.
I set the session_affinity
to true and then I changed the entrypoint
to:
entrypoint: gunicorn -b :8080 -k eventlet main:app
App engine only works with the port of 8080.
Upvotes: 1