Skip to content

Commit

Permalink
Move to .env for configuration instead of conf.json.
Browse files Browse the repository at this point in the history
This will make it easier to move things to Docker.
  • Loading branch information
tec27 committed Nov 26, 2022
1 parent 5e6a41c commit de35b09
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ npm-debug.log
*.swp
public/client.js
public/serviceworker.js
.env
48 changes: 6 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,58 +60,22 @@ $ 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:

```bash
$ 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
Expand Down Expand Up @@ -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
})
```
Expand Down Expand Up @@ -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!')
})
```
Expand Down
4 changes: 0 additions & 4 deletions conf.json-example

This file was deleted.

2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require('dotenv').config()

require('@babel/register')
require('./server')
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'))

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit de35b09

Please sign in to comment.