From 52c1e6d111b34c8b021171f86d0d806618312e75 Mon Sep 17 00:00:00 2001 From: Wassim Gharbi Date: Mon, 10 Jun 2019 23:13:33 -0400 Subject: [PATCH] Added a setup utility --- README.md | 9 ++++++--- makeconf.json | 25 +++++++++++++++++++++++++ package.json | 8 +++++--- server.js | 11 +++++------ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 makeconf.json diff --git a/README.md b/README.md index e9ba2b9..6d9b7ed 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,14 @@ Use the demo website at [http://digitaldisplay.herokuapp.com](http://digitaldisp ### How to Run: -1. Set up a MongoDB installation locally and create a `digitaldisplay` database +1. Set up a MongoDB installation locally (or in the cloud) and create a `digitaldisplay` database -2. Rename the `.env.example` file to `.env` +2. Run the setup utility using -3. Change references to the database to link to your local database (usually `mongodb://localhost:27017/digitaldisplay`) +```bash +npm run setup +``` +and specify the URI to your database. 4. Install dependencies and run the program diff --git a/makeconf.json b/makeconf.json new file mode 100644 index 0000000..b357114 --- /dev/null +++ b/makeconf.json @@ -0,0 +1,25 @@ +{ + "format": ".env", + "file": ".env", + "config": { + "MONGODB_URI": { + "description": "Your MongoDB URI (remote or local)", + "required": true + }, + "PORT": { + "description": "Which port should the server run on?", + "default": "3001", + "required": true + }, + "ENVIRON": { + "description": "Environment (DEV or PROD)", + "default": "DEV", + "required": true + }, + "SESSION_SECRET": { + "description": "Session secret key (can be anything)", + "default": "3i2br082jrfdsufnsfk10", + "required": true + } + } +} diff --git a/package.json b/package.json index 73f732b..c3a6e75 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,11 @@ "description": "This is a user interface for a dynamic digital signage", "main": "index.js", "scripts": { - "dev": "cross-env NODE_ENV=dev node server.js", - "build": "next build", + "setup": "[ -f .env ] || makeconf", + "dev": "npm run setup && ENVIRON=DEV node server.js", + "build": "npm run setup && next build", "lint": "eslint --color ./ *.js", - "start": "NODE_ENV=production node server.js", + "start": "npm run setup && ENVIRON=PROD node server.js", "test": "echo \"No test specified yet.\" && exit 0", "heroku-postbuild": "next build" }, @@ -46,6 +47,7 @@ "isomorphic-unfetch": "^3.0.0", "js-cookie": "^2.2.0", "lodash": "^4.17.11", + "makeconf": "^1.4.4", "mongoose": "^5.4.19", "mongoose-crudify": "^0.2.0", "multer": "^1.4.1", diff --git a/server.js b/server.js index 308ac73..75e799d 100644 --- a/server.js +++ b/server.js @@ -8,14 +8,13 @@ const session = require('cookie-session') const bodyParser = require('body-parser') const socketIo = require('socket.io') -const dev = process.env.NODE_ENV !== 'production' -const port = process.env.PORT || 3000 +const Keys = require('./keys') + +const dev = Keys.ENVIRON !== 'PROD' const app = next({ dev }) const routes = require('./routes') const handle = routes.getRequestHandler(app) -const Keys = require('./keys') - const apiRoutes = require('./api/routes') const User = require('./api/models/User') @@ -80,10 +79,10 @@ app return handle(req, res) }) - const finalServer = server.listen(port, err => { + const finalServer = server.listen(Keys.PORT, err => { if (err) throw err // eslint-disable-next-line - console.log('> Ready on http://localhost:' + port) + console.log('> Ready on http://localhost:' + Keys.PORT) }) // Socket.io