-
-
Save amandeepmittal/d3879063a45eefd1974d772553a27365 to your computer and use it in GitHub Desktop.
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 express from 'express'; | |
import cookieParser from 'cookie-parser'; | |
import config from './server/config'; | |
// ADD these | |
import userRoutes from './server/routes/user'; | |
import authRoutes from './server/routes/auth'; | |
// DB connection | |
require('./server/config/dbConnection'); | |
const app = express(); | |
// middleware functions | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: true })); | |
app.use(cookieParser()); | |
// ADD routes | |
app.use('/', userRoutes); | |
app.use('/', authRoutes); | |
app.use((err, req, res, next) => { | |
if (err.name === 'UnauthorizedError') { | |
res.status(401).json({ error: err.name + ':' + err.message }); | |
} | |
}); | |
app.listen(config.port, () => { | |
console.log(`🚀 at port ${config.port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment