Browse Source

Move code that needs to run only once.

controller/index.js
	-Move all of the index page HTML "initialization" code that only
	needs to run once, like markdown compilation and `style`
	prepending, out of the request handler.
pull/108/head
Severyn Kozak 10 years ago
parent
commit
29838e5b8c
  1. 7
      controller/index.js

7
controller/index.js

@ -5,16 +5,15 @@ var fs = require('fs');
function setup(){ function setup(){
var styleString = '<style>html{font-family:monospace}</style>';
var text = '# Pelias API\n'; var text = '# Pelias API\n';
text += '### Version: ['+ pkg.version+ '](https://github.com/pelias/api/releases)\n'; text += '### Version: ['+ pkg.version+ '](https://github.com/pelias/api/releases)\n';
text += fs.readFileSync( './DOCS.md', 'utf8'); text += fs.readFileSync( './DOCS.md', 'utf8');
var indexHtml = styleString + markdown.toHTML(text);
function controller( req, res, next ) { function controller( req, res, next ) {
if (req.accepts('html')) { if (req.accepts('html')) {
if( text ) { res.send(indexHtml);
var style = '<style>html{font-family:monospace}</style>';
res.send(style + markdown.toHTML(text));
}
return; return;
} }
// default behaviour // default behaviour

Loading…
Cancel
Save