forked from anqi-lu/elevate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
51 lines (41 loc) · 1.44 KB
/
loader.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
'use strict';
const bodyParser = require('body-parser');
const showdown = require('showdown');
const converter = new showdown.Converter();
const app = require('./app');
const fs = require('fs');
const path = require('path');
const express = require('express');
const config = fs.existsSync(path.join(__dirname, 'config.json')) ? require('./config') : {};
const mongoose = require('mongoose');
const bluebird = require('bluebird');
const messengerController = require('./controllers/messenger.controller');
Object.assign(process.env, config);
mongoose.connect(process.env.MONGO_URI, {
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASS,
promiseLibrary: bluebird,
useMongoClient: true
});
app.set('port', process.env.PORT);
app.use(bodyParser.json());
module.exports = app;
new messengerController(app);
app.get('/*.md', function (req, res) {
const filename_parts = req.url.split('/');
console.log('filename_partrs', filename_parts);
const path_parts = [__dirname, 'public'].concat(filename_parts);
fs.readFile(path.join.apply(this, path_parts), 'utf-8', function (err, data) {
if (err) {
return res.status(500).send(err);
}
res.send(converter.makeHtml(data));
})
});
app.use(express.static('public'));
app.listen(process.env.PORT, () => {
console.log("loaded");
})
// Start server
// Webhooks must be available via SSL with a certificate signed by a valid
// certificate authority.