/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.send('welcome');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	// Call an undefined function
	error();
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	// Set the status
	res.status(404);
	// Specify the body
	res.send('forced 404');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.status(500);
	res.send('forced 500');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	// Status and body in one line
	res.status(404).send('not found');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.send('welcome');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.send(404);
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.send(404, 'not found');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.status(404);
	res.render('index', {title: 'Express'});
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.status(404).render('index', {title: 'Express'});
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	// status is optional, it defaults to 200
	res.status(200);
	res.set('Content-Type', 'text/plain; charset=us-ascii');
	res.set('X-Secret-Message', 'not really secret');
	res.set('X-Test', 'OK');
	res.send('welcome');
}); 

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.set({
		'Content-Type': 'text/plain; charset=us-ascii',
		'X-Secret-Message': 'not really secret',
		'X-Test': 'OK'
	});
	res.send('welcome');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.charset = 'us-ascii';
	res.send('welcome');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.send('<h1>welcome</h1>');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.set('Content-Type', 'text/plain');
	res.send('<h1>welcome</h1>');
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.send('<h1>welcome</h1>');
});

/* ----------------------------------------------------------------- */

app.use(express.static('./public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

app.get('/', function(req, res) {
	res.render('index', {title:'Express'});
});

/* ----------------------------------------------------------------- */

app.use(express.static('./public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

// HTML should be prettified
app.locals.pretty = true;

app.get('/', function(req, res) {
	res.render('index', {title:'Express'});
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.json({message: 'welcome'});
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	res.jsonp({message: 'welcome'});
});

/* ----------------------------------------------------------------- */

// Use the static middleware to set up a static files directory
app.use(express.static('./files'));

/* ----------------------------------------------------------------- */

app.get('/file', function(req, res) {
	res.sendfile('./secret-file.png', function(err) {
		if (err) { condole.log(err); }
		else { console.log('file sent'); }
	});
});

/* ----------------------------------------------------------------- */

app.get('/file.html', function(req, res) {
	console.log('HTML file is an image?');
	res.sendfile('./secret-file.png');
});

/* ----------------------------------------------------------------- */

app.get('/download', function(req, res) {
	res.download('./secret-file.png', 'open-secret.png', function(err) {
		if (err) { condole.log(err); }
		else { console.log('file downloaded'); }
	});
});

/* ----------------------------------------------------------------- */

// 404 error
res.send(404);

/* ----------------------------------------------------------------- */

// 404 with additional message body
res.send(404, 'File not Found');

/* ----------------------------------------------------------------- */

app.use(function(req, res) {
	res.status(400);
	res.render('404.jade',
		{
			title: '404',
			message: 'File Not Found'
		}
	);
});

/* ----------------------------------------------------------------- */

doctype 5
html
	head
		title #{title}
	body
		h1 #{title}
		p #{message}

/* ----------------------------------------------------------------- */

app.use(function(error, req, res, next) {
	res.status(500);
	res.render('500.jade',
		{
			title: '500',
			error: error
		}
	);
});

/* ----------------------------------------------------------------- */

doctype 5
html
	head
		title #{title}
	body
		h1 #{title}
		p #{error}

/* ----------------------------------------------------------------- */

app.get('/error', function(req, res) {
	// Call an undefined function
	error();
});

/* ----------------------------------------------------------------- */

app.get('/', function(req, res) {
	
	res.format({
		
		'text/plain': function() {
			res.send('welcome');
		},
	
		'text/html': function() {
			res.send('<b>welcome</b>');
		},
	
		'application/json': function() {
			res.json({ message: 'welcome' });
		},
		
		'default': function() {
			res.send(406, 'Not Acceptable');
		}
	});

});

/* ----------------------------------------------------------------- */

res.format({
	
	text: function() {
		res.send('welcome');
	},

	html: function() {
		res.send('<b>welcome</b>');
	},

	json: function() {
		res.json({ message: 'welcome' });
	},
	
	default: function() {
		res.send(406, 'Not Acceptable');
	}
});

/* ----------------------------------------------------------------- */

res.redirect('/notice');
res.redirect(301, '/help-docs');
res.redirect('http://nodejs.org/api/');
res.redirect('../images');

