Skip to content
This repository was archived by the owner on Aug 10, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Welcome to courses-backend, an express server setup to deliver information on Georgia Tech courses.

To run the server, navigate to the root directory of the application in the cli and run the command `node app.js`. It is configured to run locally on port number 3000.
To run the server, navigate to the root directory of the application in the cli and run the command `node app.js`. It is configured to run locally on port number 8080.

## Using the routes

Expand All @@ -24,10 +24,33 @@ For accessing a specific course:

For example, `/api/course/ACCT/2101`

### Database Query

This app uses `mongodb` as its database type. The app assumes that the database has a collection called `courses` which contains documents of the following structure:
```json
{
"subject": "ACCT",
"number": "2101",
"description": "Short description.",
"name": "Accounting I"
}
```


To access this data from the database, use the same queries used for the static info, with the following change to the route:

<pre>
/api/<b>db</b>/course/...
</pre>


For example, `api/db/course/ACCT/2101`


### Course Critique Query

There is also a route that queries the [coursecritique](https://critique.gatech.edu/) website:

`/api/coursecritique/:id`

For example `/api/coursecritique/ACCT2101`.
For example `/api/coursecritique/ACCT2101`.
29 changes: 19 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var assert = require('assert');
var monk = require('monk');
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
var app = module.exports = express();


var routes = require('./routes/index');
var port = process.env.PORT || '3000';

var app = express();
// middleware setup

// view setup
//other middleware setup
// set up mongodb
var uri = "mongodb://test:[email protected]:45464/courses-backend";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be done as configuration either as an env variable or in a file that isn't committed. Note that there are bots that watch github for this kind of thing in order to hijack accounts.

var db = monk(uri);
app.db = db;
//console.log(courses);

// other middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname + '/views')));

//route setup
var routes = require('./routes/index');
app.use('/', routes);

// error handler
Expand All @@ -24,10 +34,9 @@ app.use(function(err, req, res, next) {
res.send(err);
});

app.listen(port, function(success, failure) {
console.log('server is running on port ' + port);
}).on('error', function(err) {
console.log(err)
//start the server
app.listen(server_port, server_ip_address, function(){
console.log("Listening on server_port " + server_port)
});

module.exports = app;
//module.exports = app;
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
"name": "courses-backend",
"version": "0.0.0",
"scripts": {},
"engines": {
"node": ">= 0.6.0",
"npm": ">= 1.0.0"
},
"dependencies": {
"assert": "^1.3.0",
"body-parser": "~1.13.2",
"cheerio": "^0.19.0",
"debug": "~2.2.0",
"express": "~4.13.1",
"mongodb": "^2.0.49",
"monk": "^1.0.1",
"q": "^1.4.1",
"request": "^2.65.0"
}
},
"main": "app.js"
}
Loading