forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from prebid/master
Sync with master
- Loading branch information
Showing
180 changed files
with
9,531 additions
and
2,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// This is an example of a server-side endpoint that is utilizing the Topics API header functionality. | ||
// Note: This test endpoint requires the following to run: node.js, npm, express, cors, body-parser | ||
|
||
const bodyParser = require('body-parser'); | ||
const cors = require('cors'); | ||
const express = require('express'); | ||
|
||
const port = process.env.PORT || 3000; | ||
|
||
const app = express(); | ||
app.use(cors()); | ||
app.use( | ||
bodyParser.urlencoded({ | ||
extended: true, | ||
}) | ||
); | ||
app.use(bodyParser.json()); | ||
app.use(express.static('public')); | ||
app.set('port', port); | ||
|
||
const listener = app.listen(port, () => { | ||
const host = | ||
listener.address().address === '::' | ||
? 'http://localhost' | ||
: 'http://' + listener.address().address; | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`${__filename} is listening on ${host}:${listener.address().port}\n` | ||
); | ||
}); | ||
|
||
app.get('*', (req, res) => { | ||
res.setHeader('Observe-Browsing-Topics', '?1'); | ||
|
||
const resData = { | ||
segment: { | ||
domain: req.hostname, | ||
topics: generateTopicArrayFromHeader(req.headers['sec-browsing-topics']), | ||
bidder: req.query['bidder'], | ||
}, | ||
date: Date.now(), | ||
}; | ||
|
||
res.json(resData); | ||
}); | ||
|
||
const generateTopicArrayFromHeader = (topicString) => { | ||
const result = []; | ||
const topicArray = topicString.split(', '); | ||
if (topicArray.length > 1) { | ||
topicArray.pop(); | ||
topicArray.map((topic) => { | ||
const topicId = topic.split(';')[0]; | ||
const versionsString = topic.split(';')[1].split('=')[1]; | ||
const [config, taxonomy, model] = versionsString.split(':'); | ||
const numTopicsWithSameVersions = topicId | ||
.substring(1, topicId.length - 1) | ||
.split(' '); | ||
|
||
numTopicsWithSameVersions.map((tpId) => { | ||
result.push({ | ||
topic: tpId, | ||
version: versionsString, | ||
configVersion: config, | ||
taxonomyVersion: taxonomy, | ||
modelVersion: model, | ||
}); | ||
}); | ||
}); | ||
} | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.