-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (32 loc) · 1009 Bytes
/
index.js
File metadata and controls
41 lines (32 loc) · 1009 Bytes
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
const express = require('express');
const path = require('path');
const handlebars = require('express-handlebars');
const handlers = require('./src/features/route-handlers');
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const app = express();
const PORT = 3000;
const viewEngine = '.hbs';
app.engine(viewEngine, handlebars({
layoutsDir: __dirname + '/src/pages/',
defaultLayout: 'index',
helpers: require('./src/debug'),
extname: '.hbs'
}));
app.set('view engine', viewEngine);
app.set('views', __dirname + '/src/features/');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(`${__dirname}/src/pages/index.html`);
});
app.get('/search', handlers.searchHandler);
app.get('/artist/:id', handlers.artistHandler);
app.listen(PORT, error => {
if (error) {
console.error(error);
return process.exit(1);
} else {
console.log('Listening on port: ' + PORT + '.');
}
});