From ca7f92e309744292ce8bd0c2312c63a1c16fa0e6 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 8 Aug 2018 20:41:01 +0000 Subject: [server/config] Add server configs. Add config with tftp and https details. Use config port > ENV Variables port > default port. --- server/bin/www | 6 +++++- server/config/config.template.json | 10 ++++++++++ server/lib/tftp.js | 35 +++++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 server/config/config.template.json diff --git a/server/bin/www b/server/bin/www index 512fe54..3618506 100755 --- a/server/bin/www +++ b/server/bin/www @@ -10,11 +10,15 @@ var debug = require('debug')('bas:server') var https = require('https') var fs = require('fs') +/* global __appdir */ +var path = require('path') +var config = require(path.join(__appdir, 'config', 'config')).https + /** * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000') +var port = normalizePort(config.port || process.env.PORT || '3000') app.set('port', port) /** diff --git a/server/config/config.template.json b/server/config/config.template.json new file mode 100644 index 0000000..901454c --- /dev/null +++ b/server/config/config.template.json @@ -0,0 +1,10 @@ +{ + "https": { + "port": "" + }, + "tftp": { + "host": "", + "port": "", + "root": "" + } +} diff --git a/server/lib/tftp.js b/server/lib/tftp.js index 8d45cf0..104f984 100644 --- a/server/lib/tftp.js +++ b/server/lib/tftp.js @@ -1,14 +1,21 @@ 'use strict' -// This tftp server uses BAS port +1 -var tftpPort = process.env.PORT -tftpPort++ +/* global __appdir */ +var path = require('path') +var config = require(path.join(__appdir, 'config', 'config')).tftp + +var envPort = process.env.PORT +envPort++ + +var port = normalizePort(config.port || envPort || '69') +var host = config.host +var root = config.root var tftp = require('tftp') var server = tftp.createServer({ - host: '192.52.3.91', - port: tftpPort, - root: './tftp', + host: host, + port: port, + root: root, denyPut: true }) @@ -25,3 +32,19 @@ server.on('request', function (req) { }) server.listen() + +function normalizePort (val) { + var port = parseInt(val, 10) + + if (isNaN(port)) { + // named pipe + return val + } + + if (port >= 0) { + // port number + return port + } + + return false +} -- cgit v1.2.3-55-g7522