- Clone the repository (
git clone https://github.com/Trial-In-Error/poll.js
) or download the repository's contents as a zip file. - Install mongoDB from here or with
sudo apt-get install mongoDB
. Add mongodb/bin to the system path. Opiner is known to work with version 3.0.2 of MongoDB. - Install node.js from here or with
sudo apt-get install nodejs
. Add node.js/ to the system path. Opiner is known to work with version 0.12.2 of nodeJS. - Install redis-server for linux or for windows or with
sudo apt-get install redis-server
. Add redis-server/ to the system path. Note that this step is optional but highly recommended. Opiner is known to work with version 2.4.5 of redis-server. - From the repository's directory,
npm install
. - Get a coffee while
npm
does all the hard work. (Note that if npm fails, re-running it will often cause the installation to proceed). - Start the app from the repository's directory with
npm start
. - Point a web browser at
localhost:3000
and enjoy!
Note that npm run godbless
will start the server but not start redis or mongodb. This is useful for debugging changes without having to deal with redis
, mongodb
, and forever
.
- Start the server with
npm run
. This will start a mongo database. - Create a normal user via the web interface at /login.
- Access the database's shell from the
poll.js
directory with the command-line instructionmongo
. - Choose the mongo database for this project with
use polljs
. - Promote the user to an admin by
db.userdb.update({"type.login.username":"<username>"}, {$set: {"rights.<desiredRight>":true}})
. Note that you will have to do this for each right you wish to give to the admin.
Documentation for the mongo CLI can be found here. The full set of rights can be added with db.userdb.update({"type.login.username": "<username>"}, {$set: {"rights": { "answer": true, "delete": true, "openClose": true, "accessClosed": true, "getAnswers": true, "create": true}}})
.
Note that, because of the way session based authentication is done, the user will have to log back in after being promoted in order to have access to their new rights.
- Write a poll as a valid
.json
file, corresponding to the data model indatamodel.md
. - From the terminal,
mongoimport --db polljs --collection polldb --jsonArray < example_poll.json
.
Note that many example polls are provided in /polls.
- Write a poll as a valid
.json
file, corresponding to the data model indatamodel.md
. - Log into the web app with an admin account (the app should be running at
localhost:3000/login
oryourdeploymentname.herokuapp.com/login
). - Navigate to
localhost:3000/importpoll
(oryourdeploymentname.herokuapp.com/importpoll
), paste the.json
file into the textfield, and hit submit.
- Log into the web app with an admin account.
- Navigate to
localhost:3000/createpoll
. - Follow the prompts. The create poll interface is not quite as robust as manually editing the JSON; for instance, manual editing allows for branching and forking polls, while the create poll interface does not.
- Sign up for heroku.
- Download and install the heroku toolbelt.
- Authenticate with heroku using
heroku login
. - Commit changes via git with
git commit -m "trying heroku deployment!"
. - Create a heroku project with
heroku create
. - Deploy code with
git push heroku master
. - Start one dyno (worker process) with
heroku ps:scale web=1
. - Find a MongoDB-as-a-service provider here and follow their setup instructions. This project initially used MongoLab's free service.
- Find a redis-as-a-service provider at the same place and follow their setup instructions. This project initially used redisCloud's free service.
- Visit your app with
heroku open
!
heroku logs
view server logs.- Note that these will be full of color escape code garbage.
heroku ps
will show the status of all running dynos.git push heroku master
will kill all running dynos and run new ones in the same basic 'formation.'heroku restart dyno_type.dyno_number
will restart a specific dyno.heroku config:set ENV_VAR_NAME= config_var_value
will set environment variables.- These are exposed to node as
process.env.ENV_VAR_NAME
. - Use this for things like encryption / SSL keys.
- These are exposed to node as
heroku run SCRIPT/PROCESS
will spin up a new dyno running the named script or process. This dyno will automatically die from inactivity later. Changes to the filesystem on one dyno are not propogated to other dynos; modify a shared resource (database, queue, etc.) instead. Additionally, new dynos are always created from a slug (ready-to-run format created when you deploy), not from the state of the other dynos.- You can
heroku run bash
for an interactive session.
- You can
heroku logs --ps web.1 --tail
view the logs from one dyno (named web.1) and keep the connection open.
If the server can find a running redis-server, it will use that as the session memory store (redis behaves much like memcached). Testing can be done without redis-server running (as the server will fall back on node's default memory store), but production environments should absolutely use redis! Memory store cannot sync memory between multiple processes (so Heroku cannot scale past 1 dyno and still use sessions!) and has an inherent memory leak (sessions are never released from memory). So please use redis, even though it's listed as optional above.
An overview of the whole system, detailed explanations of its parts, help with the development tools, warnings, etc., can all be found on the github wiki. Good luck!
Everything included in this repository is permissively (e.g., MIT) licensed except for Isotope and Packery. If you wish to use the grid (/grid or /grid/:id), check here to to see if your use is fair use, or if you should buy a license. If your use is not fair use, you will need two licenses, one for packery and a second for isotope.
-
The HTTPS server is currently inactive. Turn it on by providing certificates (as documented below) and uncommenting lines 41-45 in /bin/server.js.
- Note that the HTTPS server will cause Heroku deployments to crash. Cause un-investigated.
-
Skype defaults to listening on port 443, blocking server.js from starting the HTTPS server.
-
MongoDB under Mac OSX will not get as many file descriptors as it would like.
- See this note.
-
None of the HTTPS keys are packaged with the app. You can generate self-signed certificates like so:
openssl genrsa -out polljs-key.pem 1024
openssl req -new -key polljs-key.pem -out certrequest.csr
openssl x509 -req -in certrequest.csr -signkey polljs-key.pem -out polljs-cert.pem
--