var path = require('path');
var url = require('url');

var compression = require('compression');
var express = require('express');

var ssr = require('../index');
var xhr = require('./xhr');
var proxy = require('./proxy');

module.exports = function (config) {
	var app = express()
		.use(compression())
		.use(xhr());

	var pkgPath = path.join(config.path, 'package.json');
	var pkg = require(pkgPath);
	var render = ssr({
		config: pkgPath + '!npm',
		main: pkg.main
	});


	if (config.configure) {
		config.configure(app);
	}

	if (config.proxy) {
		var apiPath = config.proxyTo || '/api';
		app.use(apiPath, proxy(config.proxy));
	}

	app.use(express.static(path.join(config.path)));

	app.use("/", function (req, res) {
		const pathname = url.parse(req.url).pathname;

		render(pathname).then(res.send.bind(res));
	});

	return app;
};

@@ -215,16 +215,49 @@
 proxy');
+%0Avar doctype = '%3C!DOCTYPE html%3E';
 %0A%0Amodule
@@ -757,13 +757,11 @@
 %7B%0A%09%09
-const
+var
  pat
@@ -826,26 +826,98 @@
 hen(
-res.send.bind(res)
+function(html) %7B%0A%09%09%09var dt = config.doctype %7C%7C doctype;%0A%09%09%09res.send(dt + '%5Cn' + html);%0A%09%09%7D
 );%0A%09

Add HTML5 doctype to all rendered pages.