-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
52 lines (43 loc) · 1.52 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var fs = require('fs');
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
var app = module.exports.app = exports.app = express();
var cheerio = require('cheerio');
var request = require('request');
var cookieParser = require('cookie-parser');
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGOLAB_URI, function (err) {
if(err){
console.log(err);
} else {
console.log('mongo connected');
}
});
app.use(cookieParser());
app.use('/', express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.all('/api/*', [require('./helpers/validateRequest')]);
app.use('/', require('./routes'));
//app.post('/grades', require('./routes/grades'));
//app.post('/schedule', require('./routes/schedule'));
var home = [ '<html>',
'<head><title>CETYS API</title></head>',
'<body>',
'<h1>API para micampus de CETYS</h1>',
'<br /><h3>Requests validos:</h3>',
'<h4>/grades</h4> Regresa JSON con las calificaciones',
'<h4>/schedule</h4> Regresa JSON con los horarios',
'<br /><br />Para utilizar simplemente mandar HTTP Request de POST con los parametros:<br />',
'<strong>user</strong> :m0xxxxxxx<br />',
'<strong>password</strong> :clave de micampus',
'</body></html>'].join('');
app.get('/', function(req, res){
res.send(home);
});
app.get('*', function(req, res){
res.send('404');
});
app.listen(process.env.PORT || 3000);
console.log('Server started: http://localhost:3000/ or at heroku');