Skip to content

Commit ee0f839

Browse files
committed
fix(placards): use test endpoint instead of mock
1 parent 7bcc729 commit ee0f839

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

clients/web/src/pages/api/placards.ts

+13-40
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,26 @@ export interface PlacardData {
2525

2626
export type PlacardResponse = Record<string, PlacardData[]>
2727

28-
const mockData = {
29-
pocket_billboard: [
30-
{
31-
format: 'billboard',
32-
url: 'https://www.mozilla.org/en-US/advertising/',
33-
callbacks: {
34-
click:
35-
'http://localhost:8080/v1/t?data=CksqC2NyYXp5X2VkZGllMiQwMzI2N2FkMS0wMDc0LTRhYTYtOGUwYy1lYzE4ZTA5MDZiZmVyEHBvY2tldF9iaWxsYm9hcmSYAQKoAQQSIIRi0fSX7ChYnwOh8yODK3Qw-MfbNQZ-R3EOhTOD2wXA',
36-
impression:
37-
'http://localhost:8080/v1/t?data=CksqC2NyYXp5X2VkZGllMiQwMzI2N2FkMS0wMDc0LTRhYTYtOGUwYy1lYzE4ZTA5MDZiZmVyEHBvY2tldF9iaWxsYm9hcmSYAQGoAQQSIFoCwqf5lL2L6uM7lFVRh12I2E_FgPQtTgjYhlDvGK1K'
38-
},
39-
image_url: 'https://picsum.photos/seed/0/970/250',
40-
alt_text: 'Ad 1 for mozilla_ads',
41-
block_key: 'CAQSC2NyYXp5X2VkZGll'
42-
},
43-
{
44-
format: 'billboard',
45-
url: 'https://www.mozilla.org/en-US/advertising/',
46-
callbacks: {
47-
click:
48-
'http://localhost:8080/v1/t?data=CksqC2NyYXp5X2VkZGllMiQwMzI2N2FkMS0wMDc0LTRhYTYtOGUwYy1lYzE4ZTA5MDZiZmVyEHBvY2tldF9iaWxsYm9hcmSYAQKoAQQSIIRi0fSX7ChYnwOh8yODK3Qw-MfbNQZ-R3EOhTOD2wXA',
49-
impression:
50-
'http://localhost:8080/v1/t?data=CksqC2NyYXp5X2VkZGllMiQwMzI2N2FkMS0wMDc0LTRhYTYtOGUwYy1lYzE4ZTA5MDZiZmVyEHBvY2tldF9iaWxsYm9hcmSYAQGoAQQSIFoCwqf5lL2L6uM7lFVRh12I2E_FgPQtTgjYhlDvGK1K'
51-
},
52-
image_url: 'https://picsum.photos/seed/1/970/250',
53-
alt_text: 'Ad 2 for mozilla_ads',
54-
block_key: 'CAQSC2NyYXp5X2VkZGll'
55-
}
56-
]
57-
}
58-
5928
export default async function handler(req: NextApiRequest, res: NextApiResponse): Promise<void> {
6029
if (req.method !== 'POST') {
6130
return res.status(405).json({ message: 'Method not allowed' })
6231
}
6332

6433
try {
65-
// const payload = await req.body
66-
67-
// const body = JSON.stringify(payload)
68-
69-
// return fetch('https://ads.mozilla.org/v1/ads', { method: 'POST', body }).then((response) =>
70-
// response.json()
71-
// )
34+
const payload = await req.body
35+
const body = JSON.stringify(payload)
36+
const adResponse = await fetch('https://ads.allizom.org/v1/ads', {
37+
method: 'POST',
38+
headers: { 'Content-Type': 'application/json' },
39+
body
40+
})
41+
42+
if (!adResponse.ok) {
43+
throw new Error(`Failed ad server response: ${adResponse.status}${adResponse.statusText}`)
44+
}
7245

73-
// Returning mock data for now
74-
return res.status(200).json(mockData)
46+
const response = await adResponse.json()
47+
return res.status(200).json(response)
7548
} catch (error) {
7649
if (error instanceof Error) {
7750
res.status(500).json({ message: error.message })

0 commit comments

Comments
 (0)