From: Martin Skorupski Date: Thu, 30 Mar 2023 09:49:26 +0000 (+0200) Subject: Add generated express files to repo X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=5dc2ff0f5d281da1e96bf1f0760826f7f8fedbc5;p=oam.git Add generated express files to repo - create http-server/start file Issue-ID: OAM-321 Change-Id: Ie4bff28481217c4a05ea9c867d955dea6dfebc8e Signed-off-by: Martin Skorupski --- diff --git a/code/container-analysis/viewer/http-server/start b/code/container-analysis/viewer/http-server/start new file mode 100755 index 0000000..2e68974 --- /dev/null +++ b/code/container-analysis/viewer/http-server/start @@ -0,0 +1,99 @@ +#!/usr/bin/env node +/* + * Copyright 2023 highstreet technologies and others + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * Module dependencies. + */ +const app = require('../app'); +const debug = require('debug')('viewer:server'); +const http = require('http'); + +/** + * Normalize a port into a number, string, or false. + */ +const normalizePort = (val) => { + const port = parseInt(val, 10); + + if (isNaN(port)) { + // named pipe + return val; + } + + if (port >= 0) { + // port number + return port; + } + + return false; +} + +/** + * Event listener for HTTP server "error" event. + */ +const onError = (error) => { + if (error.syscall !== 'listen') { + throw error; + } + + const bind = typeof port === 'string' + ? 'Pipe ' + port + : 'Port ' + port; + + // handle specific listen errors with friendly messages + switch (error.code) { + case 'EACCES': + console.error(bind + ' requires elevated privileges'); + process.exit(1); + break; + case 'EADDRINUSE': + console.error(bind + ' is already in use'); + process.exit(1); + break; + default: + throw error; + } +} + +/** + * Event listener for HTTP server "listening" event. + */ +const onListening = () => { + const addr = server.address(); + const bind = typeof addr === 'string' + ? 'pipe ' + addr + : 'port ' + addr.port; + debug('Listening on ' + bind); +} + +/** + * Get port from environment and store in Express. + */ +const port = normalizePort(process.env.PORT || '3000'); +app.set('port', port); + +/** + * Create HTTP server. + */ +const server = http.createServer(app); + +/** + * Listen on provided port, on all network interfaces. + */ +server.listen(port); +server.on('error', onError); +server.on('listening', onListening);