Added ability to enable https in express

This commit is contained in:
Davide Passoni 2024-03-13 15:05:30 +01:00
parent 5ba1498802
commit f0c4b10084
5 changed files with 83 additions and 20 deletions

View File

@ -20,10 +20,10 @@ console.log("Please wait while DCS Olympus Server starts up...");
console.log(`Config location: ${args["config"]}`)
/* Load the configuration file */
var frontendPort = 0;
var httpPort = 0;
if (fs.existsSync(args["config"])) {
var json = JSON.parse(fs.readFileSync(args["config"], 'utf-8'));
frontendPort = json["frontend"]["port"];
httpPort = json["frontend"]["port"];
} else {
console.log("Failed to read config, aborting!");
return;
@ -35,7 +35,7 @@ var debug = require('debug')('client:server');
var http = require('http');
/* Normalize port */
var port = normalizePort(frontendPort);
var port = normalizePort(httpPort);
app.set('port', port);
console.log("Express server listening on port: " + port)
@ -47,6 +47,21 @@ server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/* Optional https support */
var https = null;
var credentials = null;
var httpsServer = null;
if (json["frontend"]["https"] === true){
https = require('https');
var privateKey = fs.readFileSync(json["frontend"]["keyPath"] ?? "./cert/default.key", 'utf8');
var certificate = fs.readFileSync(json["frontend"]["certPath"] ?? "./cert/default.crt", 'utf8');
var httpsPort = json["frontend"]["httpsPort"] ?? 3433;
credentials = {key: privateKey, cert: certificate};
httpsServer = https.createServer(credentials, app);
httpsServer.listen(httpsPort);
console.log("Express server listening on SSL port: " + httpsPort)
}
/* Normalize a port into a number, string, or false. */
function normalizePort(val) {
var port = parseInt(val, 10);

View File

@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIUJj3UsO7kZ2w0ERm2kq5vBKvHskIwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDAzMTExNjQzMzNaFw0yNTAz
MTExNjQzMzNaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXR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0pXAjOMGWrcNDc5a+HAS7NsV
Ze6BBGXo7uW61tQFxNXwChTtRWnRtJyLlns0a9WQHwrHo1T1vIpiRn2qB64SPtsl
wTONOUsHo01yR2reEy21PFxkvrFVvE7MhNA+eYuzsbu+tlHcjZboG7ty2QKBgBPv
0Tehc3YRNNE7n1geh2KuS6hIvlQO/7lnSanyYhl/iSxZtRs5OuIVUtSv7D/3SDFZ
OVu3wBvQ91RP1pGpn8tdc3kb0T1VNv/VrzrIlvD+i4LII20bprU/crpzlpAqeTlY
qA9UL7JSVW0ussNtWqj24TpuSbyap0aI6XfttJ9tAoGANdZ+MCSVOoLiur5twgZ2
zSImlAEfTpcvyc4wrHrx8VRKoPr3KONMjMnmmg6vxXHyXdQa2Cci8kDmdPcS0ZNl
FRw2GGVCtpbCh/AjoU1kmpMonYxyG44c182qfscizSof2bDaN+M6wZbyFYavGXQs
jqKudqwMbe/fDFVLRqvOqb4=
-----END PRIVATE KEY-----

View File

@ -4,6 +4,7 @@ echo D|xcopy /Y /S /E .\bin ..\..\build\frontend\bin
echo D|xcopy /Y /S /E .\public ..\..\build\frontend\public
echo D|xcopy /Y /S /E .\routes ..\..\build\frontend\routes
echo D|xcopy /Y /S /E .\views ..\..\build\frontend\views
echo D|xcopy /Y /S /E .\views ..\..\build\frontend\cert
echo F|xcopy /Y .\app.js ..\..\build\frontend\app.js
echo F|xcopy /Y .\client.js ..\..\build\frontend\client.js

View File

@ -183,36 +183,34 @@ declare module "constants/constants" {
maxZoom: number;
attribution: string;
};
"USGS Topo": {
urlTemplate: string;
minZoom: number;
maxZoom: number;
attribution: string;
};
"OpenStreetMap Mapnik": {
urlTemplate: string;
minZoom: number;
maxZoom: number;
attribution: string;
};
OPENVKarte: {
"DCS Marianas Modern": ({
urlTemplate: string;
minZoom: number;
maxZoom: number;
attribution: string;
};
"Esri.DeLorme": {
minNativeZoom?: undefined;
maxNativeZoom?: undefined;
attribution?: undefined;
} | {
urlTemplate: string;
minNativeZoom: number;
maxNativeZoom: number;
minZoom: number;
maxZoom: number;
attribution?: undefined;
} | {
urlTemplate: string;
minNativeZoom: number;
maxNativeZoom: number;
minZoom: number;
maxZoom: number;
attribution: string;
};
CyclOSM: {
urlTemplate: string;
minZoom: number;
maxZoom: number;
attribution: string;
};
})[];
};
export const IDLE = "Idle";
export const MOVE_UNIT = "Move unit";