-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (62 loc) · 1.77 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
const config = require('./config');
const express = require('express');
const ghost = require('ghost');
const path = require('path');
const PORT = process.env.PORT || process.argv[2] || 5000;
const API = require('./api');
const bodyParser = require('body-parser');
const Redis = require('ioredis');
const ghostUtils = require('./node_modules/ghost/core/server/utils');
let app = express();
let redis = new Redis({
hostname: config.REDIS_HOST,
port: config.REDIS_PORT,
password: config.REDIS_PASS
});
app.use(express.static(__dirname + "/public"));
app.use(express.static(__dirname + "/content"));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.get('/portfolio', (req, res) => {
res.sendFile(path.resolve(__dirname, './views/portfolio.html'));
})
app.get('/art', (req, res) => {
res.sendFile(path.resolve(__dirname, './views/art.html'));
})
app.get('/art/*', (req, res) => {
res.sendFile(path.resolve(__dirname, './views/art.html'));
})
app.get('/newsletter/:uuid', (req, res) => {
redis.hget('newsletters', req.params.uuid)
.then(result => {
if(result) {
res.send(result);
}
else {
res.status(404).send(`Sorry, we can't find what you are looking for`);
}
})
})
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, './views/home.html'));
})
app.use('/api', API);
ghost()
.then(ghostServer => {
app.use(ghostUtils.url.getSubdir(), ghostServer.rootApp);
ghostServer.start(app);
})
.catch(err => {
console.error(err);
})
if(process.env.NODE_ENV == "production"){
app.listen(PORT, process.env.PROD_IP, () => {
console.log('Connected on Production');
console.log('PORT: ', PORT);
})
}
else{
app.listen(PORT, () => {
console.log('Connected on Dev');
})
}