-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
79 lines (66 loc) · 1.92 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require('express');
const morgan = require('morgan');
const fs = require('fs');
const app = express();
const PORT = process.env.PORT || 3000;
app.listen(PORT);
console.log(`listening on port ${PORT}`);
app.set('view engine', 'ejs');
app.use( morgan('dev') );
app.use( express.static('public') );
app.use( express.urlencoded({ extended:true }) );
app.get('/', (req, res) => {
res.render('landing', {
title: '🧼 Beauty Animations',
});
});
app.get('/contact', (req, res) => {
res.render('contact', {
title: '💌 Contact Me!',
})
});
app.get('/faq', (req, res) => {
let questions = [];
let answers = [];
const filePath = './public/docs/faq.txt';
// Read Question-Answer txt file;
// questions on odd line, answers on even line
const data = fs.readFileSync(filePath);
if (data === null) {
console.log('error reading file or file is empty.');
}
const stringBlock = data.toString();
const stringSeparated = stringBlock.split('\n');
// Separate questions from answers
for (let i = 1; i <= stringSeparated.length; i++) {
if (i % 2 === 0) {
answers.push(stringSeparated[i - 1]);
} else {
questions.push(stringSeparated[i - 1]);
}
}
res.render('faq', {
title: '🙋 FAQ',
questions,
answers
});
});
app.get('/clientWork', (req, res) => {
const filePath = './public/docs/video.txt';
//Read video.txt file for embedded video links
const data = fs.readFileSync(filePath);
if (data === null) {
console.log('error reading file or file is empty.');
}
const stringBlock = data.toString();
const videos = stringBlock.split('\n');
res.render('clientWork', {
title: '🎞️ Client Work',
videos
});
});
app.use( (req, res) => {
res.status(404).render('404', {
title:'⛔ 404 Not Found'
});
});