diff --git a/.gitignore b/.gitignore index 32420a0..b801483 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ npm-debug.log *.swp public/client.js public/serviceworker.js +.env diff --git a/README.md b/README.md index 81da86e..48b1119 100644 --- a/README.md +++ b/README.md @@ -60,16 +60,15 @@ $ sudo apt-get install ffmpeg ### Configuring your server -Server configuration is handled through a JSON file: `conf.json`. +Server configuration is handled through a `.env` file. See `sample.env` for the available options. -`conf.json-example` in the main directory will often provide all you need -for a development server, so for most developers, you can simply do: +For a local development server you can likely just do: ```bash -$ cp conf.json-example conf.json +$ cp sample.env .env ``` -This will set you up with a server running on port `3456` over HTTP. +This will set you up with a server running on port `3456`. The server can then be run with: @@ -77,41 +76,6 @@ The server can then be run with: $ npm start ``` -If you are running a production seatcamp server, or simply want to -customize your development environment, you can change a few options in -`conf.json`. The options are: - -### Normal options - -#### port - -The port to run the HTTP server on for this instance. - -**Ex:** `"port": 3000` - -#### host - -The host or IP to run the HTTP server on for this instance. If left unspecified, it will listen on all interfaces. - -**Ex:** `"host": "127.0.0.1"` - -#### idKey - -The key to use for hashing user ID's. This allows users to be given a -stable, unique ID per browser, but not expose their actual fingerprint -to other users on the server or be able to track users across seatcamp -instances. This value should be unique to the server you're running it -on and sufficiently long (10+ characters recommended). - -**Ex:** `"idKey": "thisServerIsGreat123"` - -#### gaTrackingId - -The tracking ID to use for Google Analytics tracking. If this isn't -specified (or is a falsy value), Analytics will not be utilized. - -**Ex:** `"gaTrackingId": "UA-9999999-1"` - ## Requirements for production servers Using a webcam from websites requires HTTPS (except for local addresses). The @@ -145,7 +109,7 @@ which should be saved so that a client can recognize which messages are its own. constant for the lifetime of the websocket connection. An example of handling the message would be: ```javascript -io.on('userid', function(userId) { +io.on('userid', function (userId) { myId = userId }) ``` @@ -223,7 +187,7 @@ to be known. These are all handled through seperate messages, which are: Specifies how many users are currently connected. ```javascript -io.on('active', function(numActive) { +io.on('active', function (numActive) { alert('There are ' + numActive + ' active seatcamp users!') }) ``` diff --git a/conf.json-example b/conf.json-example deleted file mode 100644 index 6349150..0000000 --- a/conf.json-example +++ /dev/null @@ -1,4 +0,0 @@ -{ - "port": 3456, - "idKey": "seatcamp" -} diff --git a/index.js b/index.js index cb0cc27..216abb5 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,4 @@ +require('dotenv').config() + require('@babel/register') require('./server') diff --git a/package-lock.json b/package-lock.json index 5e1bf08..feb6b86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "cuid": "^2.1.8", "data-uri-to-blob": "0.0.4", "data-uri-to-buffer": "^4.0.0", + "dotenv": "^16.0.3", "express": "^4.17.1", "html-loader": "^4.2.0", "lit": "^2.0.2", @@ -3218,6 +3219,14 @@ "tslib": "^2.0.3" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -11059,6 +11068,11 @@ "tslib": "^2.0.3" } }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package.json b/package.json index e9c9d15..ae428a4 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "cuid": "^2.1.8", "data-uri-to-blob": "0.0.4", "data-uri-to-buffer": "^4.0.0", + "dotenv": "^16.0.3", "express": "^4.17.1", "html-loader": "^4.2.0", "lit": "^2.0.2", diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..740114b --- /dev/null +++ b/sample.env @@ -0,0 +1,14 @@ +# Sample configuration file +# Copy this to a file named .env to change server settings + +# Key to use for hashing user ID's. This allows users to be given a stable, unique ID per browser, +# but not expose their actual fingerprint to other users on the server or be able to track users +# across seatcamp instances. This value should be unique to the server you're running it on and +# sufficiently long (10+ characters recommended). +SEATCAMP_ID_KEY=seatcamp +# Port to bind the webserver on +SEATCAMP_PORT=3456 +# Host to bind the webserver on (optional) +#SEATCAMP_HOST=127.0.0.1 +# Google Analytics ID (optional) +#SEATCAMP_GA_ID=UA-12345678-9 diff --git a/server.js b/server.js index b3b9887..9cf8e36 100644 --- a/server.js +++ b/server.js @@ -12,19 +12,18 @@ import createFfmpegRunner from './lib/ffmpeg-runner' import ChatSockets from './lib/chat-sockets' import webpackConfig from './webpack.config' -import config from './conf.json' -const userIdKey = config.idKey +const userIdKey = process.env.SEATCAMP_ID_KEY if (!userIdKey) { - throw new Error('idKey must be specified in conf.json!') + throw new Error('SEATCAMP_ID_KEY must be specified!') } const app = express() app.set('x-powered-by', false).set('view engine', 'pug') const httpServer = http.Server(app) -const listenPort = config.port -const listenHost = config.host +const listenPort = process.env.SEATCAMP_PORT ?? 3456 +const listenHost = process.env.SEATCAMP_HOST const io = socketIo(httpServer) @@ -44,7 +43,7 @@ if (process.env.NODE_ENV !== 'production') { app.use(compression()) app .get('/', (req, res) => - res.render('index', { theme: req.cookies.theme, trackingId: config.gaTrackingId }), + res.render('index', { theme: req.cookies.theme, trackingId: process.env.SEATCAMP_GA_ID }), ) .get('/styles.css', serveCss(__dirname + '/css/styles.css')) @@ -81,7 +80,7 @@ const readyPromise = compilePromise.then(async stats => { await new Promise(resolve => httpServer.listen(listenPort, listenHost, resolve)) const host = httpServer.address().address const port = httpServer.address().port - console.log('Listening at http%s://%s:%s', config.sslCert ? 's' : '', host, port) + console.log('Listening at http://%s:%s', host, port) }) export default {