Adds Middleware API (#40)
* Adds test project * Adds e2e for end-2-end tests * Update gitignore * Update loaders * Creates test project * v0.1.27 * Upgrade * dependency fixes * Load project plugins in the plugin loader * Issue with instanceof * Fixes versioning issues * Adds medusa middleware api * Adds documentation * Fixes tests
This commit is contained in:
@@ -4,11 +4,11 @@ import store from "./routes/store"
|
||||
import errorHandler from "./middlewares/error-handler"
|
||||
|
||||
// guaranteed to get dependencies
|
||||
export default () => {
|
||||
export default container => {
|
||||
const app = Router()
|
||||
|
||||
admin(app)
|
||||
store(app)
|
||||
admin(app, container)
|
||||
store(app, container)
|
||||
|
||||
app.use(errorHandler())
|
||||
|
||||
|
||||
@@ -11,15 +11,23 @@ import discountRoutes from "./discounts"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app, container) => {
|
||||
const middlewareService = container.resolve("middlewareService")
|
||||
|
||||
app.use("/admin", route)
|
||||
|
||||
// Unauthenticated routes
|
||||
authRoutes(route)
|
||||
|
||||
// Calls all middleware that has been registered to run before authentication.
|
||||
middlewareService.usePreAuthentication(app)
|
||||
|
||||
// Authenticated routes
|
||||
route.use(middlewares.authenticate())
|
||||
|
||||
// Calls all middleware that has been registered to run after authentication.
|
||||
middlewareService.usePostAuthentication(app)
|
||||
|
||||
productRoutes(route)
|
||||
userRoutes(route)
|
||||
regionRoutes(route)
|
||||
|
||||
Reference in New Issue
Block a user