Skip to content
Myr

index.js

This file

Path

examples/content-negotiation/index.js

46 lines · 1003 bytes · JavaScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 2027b87 point at it.

fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87

lines 1–46why, one step back
1'use strict'
23var express = require('../../');4var app = module.exports = express();5var users = require('./db');67// so either you can deal with different types of formatting8// for expected response in index.js9app.get('/', function(req, res){10 res.format({11 html: function(){12 res.send('<ul>' + users.map(function(user){13 return '<li>' + user.name + '</li>';14 }).join('') + '</ul>');15 },1617 text: function(){18 res.send(users.map(function(user){19 return ' - ' + user.name + '\n';20 }).join(''));21 },2223 json: function(){24 res.json(users);25 }26 });27});2829// or you could write a tiny middleware like30// this to add a layer of abstraction31// and make things a bit more declarative:3233function format(path) {34 var obj = require(path);35 return function(req, res){36 res.format(obj);37 };38}3940app.get('/users', format('./users'));4142/* istanbul ignore next */43if (!module.parent) {44 app.listen(3000);45 console.log('Express started on port 3000');46}