| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | var express = require('express'),    compression = require('compression'),    serveStatic = require('serve-static'),    serveIndex = require('serve-index'),    cors = require('cors'),    morgan = require('morgan'),    path = require('path'),    fs = require('fs'),    argv = require('optimist').argv,    http = require('http'),    https = require('https');//  var privateKey  = fs.readFileSync('sslcert/server.key', 'utf8');// var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');var app = express();var port = 3007;app.use(compression());app.use(serveStatic(__dirname + '/public'));app.use(cors());// app.use(function(req, res, next) {//   res.header("Access-Control-Allow-Origin", "*");//   res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");//   next();// });app.use(morgan('combined'));/*=====Site specific paths=====*/// optional functions to load defaults (not required if DB is already bootstrapped)function readDirR(dir) {    if (fs.statSync(dir).isDirectory())     {      return Array.prototype.concat(...fs.readdirSync(dir).map(f => readDirR(path.join(dir, f))    ))    } else {      if ((dir.indexOf('.yaml') !== -1) || (dir.indexOf('.js') !== -1) || (dir.indexOf('.html') !== -1)      || (dir.indexOf('.json') !== -1))       return dir.replace(__dirname + '/public/', "/")    }}app.get('/proxy-files', function (req, res) { // console.log(allFilesSync(__dirname + '/public/proxy/'));  res.writeHead(200, {"Content-Type": "application/json"});  let json = JSON.stringify(readDirR(__dirname + '/public/defaults/proxy/'));  res.end(json);});app.get('/world-files', function (req, res) { // console.log(allFilesSync(__dirname + '/public/defaults/templates/'));  res.writeHead(200, {"Content-Type": "application/json"});  let json = JSON.stringify(readDirR(__dirname + '/public/defaults/worlds/'));  res.end(json);});// send all requests to index.html so browserHistory in React Router worksapp.get('*', function (req, res) {  res.sendFile(path.join(__dirname + '/public/', 'index.html'))})//=========end of specific===========// app.listen(port);// console.log('Web server is started on port: '+ port);var ssl = ( argv.s  || argv.ssl );var pass = ( ( argv.w) ? ( argv.w) : undefined );var sslOptions = {    key: ( ( argv.k || argv.key ) ? fs.readFileSync( argv.k || argv.key ) : undefined ),    cert: ( ( argv.c || argv.cert ) ? fs.readFileSync( argv.c || argv.cert ) : undefined ),    ca: ( ( argv.t || argv.ca ) ? fs.readFileSync( argv.t || argv.ca ) : undefined ),    passphrase: JSON.stringify(pass)};//create the servervar port = ( ( argv.p || argv.port ) ? ( argv.p || argv.port ) : 3007 );var srv = ssl ? https.createServer( sslOptions, app ).listen( port ) : http.createServer( app ).listen( port );console.log( 'Serving on port ' + port );
 |