From e66c713ea8ae4788af1917486e0beec68a0d21ab Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Fri, 13 Jan 2023 14:00:18 +0100 Subject: [PATCH] Listened SERVER_PORT env variable on applications servers --- openvidu-basic-dotnet/Program.cs | 22 ++++++++++++++-------- openvidu-basic-node/.env | 1 + openvidu-basic-node/index.js | 20 +++++++++++--------- openvidu-basic-python/.env | 1 + openvidu-basic-python/app.py | 3 ++- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/openvidu-basic-dotnet/Program.cs b/openvidu-basic-dotnet/Program.cs index b75ef76f..6d654689 100644 --- a/openvidu-basic-dotnet/Program.cs +++ b/openvidu-basic-dotnet/Program.cs @@ -8,6 +8,16 @@ var builder = WebApplication.CreateBuilder(args); var MyAllowSpecificOrigins = "_myAllowSpecificOrigins"; +IConfiguration config = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .AddEnvironmentVariables().Build(); + +// Load env variables +var SERVER_PORT = config.GetValue("SERVER_PORT"); +var OPENVIDU_URL = config.GetValue("OPENVIDU_URL"); +var OPENVIDU_SECRET = config.GetValue("OPENVIDU_SECRET"); + // Enable CORS support builder.Services.AddCors(options => { @@ -18,17 +28,13 @@ builder.Services.AddCors(options => }); }); +builder.WebHost.UseKestrel(serverOptions => { + serverOptions.ListenAnyIP(SERVER_PORT); +}); + var app = builder.Build(); app.UseCors(MyAllowSpecificOrigins); -IConfiguration config = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .AddEnvironmentVariables().Build(); - -// Load env variables -var OPENVIDU_URL = config.GetValue("OPENVIDU_URL"); -var OPENVIDU_SECRET = config.GetValue("OPENVIDU_SECRET"); // Allow for insecure certificate in OpenVidu deployment var handler = new HttpClientHandler diff --git a/openvidu-basic-node/.env b/openvidu-basic-node/.env index 5c568f85..76dfb4e8 100644 --- a/openvidu-basic-node/.env +++ b/openvidu-basic-node/.env @@ -1,2 +1,3 @@ +SERVER_PORT=5000 OPENVIDU_URL=http://localhost:4443/ OPENVIDU_SECRET=MY_SECRET \ No newline at end of file diff --git a/openvidu-basic-node/index.js b/openvidu-basic-node/index.js index a5e5aeb0..73193b15 100644 --- a/openvidu-basic-node/index.js +++ b/openvidu-basic-node/index.js @@ -6,6 +6,13 @@ var OpenVidu = require("openvidu-node-client").OpenVidu; var cors = require("cors"); var app = express(); +// Environment variable: PORT where the node server is listening +var SERVER_PORT = process.env.SERVER_PORT || 5000; +// Environment variable: URL where our OpenVidu server is listening +var OPENVIDU_URL = process.env.OPENVIDU_URL || 'http://localhost:4443'; +// Environment variable: secret shared with our OpenVidu server +var OPENVIDU_SECRET = process.env.OPENVIDU_SECRET || 'MY_SECRET'; + // Enable CORS support app.use( cors({ @@ -14,6 +21,7 @@ app.use( ); var server = http.createServer(app); +var openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET); // Allow application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: true })); @@ -24,17 +32,11 @@ app.use(bodyParser.json()); app.use(express.static(__dirname + '/public')); // Serve application -server.listen(5000, () => { - console.log("Application started"); +server.listen(SERVER_PORT, () => { + console.log("Application started on port: ", SERVER_PORT); + console.warn('Application server connecting to OpenVidu at ' + OPENVIDU_URL); }); -console.warn('Application server connecting to OpenVidu at ' + process.env.OPENVIDU_URL); - -var openvidu = new OpenVidu( - process.env.OPENVIDU_URL, - process.env.OPENVIDU_SECRET -); - app.post("/api/sessions", async (req, res) => { var session = await openvidu.createSession(req.body); res.send(session.sessionId); diff --git a/openvidu-basic-python/.env b/openvidu-basic-python/.env index 5c568f85..1ac0bfce 100644 --- a/openvidu-basic-python/.env +++ b/openvidu-basic-python/.env @@ -1,2 +1,3 @@ +OPENVIDU_URL=5000 OPENVIDU_URL=http://localhost:4443/ OPENVIDU_SECRET=MY_SECRET \ No newline at end of file diff --git a/openvidu-basic-python/app.py b/openvidu-basic-python/app.py index e5bf54d6..66dc4da6 100644 --- a/openvidu-basic-python/app.py +++ b/openvidu-basic-python/app.py @@ -9,6 +9,7 @@ app = Flask(__name__) cors = CORS(app, resources={r"/*": {"origins": "*"}}) # Load env variables +SERVER_PORT = os.environ.get("SERVER_PORT") OPENVIDU_URL = os.environ.get("OPENVIDU_URL") OPENVIDU_SECRET = os.environ.get("OPENVIDU_SECRET") @@ -47,4 +48,4 @@ def createConnection(sessionId): if __name__ == "__main__": - app.run(debug=True, host="0.0.0.0") + app.run(debug=True, host="0.0.0.0", port=SERVER_PORT)