Skip to content

Commit 39949dc

Browse files
add dockerfile and clean error logging
1 parent 70857ee commit 39949dc

File tree

5 files changed

+83
-17
lines changed

5 files changed

+83
-17
lines changed

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ services:
4242
env_file:
4343
- .env
4444

45+
prebid-client-server:
46+
build:
47+
context: .
48+
dockerfile: web-integrations/prebid-integrations/client-server/Dockerfile
49+
ports:
50+
- "3052:3052"
51+
container_name: prebid-client-server
52+
env_file:
53+
- .env
54+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:20.11.0-alpine3.18
2+
3+
WORKDIR /usr/src/app
4+
5+
# Copy package files first for better caching
6+
COPY web-integrations/prebid-integrations/client-server/package*.json ./
7+
RUN npm install
8+
9+
# Copy application files
10+
COPY web-integrations/prebid-integrations/client-server/server.js ./
11+
COPY web-integrations/prebid-integrations/client-server/public ./public/
12+
13+
EXPOSE 3052
14+
CMD ["npm", "start"]
15+

web-integrations/prebid-integrations/client-server/README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,45 @@ For the client-side Prebid.js integration example, see [../client-side](../clien
66

77
> **NOTE:** While the server side of this example is implemented in JavaScript using Node.js, it is not a requirement. You can use any technology of your choice and refer to this example for illustration of the functionality that needs to be implemented.
88
9+
## Prerequisites
10+
11+
- **For local testing:** Node.js (version 20.x or later recommended)
12+
- **For Docker:** Docker and Docker Compose installed
13+
- UID2 API credentials (API Key and Client Secret)
14+
- A local UID2 Operator instance **OR** access to the UID2 integration environment
15+
16+
## Run with Docker (Recommended)
17+
18+
### 1. Set Up Environment Variables
19+
20+
Create a `.env` file in the **root of the uid2-examples repository** with the following:
21+
22+
```bash
23+
# UID2 Operator configuration
24+
UID2_BASE_URL=http://localhost:8080
25+
UID2_API_KEY=your-api-key-here
26+
UID2_CLIENT_SECRET=your-client-secret-here
27+
```
28+
29+
**For local operator:** Use `UID2_BASE_URL=http://localhost:8080` and your local operator credentials.
30+
31+
**For integration environment:** Use `UID2_BASE_URL=https://operator-integ.uidapi.com` and your portal credentials.
32+
33+
### 2. Build and Run with Docker Compose
34+
35+
From the **root of the uid2-examples repository**, run:
36+
37+
```bash
38+
docker-compose up prebid-client-server
39+
```
40+
41+
The application will be available at **`http://localhost:3052`**
42+
43+
To stop the container, press `Ctrl+C` or run:
44+
45+
```bash
46+
docker-compose down
47+
```
948

1049
## Run Locally for Testing
1150

@@ -37,7 +76,7 @@ npm start
3776
You should see:
3877

3978
```
40-
UID2 Prebid Client-Server example listening at http://localhost:3005
79+
UID2 Prebid Client-Server example listening at http://localhost:3052
4180
Make sure you have set the following environment variables:
4281
- UID2_API_KEY
4382
- UID2_CLIENT_SECRET
@@ -46,7 +85,7 @@ Make sure you have set the following environment variables:
4685

4786
### 4. Test the Application
4887

49-
1. Open your browser to `http://localhost:3005`
88+
1. Open your browser to `http://localhost:3052`
5089
2. Enter an email address in the input field
5190
3. Click **"Generate UID2"**
5291
4. You should see:
@@ -89,7 +128,8 @@ Refresh the page - the UID2 token should persist (loaded from localStorage) and
89128
| `UID2_BASE_URL` | Yes | The base URL of the UID2 service. For local testing: `http://localhost:8080`. For integration: `https://operator-integ.uidapi.com`. |
90129
| `UID2_API_KEY` | Yes | Your UID2 API key. Must have the GENERATOR role. |
91130
| `UID2_CLIENT_SECRET` | Yes | Your UID2 client secret corresponding to the API key. |
92-
| `PORT` | No | Port for the Express server (default: 3000). Set to 3005 to avoid conflicts with other examples. |
131+
132+
**Note:** This application runs on port **3052** by default.
93133

94134
## How It Works
95135

web-integrations/prebid-integrations/client-server/public/index.html

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
const email = $('#email').val();
9898

9999
if (!email) {
100-
alert('Please enter an email address');
101100
return;
102101
}
103102

@@ -115,18 +114,18 @@
115114

116115
const data = await response.json();
117116

118-
// Check for opt-out (server returns 400 with status: 'optout')
117+
// Check for opt-out (server returns 200 with status: 'optout')
118+
if (data.status === 'optout') {
119+
console.log('UID2 status: optout');
120+
localStorage.setItem(UID2_STORAGE_KEY, JSON.stringify({ status: 'optout' }));
121+
currentIdentity = null;
122+
updateGuiElements();
123+
return;
124+
}
125+
126+
// Check for other errors
119127
if (!response.ok) {
120-
if (data.status === 'optout') {
121-
console.log('User has opted out');
122-
localStorage.setItem(UID2_STORAGE_KEY, JSON.stringify({ status: 'optout' }));
123-
currentIdentity = null;
124-
updateGuiElements();
125-
return;
126-
}
127-
// Other errors
128128
console.error('Token generation failed:', data);
129-
alert('Failed to generate UID2 token: ' + (data.error || 'Unknown error'));
130129
return;
131130
}
132131

@@ -146,7 +145,6 @@
146145

147146
} catch (error) {
148147
console.error('Error calling login endpoint:', error);
149-
alert('Failed to generate UID2 token: ' + error.message);
150148
}
151149
}
152150

web-integrations/prebid-integrations/client-server/server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const express = require('express');
1919
const crypto = require('crypto');
2020

2121
const app = express();
22-
const port = process.env.PORT || 3000;
22+
const port = 3052;
2323

2424
// UID2 API Configuration
2525
// These values should be set via environment variables for security
@@ -178,7 +178,10 @@ app.post('/login', async (req, res) => {
178178
);
179179
const response = decrypt(encryptedResponse.data, uid2ClientSecret, nonce);
180180

181-
if (response.status !== 'success') {
181+
if (response.status === 'optout') {
182+
// Opt-out is a valid state, return 200 with status
183+
res.json({ status: 'optout' });
184+
} else if (response.status !== 'success') {
182185
res.status(400).json({ error: 'Token generation failed', status: response.status });
183186
} else if (typeof response.body !== 'object') {
184187
res.status(400).json({ error: 'Unexpected response format' });

0 commit comments

Comments
 (0)