Files
medusa-store/packages/medusa/src/loaders/api.ts
T
Riqwan Thamir a12c28b7d5 feat(medusa,types): add promotion list/get endpoint (#6110)
what:

- adds get promotion endpoint (RESOLVES CORE-1677)
- adds list promotions endpoint (RESOLVES CORE-1676)
- uses new API routes
2024-01-18 16:01:19 +00:00

32 lines
944 B
TypeScript

import { AwilixContainer } from "awilix"
import bodyParser from "body-parser"
import { Express } from "express"
import qs from "qs"
import routes from "../api"
import { ConfigModule } from "../types/global"
type Options = {
app: Express
container: AwilixContainer
configModule: ConfigModule
}
export default async ({ app, container, configModule }: Options) => {
// This is a workaround for the issue described here: https://github.com/expressjs/express/issues/3454
// We parse the url and get the qs to be parsed and override the query prop from the request
app.use(function (req, res, next) {
const parsedUrl = req.url.split("?")
parsedUrl.shift()
const queryParamsStr = parsedUrl.join("?")
if (queryParamsStr) {
req.query = qs.parse(queryParamsStr, { arrayLimit: Infinity })
}
next()
})
app.use(bodyParser.json())
app.use("/", routes(container, configModule.projectConfig))
return app
}