Giter Club home page Giter Club logo

dev-proxy's Introduction

Dev script proxy

Provides the capability to override an news-projects script with a different script with settings defined in localStorage.

The script being overridden needs to import and use this library:

import { proxy } from '@abcnews/dev-proxy';

function init() {
  // The code that kicks off your script goes here.
}

proxy('project-name').then(init);

To put the override into effect localStorage needs to contain an entry with key proxy_<project-name> that contains the URL of the script to override with.

How does it work?

The proxy function returns a promise that will either:

  • resolve successfully, indicating that the script initialisation should go ahead (i.e. the .then(init) part of the above implementation example), or
  • be rejected, indicating that an alternative script has been successfully identified and added to the document and the init function should not be run.

For the proxy function to successfully identify a script to run instead a few criteria need to be met:

  • The script importing the proxy function should not have a NODE_ENV of 'development' (this prevents infinite loops when this proxy function is used on a dev server.
  • The script should not be running on a production URL.
  • localStorage must contain an entry identifying a suitable replacement hosted on an ABC url (including localhost aliases that include abc.net.au).

Usage

As of version 1.2.0 pressing the key combination Alt-M when you're in an approprate dev or preview environment offers an easy way to set the appropriate localStorage values to proxy relevant scripts on the page.

dev-proxy's People

Contributors

drzax avatar colingourlay avatar

Watchers

 avatar James Cloos avatar  avatar

dev-proxy's Issues

Make exceptions for public URLs under /news-projects/

I'd like to be able to run the dev proxy on my chart builder, which is deployed to /news-projects/, but currently we never load proxies from anything on www.abc.net.au (understandably).

Could we possibly add a 2nd boolean argument to proxy that will allow it to run on /news-projects/ URLs, regardless of the live/preview environment? It seems reasonably safe to do so, but I'd like your thoughts @drzax.

Bookmarklet is broken

The bookmarlet link in the readme needs to be updated. It currently points to a non-existent URL.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.