Giter Club home page Giter Club logo

strapi-plugin-moesif's Introduction

Strapi plugin moesif

WARNING (Breaking Changes): ^2.0.0 only supports Strapi v4 and above. For Strapi v3 support, use ^1.0.5

Plugin to add Moesif API Analytics and Monitoring to Strapi!

Installation

  1. Install the plugin
npm install --save strapi-plugin-moesif
  1. Enable the plugin ./config/plugins.js
module.exports = {
  'strapi-plugin-moesif': {
    enabled: true,
    config: {
      moesif: {
        //custom config passed to moesif middleware goes here
      }
    },
  },
}
  1. Add Moesif to your middleware array ./config/middleware.js
module.exports = [
  'strapi::errors',
  'strapi::security',
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::favicon',
  'strapi::public',
  'plugin::strapi-plugin-moesif.moesif'
];

Add MOESIF_APPLICATION_ID to your environment variables Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

  1. Run Strapi

npm

npm run develop

yarn

yarn develop

Make a few API calls to your resources like so:

curl `http://localhost:1337`

Heroku

If using Heroku, simply install the Moesif application as an add-on. The MOESIF_APPLICATION_ID environment variable will be automatically created and managed by Heroku.

Configuration options

Because this plugin uses moesif-nodejs under the hood, all of the configuration options for moesif-nodejs are supported by this plugin also.

identifyUser

To track Strapi users, we set the identifyUser function by default:

identifyUser: function (req, res) {
  if (req.state && req.state.user) {
    return String(req.state.user.id);
  }
  return undefined;
}

skip

Moesif can be setup to track all traffic in and out of your application, but usually the interest is in API metrics specifically. The default configuration of this plugin skips all non-JSON communication to avoid having tons of file requests in your Moesif dashboard.

To override the skip function, simple include one in your config, or set to to send all communications:

// return true if the data should be skipped
skip: function (req, res) {
  // don't log non JSON types
  return (
    res.headers && !res.headers["Content-Type"].includes("application/json")
  );
}

//send all data regardless of type
skip: null

Credits

This plugin was originally created by Bobby Glidwell

strapi-plugin-moesif's People

Contributors

bglidwell avatar dgilling avatar umair-me avatar xinghengwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

moesif

strapi-plugin-moesif's Issues

Which file to add the skip options

Where do we add the skip configuration in strapi v4?

    skip: function (req, res) {
        console.log(req);
        return (
          res.headers && !res.headers["Content-Type"].includes("application/json")
        );
      }

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.