-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (34 loc) · 1.31 KB
/
server.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
/* Require modules
--------------------------------------------------------------- */
require('dotenv').config()
const path = require('path');
const express = require('express');
/* Require the db connection, models, and seed data
--------------------------------------------------------------- */
const db = require('./models');
const carsCtrl = require('./controllers/cars')
/* Create the Express app
--------------------------------------------------------------- */
const app = express();
/* Configure the app (app.set)
--------------------------------------------------------------- */
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
/* Middleware (app.use)
--------------------------------------------------------------- */
app.use(express.static('public'))
/* Mount routes
--------------------------------------------------------------- */
app.get('/', function (req, res) {
db.car.getCars(db.sql)
.then(cars => {res.render('home', {cars: cars})})
});
app.get('/about', function (req, res) {
res.render('about')
})
app.use('/cars', carsCtrl)
/* Tell the app to listen on the specified port
--------------------------------------------------------------- */
app.listen(process.env.PORT, function () {
console.log('Express is listening to port', process.env.PORT);
});