adds wishlist plugin
This commit is contained in:
@@ -3,8 +3,17 @@ import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default app => {
|
||||
export default (app, container) => {
|
||||
const middlewareService = container.resolve("middlewareService")
|
||||
|
||||
app.use("/customers", route)
|
||||
route.param("id", middlewares.wrap(require("./authorize-customer").default))
|
||||
|
||||
// Inject plugin routes
|
||||
const routers = middlewareService.getRouters("store/customers")
|
||||
for (const router of routers) {
|
||||
route.use("/", router)
|
||||
}
|
||||
|
||||
route.post("/", middlewares.wrap(require("./create-customer").default))
|
||||
|
||||
@@ -21,8 +30,6 @@ export default app => {
|
||||
// Authenticated endpoints
|
||||
route.use(middlewares.authenticate())
|
||||
|
||||
route.param("id", middlewares.wrap(require("./authorize-customer").default))
|
||||
|
||||
route.get("/:id", middlewares.wrap(require("./get-customer").default))
|
||||
route.post("/:id", middlewares.wrap(require("./update-customer").default))
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export default (app, container, config) => {
|
||||
route.use(middlewares.authenticateCustomer())
|
||||
|
||||
authRoutes(route)
|
||||
customerRoutes(route)
|
||||
customerRoutes(route, container)
|
||||
productRoutes(route)
|
||||
orderRoutes(route)
|
||||
cartRoutes(route)
|
||||
|
||||
@@ -52,6 +52,7 @@ export default ({ rootDirectory, container, app }) => {
|
||||
registerServices(pluginDetails, container)
|
||||
registerMedusaApi(pluginDetails, container)
|
||||
registerApi(pluginDetails, app)
|
||||
registerCoreRouters(pluginDetails, container)
|
||||
registerSubscribers(pluginDetails, container)
|
||||
})
|
||||
}
|
||||
@@ -84,6 +85,29 @@ function registerMedusaMiddleware(pluginDetails, container) {
|
||||
}
|
||||
}
|
||||
|
||||
function registerCoreRouters(pluginDetails, container) {
|
||||
const middlewareService = container.resolve("middlewareService")
|
||||
const { resolve } = pluginDetails
|
||||
const adminFiles = glob.sync(`${resolve}/api/admin/[!__]*.js`, {})
|
||||
const storeFiles = glob.sync(`${resolve}/api/store/[!__]*.js`, {})
|
||||
|
||||
adminFiles.forEach(fn => {
|
||||
const descriptor = fn.split(".")[0]
|
||||
const splat = descriptor.split("/")
|
||||
const path = `${splat[splat.length - 2]}/${splat[splat.length - 1]}`
|
||||
const loaded = require(fn).default
|
||||
middlewareService.addRouter(path, loaded())
|
||||
})
|
||||
|
||||
storeFiles.forEach(fn => {
|
||||
const descriptor = fn.split(".")[0]
|
||||
const splat = descriptor.split("/")
|
||||
const path = `${splat[splat.length - 2]}/${splat[splat.length - 1]}`
|
||||
const loaded = require(fn).default
|
||||
middlewareService.addRouter(path, loaded())
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the plugin's api routes.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,17 @@ class MiddlewareService {
|
||||
constructor(container) {
|
||||
this.postAuthentication_ = []
|
||||
this.preAuthentication_ = []
|
||||
this.routers = {}
|
||||
}
|
||||
|
||||
addRouter(path, router) {
|
||||
const existing = this.routers[path] || []
|
||||
this.routers[path] = [...existing, router]
|
||||
}
|
||||
|
||||
getRouters(path) {
|
||||
const routers = this.routers[path] || []
|
||||
return routers
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user