From 82e03978b89938219958032efb1448cc76baa181 Mon Sep 17 00:00:00 2001 From: Saumit Date: Sat, 27 Sep 2025 02:14:26 +0530 Subject: Initial snapshot - OpenTelemetry demo 2.1.3 -f --- src/frontend/pages/api/shipping.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/frontend/pages/api/shipping.ts (limited to 'src/frontend/pages/api/shipping.ts') diff --git a/src/frontend/pages/api/shipping.ts b/src/frontend/pages/api/shipping.ts new file mode 100644 index 0000000..3a29001 --- /dev/null +++ b/src/frontend/pages/api/shipping.ts @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +import type { NextApiRequest, NextApiResponse } from 'next'; +import InstrumentationMiddleware from '../../utils/telemetry/InstrumentationMiddleware'; +import ShippingGateway from '../../gateways/http/Shipping.gateway'; +import { Address, CartItem, Empty, Money } from '../../protos/demo'; +import CurrencyGateway from '../../gateways/rpc/Currency.gateway'; + +type TResponse = Money | Empty; + +const handler = async ({ method, query }: NextApiRequest, res: NextApiResponse) => { + switch (method) { + case 'GET': { + const { itemList = '', currencyCode = 'USD', address = '' } = query; + const { costUsd } = await ShippingGateway.getShippingCost(JSON.parse(itemList as string) as CartItem[], + JSON.parse(address as string) as Address); + const cost = await CurrencyGateway.convert(costUsd!, currencyCode as string); + + return res.status(200).json(cost!); + } + + default: { + return res.status(405); + } + } +}; + +export default InstrumentationMiddleware(handler); -- cgit v1.2.3