-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
88 lines (60 loc) · 2.12 KB
/
index.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
const express = require("express");
const exphbs = require("express-handlebars");
const bodyParser = require("body-parser"); // add this line
const app = express();
const pg = require("pg");
const Pool = pg.Pool;
const shapes_colours = require("./shapes-and-colours");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: false })); // add this line
app.use(bodyParser.json()); // add this line
app.engine('handlebars', exphbs());
app.set('view engine', 'handlebars');
const connectionString = process.env.DATABASE_URL || 'postgresql://codex-coder:pg123@localhost:5432/shape_it_with_colours';
const pool = new Pool({
connectionString
});
const ShapesAndColors = shapes_colours(pool);
// //setup template handlebars as the template engine
// app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
// app.set('view engine', 'handlebars');
// app.use(express.static(__dirname + '/public'));
// //setup middleware
// // parse application/x-www-form-urlencoded
// app.use(bodyParser.urlencoded({ extended: false }))
// // parse application/json
// app.use(bodyParser.json())
// function errorHandler(err, req, res, next) {
// res.status(500);
// res.render('error', { error: err });
// }
// app.engine('handlebars', exphbs({
// defaultLayout: 'main',
// layoutsDir: "./views/layouts/"
// }));
// app.set('view engine', 'handlebars');
app.use(express.static('public'));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
// app.get('/', function(req, res){
// res.render('index')
// })
app.get('/shapes-and-colours', function(req, res){
res.render('shapes-and-colours')
})
app.post('/shapes-and-colours', function(req, res){
res.render('shapes-and-colours')
})
// app.get('/results', function(req, res){
// res.render()
// })
// app.post('/results', function(req, res){
// res.render()
// })
var portNumber = process.env.PORT || 3002;
//start everything up
app.listen(portNumber, function () {
console.log('shapes and colors example server listening on:', portNumber);
});