Skip to content

Commit

Permalink
todos: read html and css file on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
proppy authored and stephenplusplus committed Oct 15, 2014
1 parent b99319c commit fbd9386
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"body-parser": "^1.4.3",
"gcloud": "^0.6.0",
"markdown": "^0.5.0",
"github-markdown-css": "^1.1.1",
"async": "~0.9.0"
"github-markdown-css": "^1.1.1"
},
"devDependencies": {
"jshint": "^2.5.2",
Expand Down
29 changes: 9 additions & 20 deletions todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var express = require('express'),
bodyParser = require('body-parser'),
fs = require('fs'),
markdown = require('markdown').markdown,
async = require('async');
app = express();

var gcloud = require('gcloud'),
Expand Down Expand Up @@ -130,26 +129,16 @@ app.get('/_ah/health', function(req, res) {
.send('ok');
});

var githubMarkdownCSS = 'node_modules/github-markdown-css/github-markdown.css';
var todosAPIBlueprint = 'todos.apib';
var githubMarkdownCSS = fs.readFileSync('node_modules/github-markdown-css/github-markdown.css').toString();
var todosAPIBlueprint = fs.readFileSync('todos.apib').toString();
app.get('/', function(req, res) {
async.parallel([
function(callback) { fs.readFile(githubMarkdownCSS, callback); },
function(callback) { fs.readFile(todosAPIBlueprint, callback); },
], function(err, results) {
if (err) {
console.error(err);
res.status(500).send(err.message);
return;
}
res.status(200)
.set('Content-Type', 'text/html')
.send('<html><head><style>'+
results[0].toString()+
'</style></head><body class="markdown-body">'+
markdown.toHTML(results[1].toString())+
'</body></html>');
});
res.status(200)
.set('Content-Type', 'text/html')
.send('<html><head><style>'+
githubMarkdownCSS+
'</style></head><body class="markdown-body">'+
markdown.toHTML(todosAPIBlueprint)+
'</body></html>');
});

module.exports = app;

0 comments on commit fbd9386

Please sign in to comment.