-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (34 loc) · 1.1 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
const express = require('express')
const app = express()
const exphbs = require('express-handlebars');
const port = process.env.PORT || 3000
const path = require('path') // research the path native node module
const bodyParser = require('body-parser')
const Email = require('./Email');
app.set('views', path.join(__dirname, 'views'));
app.engine('hbs', exphbs({
defaultLayout: "main",
extname: ".hbs",
helpers: require("handlebars-helpers")(),
layoutsDir: __dirname + '/views/layouts/',
partialsDir: __dirname + '/views/partials/'
}));
app.set('view engine', 'hbs');
app.use(express.static(path.join(__dirname, 'public')));
require('./data/clientbird-comingsoon-db.js');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get('/', (req, res) => {
res.render('index');
});
app.post('/email', (req, res) => {
let email = new Email({email: req.body.email}).save((email) => {
res.render('index', {yay: 'Success!'});
})
})
app.get('/api/emails', (req, res) => {
Email.find({}).then((emails) => {
res.send(emails);
})
})
app.listen(process.env.PORT || port)