forked from mzenzie/320MusicLessonPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·88 lines (61 loc) · 3.41 KB
/
app.js
File metadata and controls
executable file
·88 lines (61 loc) · 3.41 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Modules ==================================================
var database = require("./database/dbinit.js");
var express = require("express");
var jwt = require("express-jwt");
var app = express();
var bodyParser = require("body-parser");
var dbConnector = require('./database/dbinit.js');
var logger = require('morgan'); // HTTP Req/Res Logger (not Morgan Freeman)
var multer = require('multer'); // Parsing multi-part/form data
var format = require("string-format"); //allows formating of string
var secret = require('./server/config/secret.js');
// controllers
var studentRecordController = require('./server/controller/student-record-controller');
var authenticationController = require('./server/controller/authentication-controller');
var lessonScheduleController = require('./server/controller/lesson-schedule-controller');
var teacherController = require('./server/controller/teacher-controller');
// Configuration ============================================
var port = process.env.PORT || 8000;
var development = process.env.DEV || false;
format.extend(String.prototype); //allows usage of String.format(arg1, arg2), i.e. "Hello {0}".format(name); -> "Hello "
// Middleware registration
app.use(bodyParser());
app.use(logger('dev'));
app.use(multer());
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
})
// Set the static files location (This is so the app will be able to find images, html, and javascript files)
// ............Refactored to use the entire 'client' folder.
app.use(express.static(__dirname + "/"));
if (development) dbConnector.init('./test.sql');
else dbConnector.init();
// var db = dbConnector.getInstance();
// var studentRecordController = require(__dirname+"/server/controller/student-record-controller.js");
// authenticationController.startRedisServer(); //uncomment when authen completes.
// Routes ======================================================
/* For Angular people, use these routes to make requests, i.e. $resource('/api/studentRecord/:sid/lessonSchedule')
or use the lower level http service $http.get('/api/studentRecord/:sid/lessonSchedule/:lsid', callback...) etc etc etc.
*/
//ACCOUNT
app.post('/api/signout', jwt({ secret: secret.secretToken }),authenticationController.signout);
app.post('/api/signin', authenticationController.signin);
app.post('/api/signup', authenticationController.signup);
// STUDENT RECORD
app.post("/api/studentRecord/", studentRecordController.create);
app.get("/api/studentRecord/", studentRecordController.get);
app.delete("/api/studentRecord/", studentRecordController.delete);
app.put("/api/studentRecord/", studentRecordController.update);
// LESSON SCHEDULE
app.get('/api/studentRecord/:sid/lessonSchedule/', lessonScheduleController.list);
app.get('/api/studentRecord/:sid/lessonSchedule/:lsid', lessonScheduleController.get);
app.post('/api/studentRecord/:sid/lessonSchedule/', lessonScheduleController.create);
app.delete('/api/studentRecord/:sid/lessonSchedule/:lsid', lessonScheduleController.delete);
app.put('/api/studentRecord/:sid/lessonSchedule/:lsid', lessonScheduleController.update);
//TEACHER
app.get('/api/teacher/', teacherController.get);
app.get('/api/teacher/:id', teacherController.get); // testing
// console.log([1]);
// Start app ==================================================
app.listen(port);
console.log("Server at port={0}".format(port));