-
Notifications
You must be signed in to change notification settings - Fork 6
/
router.js
161 lines (135 loc) · 4.13 KB
/
router.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const express = require('express');
const router = express.Router();
const {mdTree} = require('./utils');
const _ = require('lodash');
const config = require('config');
const Mailgun = require('mailgun-js');
const docsTree = mdTree('./docs', './views');
const releaseTree = mdTree('./releases', './views');
// Home
router.get('/', function(req, res) {
const t = 'drachtio - the open source SIP application server framework';
const d = 'drachtio - making SIP server apps as easy to build as web apps.';
const k = 'drachtio, SIP, sip, Node.js, nodejs, sofia, drachtio-srf';
res.render('index', {title : t, description : d, keywords: k});
});
// Interior Pages
router.get('/about', function(req, res) {
const t = 'drachtio - about';
const d = 'Learn more about drachtio, the node.js SIP application server framework.';
res.render('about', {title : t, description : d});
});
/*
router.get('/features', function(req, res) {
const t = 'Features - drachtio';
const d = 'Learn more about what drachtio has to offer.';
res.render('features', {title : t, description : d});
});
*/
router.get('/middleware', function(req, res) {
const t = 'drachtio - middleware';
const d = 'drachtio middleware';
res.render('middleware', {title : t, description : d});
});
router.get('/apps', function(req, res) {
const t = 'drachtio - apps';
const d = 'drachtio reference apps';
res.render('apps', {title : t, description : d});
});
router.get('/api', function(req, res) {
const t = 'drachtio API';
const d = 'drachtio API documentation';
res.render('api', {title : t, description : d});
});
// Contact
router.get('/contact', function(req, res) {
const t = 'Contact - drachtio';
const d = 'Have a question? Contact us.';
res.render('contact', {title : t, description : d, submitted: false});
});
router.post('/contact', function(req, res) {
const mailgun = Mailgun(config.get('mailgun'));
const t = 'Contact - drachtio';
const d = 'Have a question? Contact us.';
console.log(req.body);
const data = {
from: req.body.email,
to: config.get('mailgun.to'),
subject: req.body.subject,
html: req.body.message
};
mailgun.messages().send(data, (err, body) => {
if (err) {
res.render('error', { error : err});
console.log(`got an error: ${err}`);
}
else {
res.render('contact', {title : t, description : d, submitted: true});
}
});
});
//
// Releases
router.get('/releases', (req, res) => {
var len = releaseTree.children.length;
var children = JSON.parse(JSON.stringify(releaseTree.children));
var pageSize = 2,
pageCount = len / 2,
currentPage = 1,
currentType = 'drachtio-srf',
data = [];
for (var i = 0; i < children.length; i++) {
data.push([]);
while (children[i].children.length > 0) {
data[i].push(children[i].children.splice(0, pageSize));
}
}
if (typeof req.query.page !== 'undefined') {
currentPage = req.query.page;
}
if (typeof req.query.type !== 'undefined') {
currentType = req.query.type;
}
res.render('releases', {
title : 'drachtio - releases',
description : 'Release notes for drachtio.',
tree: releaseTree.children,
data: data,
pageSize: pageSize,
total: len,
pageCount: pageCount,
currentPage: currentPage,
currentType: currentType
});
});
// Documentation
router.get('/docs', (req, res) => {
res.render('docs', {
title : 'drachtio - docs',
description : 'Documentation for dracht.io, the node.js SIP application server framework.',
tree: docsTree.children,
active: 'developer-guide'
});
});
router.get('/docs/:folder', (req, res) => {
const t = 'drachtio - docs';
const d = 'Documentation for drachtio, the node.js SIP application server framework.';
const tree = _.find(docsTree.children, (c) => c.file === req.params.folder);
if (tree) {
console.log('found folder');
res.render('docs', {
title : t,
description : d,
tree: docsTree.children,
active: req.params.folder
});
} else {
res.render('docs', {
title : t,
description : d,
tree: docsTree.children,
active: 'api'
});
}
});
module.exports = router;