-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
27 lines (26 loc) · 961 Bytes
/
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
const express = require('express')
const app = express()
const path = require('path')
const port = process.env.PORT || 5000
const engine = require('consolidate');
const compression = require('compression');
// set up router
var router = express.Router();
router.use(express.urlencoded({ extended: true }));
router.use(express.json())
router.use((req, res, next) => { // router middleware
res.header('Access-Control-Allow-Origin', process.env.ORIGIN || '*');
next();
});
// REGISTER ALL ROUTES -------------------------------
// Compress all HTTP responses
app.use(compression());
app.use('/api', router); // all of the routes will be prefixed with /api
app.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.engine('html', engine.mustache)
.set('view engine', 'html')
.get('/', (req, res) => res.render('index.html'))
.listen(port, () => {
console.log(`Example app listening on port ${port}!`)
});