Skip to content

Commit 9ca589e

Browse files
author
Vitaly Puzrin
committed
babelmark responder + heroku config
1 parent 835dcb3 commit 9ca589e

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Diff for: Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node support/babelmark-responder.js

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"markdown-it": "bin/markdown-it.js"
1717
},
1818
"scripts": {
19-
"test": "make test"
19+
"test": "make test",
20+
"heroku-postbuild": "npm install express"
2021
},
2122
"files": [
2223
"index.js",
@@ -39,6 +40,7 @@
3940
"chai": "^3.4.1",
4041
"coveralls": "~2.11.9",
4142
"eslint": "^3.5.0",
43+
"express": "^4.14.0",
4244
"highlight.js": "^9.2.0",
4345
"istanbul": "^0.4.5",
4446
"jade": "~1.11.0",

Diff for: support/babelmark-responder.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
/* eslint-env es6 */
4+
/* eslint-disable no-console */
5+
'use strict';
6+
7+
const md = require('../')('commonmark');
8+
const app = require('express')();
9+
10+
const version = require('../package.json').version;
11+
12+
const banner = `<!doctype html>
13+
<html lang="en">
14+
<head>
15+
<meta charset="utf-8">
16+
<title>markdown-it responder for babelmark</title>
17+
</head>
18+
<body>
19+
<p><a href="https://github.com/markdown-it/markdown-it" target="_blank">markdown-it</a>
20+
responder for <a href="http://johnmacfarlane.net/babelmark2/" target="_blank">Babelmark2</a></p>
21+
<p>Usage: /?text=...</p>
22+
</body>
23+
</html>
24+
`;
25+
26+
app.set('port', (process.env.PORT || 5000));
27+
28+
app.get('/', function (req, res) {
29+
if (typeof req.query.text === 'string') {
30+
res.json({
31+
name: 'markdown-it',
32+
html: md.render(req.query.text.slice(0, 1000)),
33+
version
34+
});
35+
return;
36+
}
37+
res.setHeader('Content-Type', 'text/html');
38+
res.send(banner);
39+
});
40+
41+
app.listen(app.get('port'), function () {
42+
console.log(`Node app is running on port ${app.get('port')}`);
43+
});

0 commit comments

Comments
 (0)