UNPKG

570 BJavaScriptView Raw
1module.exports = ({
2 Shippo,
3 router,
4 asyncMiddleware,
5 getConfig,
6 handleResponse,
7 handleError,
8}) => {
9
10 router.all(
11 '/shippo/quote.:ext?',
12 asyncMiddleware(async (req, res) => {
13 const shippo = Shippo(await getConfig());
14
15 const address = req.body.address || JSON.parse(req.params.address);
16 const parcel = req.body.parcel || JSON.parse(req.params.parcel);
17
18 try {
19 handleResponse(req, res, await shippo.getQuote(address, parcel), true);
20 } catch (error) {
21 handleError(req, res, error);
22 }
23 })
24 );
25
26};