Browse Source

babelmark responder + heroku config

pull/312/head
Vitaly Puzrin 8 years ago
parent
commit
9ca589e2f1
  1. 1
      Procfile
  2. 4
      package.json
  3. 43
      support/babelmark-responder.js

1
Procfile

@ -0,0 +1 @@
web: node support/babelmark-responder.js

4
package.json

@ -16,7 +16,8 @@
"markdown-it": "bin/markdown-it.js" "markdown-it": "bin/markdown-it.js"
}, },
"scripts": { "scripts": {
"test": "make test" "test": "make test",
"heroku-postbuild": "npm install express"
}, },
"files": [ "files": [
"index.js", "index.js",
@ -39,6 +40,7 @@
"chai": "^3.4.1", "chai": "^3.4.1",
"coveralls": "~2.11.9", "coveralls": "~2.11.9",
"eslint": "^3.5.0", "eslint": "^3.5.0",
"express": "^4.14.0",
"highlight.js": "^9.2.0", "highlight.js": "^9.2.0",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"jade": "~1.11.0", "jade": "~1.11.0",

43
support/babelmark-responder.js

@ -0,0 +1,43 @@
#!/usr/bin/env node
/* eslint-env es6 */
/* eslint-disable no-console */
'use strict';
const md = require('../')('commonmark');
const app = require('express')();
const version = require('../package.json').version;
const banner = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>markdown-it responder for babelmark</title>
</head>
<body>
<p><a href="https://github.com/markdown-it/markdown-it" target="_blank">markdown-it</a>
responder for <a href="http://johnmacfarlane.net/babelmark2/" target="_blank">Babelmark2</a></p>
<p>Usage: /?text=...</p>
</body>
</html>
`;
app.set('port', (process.env.PORT || 5000));
app.get('/', function (req, res) {
if (typeof req.query.text === 'string') {
res.json({
name: 'markdown-it',
html: md.render(req.query.text.slice(0, 1000)),
version
});
return;
}
res.setHeader('Content-Type', 'text/html');
res.send(banner);
});
app.listen(app.get('port'), function () {
console.log(`Node app is running on port ${app.get('port')}`);
});
Loading…
Cancel
Save