UNPKG

adventure-engine

Version:

Simple text based adventure game library.

59 lines (43 loc) 1.49 kB
//========================================================= // server.js: Express server for eighty40 game library //========================================================= // Author: Mr. Piltin // Version: 0.2.1 // History: // 0.1.0: Initial version // 0.2.0: Wrap as a module // 0.2.1: Fix path for use as npm module on repl.io //========================================================= "use strict" const path = require('path'); var EightyForty = (function () { let instance; function init(port, debug) { const express = require('express'), app = express(), http = require('http').createServer(app), io = require('socket.io')(http); debug && console.log('Server path: ' + __dirname); debug && console.log('Client path: ' + path.join(__dirname, '../client')); global.ASSETS_DIR = path.join(__dirname, 'assets'); if (debug) { app.use(express.static('../adventure_engine/src/client')); } else { app.use(express.static(path.join(__dirname, '../client'))); } app.get('/', function (req, res) { res.sendFile('index.html'); }); http.listen(port, function () { console.log(`EightyForty server up on port ${port}.`); }); return io; } return { getInstance: function (port, debug) { if (!instance) { instance = init(port, debug); } return instance; } } })(); module.exports = EightyForty;