|
| 1 | + |
| 2 | +PrairieLearn |
| 3 | +============ |
| 4 | + |
| 5 | +PrairieLearn is an online problem-driven learning system. It consists |
| 6 | +of a server component that presents questions and other data via an |
| 7 | +API, and a webapp that interfaces with the user and communicates with |
| 8 | +the server. |
| 9 | + |
| 10 | +Building |
| 11 | +-------- |
| 12 | + |
| 13 | +1. Install the pre-requisites: |
| 14 | + |
| 15 | + * [Node.js](http://nodejs.org/) |
| 16 | + * [npm](https://npmjs.org/) |
| 17 | + * [MongoDB](http://www.mongodb.org/) |
| 18 | + |
| 19 | + On OS X these can be installed with [MacPorts](http://www.macports.org/) or [Homebrew](http://brew.sh/). |
| 20 | + |
| 21 | +2. Next clone the latest code: |
| 22 | + |
| 23 | + $ git clone https://github.com/PrairieLearn/PrairieLearn.git |
| 24 | + |
| 25 | +3. Install the backend libraries: |
| 26 | + |
| 27 | + $ cd PrairieLearn/backend |
| 28 | + $ npm install |
| 29 | + |
| 30 | +4. (Optional) Render question TeX image files for figures |
| 31 | + |
| 32 | + $ cd PrairieLearn/backend |
| 33 | + $ make |
| 34 | + |
| 35 | + |
| 36 | +Running the server |
| 37 | +------------------ |
| 38 | + |
| 39 | +1. Run the database: |
| 40 | + |
| 41 | + $ mongod --dbpath ~/db |
| 42 | + |
| 43 | +2. Run the server: |
| 44 | + |
| 45 | + $ cd PrairieLearn/backend |
| 46 | + $ node server |
| 47 | + |
| 48 | +3. In a web-browswer view the PrairieLearn/frontend/index.html file: |
| 49 | + |
| 50 | + $ open file://...<path>.../PrairieLearn/frontend/index.html |
| 51 | + |
| 52 | + |
| 53 | +To test the database, you can access it directly: |
| 54 | + |
| 55 | + $ mongo |
| 56 | + > show dbs |
| 57 | + > use data |
| 58 | + > show collections |
| 59 | + > db.users.find() |
| 60 | + > db.users.save({uid: "user1@illinois.edu"}) |
| 61 | + |
| 62 | +To test the server, you can access it from the commandline: |
| 63 | + |
| 64 | + $ curl http://localhost:3000/questions |
| 65 | + $ curl http://localhost:3000/questions/scalarAdd |
| 66 | + |
| 67 | + $ curl -H "X-Auth-UID: user1@illinois.edu" -H "X-Auth-Name: User Name" -H "X-Auth-Date: 2013-08-17T09:44:18Z" -H "X-Auth-Signature: 3d38a7acba63047cf8bcf29f9691c68a2cae30e3ae5057ef1ea4616d2060a4be" http://localhost:3000/users |
| 68 | + $ curl -H "X-Auth-UID: user1@illinois.edu" -H "X-Auth-Name: User Name" -H "X-Auth-Date: 2013-08-17T09:44:18Z" -H "X-Auth-Signature: 3d38a7acba63047cf8bcf29f9691c68a2cae30e3ae5057ef1ea4616d2060a4be" http://localhost:3000/users/user1@illinois.edu |
| 69 | + |
| 70 | + $ curl -H "X-Auth-UID: user1@illinois.edu" -H "X-Auth-Name: User Name" -H "X-Auth-Date: 2013-08-17T09:44:18Z" -H "X-Auth-Signature: 3d38a7acba63047cf8bcf29f9691c68a2cae30e3ae5057ef1ea4616d2060a4be" -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"uid": "user1@illinois.edu", "qid": "scalarAdd"}' http://localhost:3000/qInstances |
| 71 | + |
| 72 | + $ curl http://localhost:3000/questions/scalarAdd/1/question.html |
| 73 | + $ curl http://localhost:3000/questions/scalarAdd/1/client.js |
| 74 | + $ curl http://localhost:3000/questions/scalarAdd/1/params |
| 75 | + |
| 76 | + $ curl -H "X-Auth-UID: user1@illinois.edu" -H "X-Auth-Name: User Name" -H "X-Auth-Date: 2013-08-17T09:44:18Z" -H "X-Auth-Signature: 3d38a7acba63047cf8bcf29f9691c68a2cae30e3ae5057ef1ea4616d2060a4be" -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"uid": "user1@illinois.edu", "qid": "scalarAdd", "vid": "1", "qiid": "qi32", "submittedAnswer": {"c": "43"}}' http://localhost:3000/submissions |
| 77 | + |
| 78 | +Useful curl options: |
| 79 | + |
| 80 | + --trace |
| 81 | + --trace-time |
| 82 | + -w, --write-out |
| 83 | + -v, --verbose |
| 84 | + |
| 85 | + |
| 86 | +Accessing the client |
| 87 | +-------------------- |
| 88 | + |
| 89 | +To access the client we can either run a webserver locally or acess |
| 90 | +the files directly from disk. |
| 91 | + |
| 92 | +### Accessing files directly from disk |
| 93 | + |
| 94 | +Simply open `frontend/index.html` in a web browser. Chrome will give |
| 95 | +cross-origin errors when loading non-javascript from disk, so it must |
| 96 | +be run with the `--allow-file-access-from-files` commandline |
| 97 | +argument. Under OS X this can be done with: |
| 98 | + |
| 99 | + open '/Applications/Google Chrome.app' --new --args --allow-file-access-from-files |
| 100 | + |
| 101 | +On Windows this can be done by adding the |
| 102 | +`--allow-file-access-from-files` flag to a special shortcut (edit it |
| 103 | +with right-click and properties -> target). |
| 104 | + |
| 105 | +To disable cross-origin errors in Firefox go to `about:config` and set |
| 106 | +`security.fileuri.strict_origin_policy` to `false`. |
| 107 | + |
| 108 | +### Run a local webserver |
| 109 | + |
| 110 | +Any webserver that can serve up the `frontend` directory tree can be |
| 111 | +used to access the client. One particularly easy way to do this is to |
| 112 | +run `python -m SimpleHTTPServer` in the `frontend` directory, and then |
| 113 | +point the webbrowser to `http://localhost:8000`. |
| 114 | + |
| 115 | + |
| 116 | +Restore of the database |
| 117 | +---------------------------------- |
| 118 | + |
| 119 | +When the DB is stopped: |
| 120 | + |
| 121 | + mongorestore --dbpath ~/db ~/path-to-dump |
| 122 | + |
| 123 | + |
| 124 | +Miscellaneous Notes |
| 125 | +=================== |
| 126 | + |
| 127 | +### Run grunt to check code |
| 128 | + |
| 129 | + $ sudo npm install -g grunt-cli |
| 130 | + $ grunt |
| 131 | + |
| 132 | +### Use `marked` to process markdown |
| 133 | + |
| 134 | + $ sudo npm install -g marked |
| 135 | + $ marked --gfm README.md > README.html |
| 136 | + |
| 137 | + |
| 138 | +Tools and libraries |
| 139 | +=================== |
| 140 | + |
| 141 | +* [Node.js](http://nodejs.org/) |
| 142 | +* [npm](https://npmjs.org/) |
| 143 | +* [MongoDB](http://www.mongodb.org/) |
| 144 | +* [Express](http://expressjs.com/) |
| 145 | +* [jQuery](http://jquery.com/) |
| 146 | +* [Underscore.js](http://underscorejs.org/) |
| 147 | +* [Backbone.js](http://backbonejs.org/) |
| 148 | +* [Bootstrap](http://getbootstrap.com/) |
| 149 | +* [Grunt](http://gruntjs.com/) |
| 150 | +* [async](https://github.com/caolan/async) |
| 151 | +* [JSHint](http://www.jshint.com/) |
| 152 | +* [RequireJS](http://requirejs.org/) |
| 153 | +* [tween.js](https://github.com/sole/tween.js/) |
| 154 | +* [Sylvester](http://sylvester.jcoglan.com/) |
| 155 | +* [MathJax](http://www.mathjax.org/) |
| 156 | +* [Rivets.js](http://rivetsjs.com/) |
| 157 | + |
| 158 | + |
| 159 | +Deploying to a Vagrant virtual machine |
| 160 | +====================================== |
| 161 | + |
| 162 | +Install: |
| 163 | + |
| 164 | +* VirtualBox: http://www.virtualbox.org/ |
| 165 | +* Vagrant: http://www.vagrantup.com/ |
| 166 | + |
| 167 | +In the `PrairieLearn` directory run: |
| 168 | + |
| 169 | + vagrant up # download and boot the VM and install packages |
| 170 | + |
| 171 | +To run the PrairieLearn server do: |
| 172 | + |
| 173 | + vagrant ssh # login to the VM |
| 174 | + cd /vagrant/backend # change to the PrairieLearn backend server directory |
| 175 | + npm install # install libary packages (one time only) |
| 176 | + make # compile latex in figures (only after changing figure latex) |
| 177 | + grunt # check code for syntax and style (optional) |
| 178 | + node server # run the PrairieLearn server |
| 179 | + |
| 180 | +When the server is running, access PrairieLearn in a web browser on |
| 181 | +the host at the URL http://localhost:8080/ |
| 182 | + |
| 183 | +To stop the server and logout of the VM: |
| 184 | + |
| 185 | + ctrl-c # stop the server |
| 186 | + logout # logout of the VM (can also use ctrl-d) |
| 187 | + |
| 188 | +Other useful vagrant commands on the host: |
| 189 | + |
| 190 | + vagrant halt # shutdown the VM |
| 191 | + vagrant destroy # delete the VM completely |
| 192 | + vagrant up # start the VM again (after halt or destroy) |
| 193 | + vagrant suspend # suspend the VM |
| 194 | + vagrant resume # resume a suspended VM |
0 commit comments