-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
113 lines (96 loc) · 2.68 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var express = require('express');
let app = express();
let handlebars = require('express-handlebars').create({defaultLayout:'main'});
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'html');
app.set('port', 4962);
//engine setup
// app.set('views', path.join(__dirname, 'views'));
app.use(express.json());
app.use(express.urlencoded({ extended: false}));
app.use(express.static('public'));
// const indexRouter = require('./routes/index');
// app.use('/', indexRouter);
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 10,
host : 'classmysql.engr.oregonstate.edu',
user : '[crawzach]',
password : '[6352]',
database : '[crawzach]'
});
module.exports.pool = pool;
// Get the home page
app.get('/', function(req, res, next) {
res.render('index')
}) ;
// Get the galaxies page
app.get('/galaxies', function(req, res, next) {
let context = {};
pool.query('SELECT * from galaxies', function(err, rows, fields){
if (err) {
next(err);
return;
}
context.results = JSON.stringify(rows);
res.render('galaxies', context)
})
});
// get the hostSystems page
app.get('/hostSystems', function(req, res, next) {
let context = {};
pool.query('SELECT * FROM hostSystems', function(err, rows, fields){
if (err) {
next(err);
return;
}
context.results = JSON.stringify(rows);
res.render('hostSystems', context)
})
});
// get the stars page
app.get('/stars', function(req, res, next) {
let context = {};
pool.query('SELECT * FROM stars', function(err, rows, fields){
if (err) {
next(err);
return;
}
context.results = JSON.stringify(rows);
res.render('stars', context)
})
});
// get the exoplanets page
app.get('/exoplanets', function(req, res, next) {
let context = {};
pool.query('SELECT * FROM exoplanets', function(err, rows, fields){
if (err) {
next(err);
return;
}
context.results = JSON.stringify(rows);
res.render('exoplanets', context)
})
});
// get the M:M exoplanets:stars table page
app.get('/EPSRelation', function(req, res, next) {
let context = {};
pool.query('SELECT * FROM exoplanetStarRelationShip', function(err, rows, fields){
if (err) {
next(err);
return;
}
context.results = JSON.stringify(rows);
res.render('EPSRelation', context)
})
});
app.use(function(req,res){
res.status(404);
res.render('404');
});
app.use(function(err, req, res, next){
console.error(err.stack);
res.type('plain/text');
res.status(500);
res.render('500');
});