Skip to content

Instantly share code, notes, and snippets.

@alextorn
Created October 16, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alextorn/255013f01109407ad8d1e070aa1569eb to your computer and use it in GitHub Desktop.
Save alextorn/255013f01109407ad8d1e070aa1569eb to your computer and use it in GitHub Desktop.
koa-send, react app with react-router
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