Created
October 29, 2018 11:26
-
-
Save viral-sh/4f7162819df26e9c8c19fa5ccf77608f to your computer and use it in GitHub Desktop.
Express Real world app
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
const express = require('express') | |
// ...all imports & requires here | |
const app = express() | |
const PORT = 3000 | |
// add middlewares | |
app.use(helmet()) | |
app.use(compression()) | |
app.use(bodyParser.urlencoded({ extended: false })) | |
app.use(bodyParser.json()) | |
app.use(cors()) | |
app.use(fileUpload()) | |
// add router middlewares | |
protectedRouter.use(authMiddleware()) | |
adminRouter.use(adminMiddleware()) | |
// add routers | |
app.use('/', publicRouter) | |
app.use('/protected', protectedRouter) | |
app.use('/admin', adminRouter) | |
// register APIs | |
registerApis(publicRouter, protectedRouter, adminRouter) | |
// add error handlers | |
app.use(errorHandler404) | |
app.use(notifyErrorHandler) | |
app.use(globalErrorHandler) | |
app.listen(port, () => console.log(`Realworld app listening on port ${port}!`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Above, in 'add routers' part, don't you have to use callback functions as
publicRouter()
,protectedRouter()
andadminRouter()
? Some documentations recommend that way.