detect-is-on-glitch
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Detect-Is-On-Glitch

Creative name, right?

Well, in my defense, this is a very simple package. It simply tells you whether or not your code is executing inside of the Glitch environment.

Using

Options:

  • Call via CLI
    • detect-is-on-glitch or isglitch
      • isglitch && echo "Running on Glitch"
    • You can use the -i or --invert flag to get !result, like so:
      • isglitch -i && echo "Not running on Glitch"
  • Pull in to front-end
    <script src="node_modules/detect-is-on-glitch/dist/browser/glitch-detect.min.js"></script>
    <script>
    detectIsOnGlitch().then((res) => {
        alert(`You are ${res ? '' : 'not '}on Glitch`);
    });
    </script> 
  • Backend / NodeJS
    const getIsOnGlitch = require('detect-is-on-glitch');
     
    getIsOnGlitch().then((isOnGlitch) => {
        if (isOnGlitch) {
            console.log('is on glitch!');
        } else {
            console.log('somewhere else!');
        }
    });

Building

yarn build

Detection method

Right now, the detection method is extremely simple:

  • Browser / client: Checks if the current URL belongs to Glitch, or a subdomain
  • Server side: Checks for some env / process.env.* environmental variables that are injected by Glitch
    • For example, GLITCH_SHARED_INCLUDES_LEGACY_CLS

Package Sidebar

Install

npm i detect-is-on-glitch

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

11.6 kB

Total Files

14

Last publish

Collaborators

  • joshuatz