This repository has been archived by the owner on Sep 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (63 loc) · 1.85 KB
/
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
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
const DEBUG = true
const PORT = 3004 || process.env.careerPort
const fs = require('fs')
const ejs = require('ejs')
const cors = require('cors')
const path = require('path').resolve()
const chalk = require('chalk')
const express = require('express')
const layout = Object
layoutReload()
const app = express()
app.use(cors())
app.get('/', (_req, res) => {
if (DEBUG) layoutReload()
ejs.renderFile(path + '/page/index.ejs', { layout }, (err, str) => {
if (err) console.log(chalk.bold.red(err))
res.send(str)
})
})
app.get('/job/:path', (req, res) => {
if (DEBUG) layoutReload()
ejs.renderFile(path + '/page/job/' + req.params.path + '.ejs', { layout }, (err, str) => {
if (err) console.log(chalk.bold.red(err))
res.send(str)
})
})
app.get('/src/:type/:path', (req, res) => {
switch (req.params.type) {
case 'js':
fs.readFile(path + '/page/javascript/' + req.params.path, (err, data) => {
if (err) res.sendStatus(500)
else res.send(data)
})
break
case 'css':
fs.readFile(path + '/page/style/' + req.params.path, (err, data) => {
if (err) res.sendStatus(500)
else res.send(data)
})
break
case 'img':
if (fs.existsSync(path + '/page/image/' + req.params.path)) res.sendFile(path + '/page/image/' + req.params.path)
else res.sendStatus(404)
break
default:
res.sendStatus(404)
break
}
})
app.get('/favicon.png', (req, res) => {
res.sendFile(path + '/page/image/favicon.png')
})
app.listen(PORT, () => {
console.log(chalk.bold.blue('Seoa Career Page is now running on http://localhost:' + PORT + '/ !'))
})
function layoutReload () {
fs.readdir(path + '/layout/', (err, files) => {
if (err) console.error(err)
files.forEach((file) => {
layout[file.replace('.html', '')] = fs.readFileSync(path + '/layout/' + file)
})
})
}