-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (34 loc) · 1.05 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
const express = require('express');
const compression = require('compression');
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
const path = require('path');
const formsubmit = require('./controllers/formsubmit');
const Process = require('process');
const knex = require('knex');
const db = knex({
client: 'pg',
connection: {
connectionString: process.env.DATABASE_URL,
ssl: true,
}
});
const app = express();
app.use(compression());
//BODY PARSER MIDDLEWARE
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
//STATIC FOLDER
app.use('/public', express.static(path.join(__dirname, 'public')))
//SET VIEW ENGINE
app.engine('handlebars', exphbs());
app.set('view engine', 'handlebars');
//ROOT ROUTE
app.get('/', (req, res)=> {
res.render('index');
})
//SEND END POINT
app.post('/formsubmit', (req, res) => {formsubmit.handleFormSubmit(req, res, db)})
app.listen(Process.env.PORT || 3000, () => {
console.log(`Server is running on port..${Process.env.PORT}` );
})