Created
June 3, 2015 09:37
-
-
Save mattboon/8fe5435b1c49f73ec233 to your computer and use it in GitHub Desktop.
server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Middleware | |
var middleware = require('./middleware/components.js'); | |
app.use(middleware); | |
// Require the core Styleguide | |
var Styleguide = require('../app/node_modules/styleguide/layout'); | |
var styleguideProps = this.props; | |
// Json for all components | |
app.get('/components.json', function(req, res) { | |
res.json(res.locals.components); | |
}); | |
// Core Styleguide route | |
app.get('/styleguide', function(req, res) { | |
// append new props to Styleguide | |
var newProps = { | |
components: res.locals.components | |
}; | |
var reactEl = React.createElement(Styleguide, objectAssign({}, styleguideProps, newProps)); | |
// route rendering | |
res.render('layouts/styleguide.html', { | |
title: 'AZ Medien Styleguide', | |
content: React.renderToString(reactEl) | |
}); | |
}); | |
// All our component routes | |
app.get('/styleguide/component/:component', function(req, res) { | |
var components = res.locals.components; | |
var slug = req.params.component; | |
// append new props to Styleguide | |
var newProps = { | |
components: components, | |
displaying: slug | |
}; | |
var reactEl = React.createElement(Styleguide, objectAssign({}, styleguideProps, newProps)); | |
// route rendering | |
res.render('layouts/styleguide.html', { | |
title: slugToTitle(slug) + ' | AZ Medien Styleguide', | |
content: React.renderToString(reactEl) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment