Created
May 10, 2016 16:12
-
-
Save matthiasak/4a96ef8bf7a6f8b6cf4a260e88f9b2c6 to your computer and use it in GitHub Desktop.
react-iso.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
import polyfill from "babel-polyfill" | |
const cluster = require('cluster') | |
import _router from 'koa-router' | |
const router = _router() | |
// middleware | |
import stat from 'koa-serve-static' | |
import conditional from 'koa-conditional-get' | |
import bodyParser from 'koa-bodyparser' | |
import Compress from 'koa-compress' | |
import Morgan from 'koa-morgan' | |
import favicon from 'koa-favicon' | |
import session from 'koa-session' | |
// adapt pre Koa 2.0 middle ware to be compatible with Koa 2.0. | |
import adapt from 'koa-convert' | |
import etag from 'koa-etag' | |
import Koa from 'koa' | |
import request from 'request' | |
import passport from 'koa-passport' | |
export const app = new Koa() | |
const logger = Morgan('combined') | |
import rt from 'koa-response-time' | |
//-- app.use(adapt(favicon(require.resolve('./dist/favicon.ico')))) | |
app.use(adapt(rt())) | |
app.use(adapt(conditional())) | |
app.use(adapt(etag())) | |
app.use(logger) | |
app.use(adapt(Compress({ flush: require('zlib').Z_SYNC_FLUSH }))) | |
app.keys = [ Array(4).fill(true).map(x => Math.random()+'').join('') ] | |
app.use(adapt(session({ maxAge: 24 * 60 * 60 * 1000 }, app))) | |
app.use(adapt(bodyParser())) | |
// router.get('/students/:id', ctx => { | |
// console.log(ctx.params.id) | |
// ctx.body = { name:'test', id: id } | |
// }) | |
import React from 'react' | |
import Server from 'react-dom/server' | |
import StudentPage from './components/page.student/js' | |
router.get('/students/:id', (ctx, next) => { | |
ct.body = Server.renderToString(<StudentPage student_id={id} />) | |
}) | |
app.use(router.routes()) | |
app.use(router.allowedMethods()) | |
app.use(stat('dist')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment