Skip to content

Commit

Permalink
server: DRY HTML_HEADERS
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jan 15, 2011
1 parent e3ba859 commit d3bbed0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server.js
Expand Up @@ -6,8 +6,9 @@ var template = require('./template');
var MAX_FILE_SIZE = 100 * 1024 * 1024; var MAX_FILE_SIZE = 100 * 1024 * 1024;


function app(app) { function app(app) {
var HTML_HEADERS = { 'Content-Type': 'text/html; charset=UTF-8' };
app.get('/', function(req, res) { app.get('/', function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, HTML_HEADERS);
res.write(template.htmlHead); res.write(template.htmlHead);
res.write(template.uploadForm); res.write(template.uploadForm);
res.write(template.downloadList(files.getFiles())); res.write(template.downloadList(files.getFiles()));
Expand Down Expand Up @@ -57,13 +58,13 @@ function app(app) {
req.on('end', function() { req.on('end', function() {
if (error) { if (error) {
console.error(error.stack); console.error(error.stack);
res.writeHead(400, { 'Content-Type': 'text/html' }); res.writeHead(400, HTML_HEADERS);
res.write(template.htmlHead); res.write(template.htmlHead);
res.write(template.error(error || new Error('No file received'))); res.write(template.error(error || new Error('No file received')));
res.write(template.htmlFoot); res.write(template.htmlFoot);
res.end(); res.end();
} else { } else {
res.writeHead(200, { 'Content-Type': 'text/html' }); res.writeHead(200, HTML_HEADERS);
res.write(template.htmlHead); res.write(template.htmlHead);
res.write(template.thanks); res.write(template.thanks);
res.write(template.htmlFoot); res.write(template.htmlFoot);
Expand Down

0 comments on commit d3bbed0

Please sign in to comment.