Skip to content

Commit

Permalink
Added a setup utility
Browse files Browse the repository at this point in the history
  • Loading branch information
wassgha committed Jun 11, 2019
1 parent 5e369e2 commit 52c1e6d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions makeconf.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

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

0 comments on commit 52c1e6d

Please sign in to comment.