Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Optimera network call to use https #3580

Closed
mcallari opened this issue Feb 22, 2019 · 4 comments
Closed

Update Optimera network call to use https #3580

mcallari opened this issue Feb 22, 2019 · 4 comments
Labels

Comments

@mcallari
Copy link
Contributor

Type of issue

Bug

Description

Update network request to use https.

mcallari added a commit to optimera-nyc/Prebid.js that referenced this issue Feb 22, 2019
@betancourtl
Copy link
Contributor

betancourtl commented Feb 22, 2019

If anyone builds prebid manually you can add this script to your package.json to fix the url during the build process.

package.json

  "scripts": {
    "build": "./scripts/build.sh && node ./scripts/fix-optimera.js",
    "prebid:upgrade": "npm upgrade prebid.js && npm run build"
  },

build.sh

#!/usr/bin/env bash
rm ./dist/prebid.js
cd ./node_modules/prebid.js
npm install
# Check if prebid-modules.json files exist.
if [ -f "../../modules.json" ];
    then
    gulp build --modules=../../modules.json
    echo "modules.json file found.";
else
    gulp build
    echo "modules.json file does not exist. Create one to bundle certain modules only.";
fi
# Check if output directory exists.
if [ -d "../../dist" ];
    then
    echo "dist/ directory exists.";
else
    mkdir "../../dist";
    echo "Directory does not exist, creating destination directory.";
fi
# copy the build into the root directory
cp ./build/dist/prebid.js ../../dist/prebid.js

fix-optimera.js

const fs = require('fs');
const path = require('path');

const prebidFilePath = path.join(__dirname, '../', 'dist', 'prebid.js');
const srcPath = prebidFilePath;
const destPath = prebidFilePath;
const regex = /http:\/\/dyv1bugovvq1g\.cloudfront\.net/;
const replacement = 'https://dyv1bugovvq1g.cloudfront.net'

const replaceOptimeraURL = () => new Promise((resolve, reject) => {
  fs.readFile(srcPath, { encoding: 'utf8' }, (err, data) => {
    if (err) return reject(err);
    if (!regex.test(data)) return reject('Optimera url not found.');
    return resolve(data.replace(regex, replacement))
  });
});

/**
 * Saves the prebid file.
 */
const savePrebidFile = data => new Promise((resolve, reject) => {
  fs.writeFile(destPath, data, err => {
    if (err) reject(err);
    else resolve();
  });
});

replaceOptimeraURL()
  .then(savePrebidFile)
  .then(() => console.log('Optimera file patched!'))
  .catch((err) => console.log(err))  

@mkendall07
Copy link
Member

nice script 👍
It occurs to me that prebid.js build should probably fail the build if we can't load in a secure environment. I think that's a challenging thing to test properly though.

@betancourtl
Copy link
Contributor

Should the protocol be dynamic?
In my testing environment I use http but in prod I'm using https. In order to get the url working in both the api call could be made to //dyv1bugovvq1g.cloudfront.net but I'm not sure if that is a security concern.

@stale
Copy link

stale bot commented Mar 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 15, 2019
@stale stale bot closed this as completed Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants