-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (26 loc) · 988 Bytes
/
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
const express = require('express')
const path = require('path')
const dbPath = path.join(__dirname, '/data/widly_db_16395.json');
global.widly_db = dbPath
const webRoute = require('./routes/web');
const apiRoute = require('./routes/api');
const app = express();
// Set a view engine for the app
app.set('view engine', 'pug');
// Set the public folder as a static folder
app.use('/css', express.static('public/css'))
app.use('/images', express.static('public/images'))
app.use('/js', express.static('public/js'))
// Set the body parser for the app
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Set the routes for the app
app.use('/api', apiRoute);
app.use('/', webRoute);
// Set a 404 page and redirect to homepage
app.use((req, res) => {
res.redirect('/');
});
// Set the port for the app
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server running on http://localhost:${port}`));