Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active Aug 16, 2018
Embed
What would you like to do?
import { Router } from 'express';
const router = Router();
router.get('/users', (err, req, res, next) => {
res.json(someshit);
});
router.get('/activities', (err, req, res, next) => {
res.json({message: 'look at all the room we have'});
});
// and so on
export default router;
import http from 'http';
import express from 'express';
import apiRouter from './apiRouter';
import { Router } from 'express';
const app = express();
const httpServer = http.createServer(app);
const router = Router();
router.use('/api', apiRouter);
app.use(router);
app.use( (req, res, next) => {
res.sendFile('index.html', {
root: 'lib/static',
headers: {
'Content-Type': 'text/html'
}
}, error => {
if( error ) {
next( error )
}
})
});
// error handling
if( !production ) {
app.use( (err, req, res, next) => {
console.log(err.stack);
res.status(err.status || 500);
res.json({
errors: {
message: err.message,
error: err
}
});
});
}
app.use( (err, req, res, next) => {
res.status(err.status || 500);
res.json({
errors: {
message: err.message,
error: {}
}
});
});
httpServer.listen( process.env.PORT, _ =>
console.info(`Listening on port ${httpServer.address().port}`)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment