Adds ip lookup middleware for cart creation
This commit is contained in:
@@ -3,12 +3,19 @@ import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app, container) => {
|
||||
const middlewareService = container.resolve("middlewareService")
|
||||
|
||||
app.use("/carts", route)
|
||||
|
||||
route.get("/:id", middlewares.wrap(require("./get-cart").default))
|
||||
|
||||
route.post("/", middlewares.wrap(require("./create-cart").default))
|
||||
route.post(
|
||||
"/",
|
||||
middlewareService.usePreCartCreation(),
|
||||
middlewares.wrap(require("./create-cart").default)
|
||||
)
|
||||
|
||||
route.post("/:id", middlewares.wrap(require("./update-cart").default))
|
||||
|
||||
// Line items
|
||||
|
||||
@@ -30,7 +30,7 @@ export default (app, container, config) => {
|
||||
customerRoutes(route, container)
|
||||
productRoutes(route)
|
||||
orderRoutes(route)
|
||||
cartRoutes(route)
|
||||
cartRoutes(route, container)
|
||||
shippingOptionRoutes(route)
|
||||
regionRoutes(route)
|
||||
|
||||
|
||||
@@ -109,6 +109,10 @@ function registerMedusaMiddleware(pluginDetails, container) {
|
||||
pluginDetails.options
|
||||
)
|
||||
}
|
||||
|
||||
if (module.preCartCreation) {
|
||||
middlewareService.addPreCartCreation(module.preCartCreation)
|
||||
}
|
||||
}
|
||||
|
||||
function registerCoreRouters(pluginDetails, container) {
|
||||
|
||||
@@ -7,6 +7,7 @@ class MiddlewareService {
|
||||
constructor(container) {
|
||||
this.postAuthentication_ = []
|
||||
this.preAuthentication_ = []
|
||||
this.preCartCreation_ = []
|
||||
this.routers = {}
|
||||
}
|
||||
|
||||
@@ -65,6 +66,17 @@ class MiddlewareService {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a middleware function to be called before cart creation
|
||||
* @param {function} middleware - the middleware function. Should return a
|
||||
* middleware function.
|
||||
* @return {void}
|
||||
*/
|
||||
addPreCartCreation(middleware) {
|
||||
this.validateMiddleware_(middleware)
|
||||
this.preCartCreation_.push(middleware)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds post authentication middleware to an express app.
|
||||
* @param {ExpressApp} app - the express app to add the middleware to
|
||||
@@ -86,6 +98,10 @@ class MiddlewareService {
|
||||
app.use(object.middleware(object.options))
|
||||
}
|
||||
}
|
||||
|
||||
usePreCartCreation() {
|
||||
return this.preCartCreation_
|
||||
}
|
||||
}
|
||||
|
||||
export default MiddlewareService
|
||||
|
||||
Reference in New Issue
Block a user