Created
October 16, 2017 14:58
-
-
Save alextorn/255013f01109407ad8d1e070aa1569eb to your computer and use it in GitHub Desktop.
koa-send, react app with react-router
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 Koa from 'koa'; | |
import logger from 'koa-logger'; | |
import koaSend from 'koa-send'; | |
import App from 'app/shell/server/App'; | |
function staticMiddleware() { | |
return async function staticMiddlewareHandler(ctx, next) { | |
try { | |
if (ctx.path !== '/') { | |
return await koaSend( | |
ctx, | |
ctx.path, | |
process.env.NODE_ENV === 'production' | |
? { | |
root: 'build', | |
} | |
: { | |
root: PATHS.distDev, | |
}, | |
); | |
} | |
} catch (e) { | |
console.log(e); | |
} | |
return next(); | |
}; | |
} | |
server | |
.use(logger()) | |
.use(staticMiddleware()) | |
.use(async (ctx, next) => { | |
console.log('Run app'); | |
await App(ctx, next); | |
next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment