Git Product home page Git Product logo

Comments (6)

sv2 avatar sv2 commented on May 31, 2024 1

Got it working ! I've created new starter sails.js project sails new test-project, selecting Web App template.

Then to enable swagger-stats, modify file config/http.js as follows:

/**
 * HTTP Server Settings
 * (sails.config.http)
 *
 * Configuration for the underlying HTTP server in Sails.
 * (for additional recommended settings, see `config/env/production.js`)
 *
 * For more information on configuration, check out:
 * https://sailsjs.com/config/http
 */

let swStats = require('swagger-stats');    
let swaggerSpec = require('swagger-stats/examples/authtest/petstore.json')

module.exports.http = {

  middleware: {

    order: [
      'swaggerStats',
      'cookieParser',
      'session',
      'bodyParser',
      'compress',
      'poweredBy',
      'router',
      'www',
      'favicon'
    ],

    swaggerStats: (function _configureSwaggerStats(){
      let swsOptions = {
        name: 'swagger-stats-sailsjs',
        version: '0.1.0',
        timelineBucketDuration: 60000,
        swaggerSpec:swaggerSpec,
        durationBuckets: [50, 100, 200, 500, 1000, 5000],
        requestSizeBuckets: [500, 5000, 15000, 50000],
        responseSizeBuckets: [600, 6000, 6000, 60000],
        // Make sure both 50 and 50*4 are buckets in durationBuckets, 
        // so Apdex could be calculated in Prometheus 
        apdexThreshold: 50,    
        onResponseFinish: function(req,res,rrr){
          debug('onResponseFinish: %s', JSON.stringify(rrr));
        },
        authentication: false
      };
      return swStats.getMiddleware(swsOptions);
    })(),
  },
};

I'm using here example swagger spec that comes with swagger-stats, just for illustration.
This gives working sails.js example app with swagger-stats enabled:

image

image

from swagger-stats.

sv2 avatar sv2 commented on May 31, 2024

Only works with express so far. Will take a look at sail.js ...

from swagger-stats.

sv2 avatar sv2 commented on May 31, 2024

Looks like sail.js is compatible with express and the same middleware can be used with sail.js:
https://sailsjs.com/documentation/concepts/middleware

Perhaps you could try to add swagger-stats as a middleware to you app per instructions on the page above ?

from swagger-stats.

hametGh avatar hametGh commented on May 31, 2024

yes it's worked with config/express.js

const swStats = require('swagger-stats');
const apiSpec = require('../swagger.json');

module.exports.express = {
    customMiddleware: function (app) {
        app.use(swStats.getMiddleware({ swaggerSpec: apiSpec }));
    }
};

but now when i send GET request to /swagger-stats/ui i got this error:

error: Server Error:
error: TypeError: res.sendFile is not a function
at Object.trackingMiddleware [as handle] (\node_modules\swagger-stats\lib\swsInterface.js:357:21)

from swagger-stats.

hametGh avatar hametGh commented on May 31, 2024

any solution?

from swagger-stats.

sv2 avatar sv2 commented on May 31, 2024

Closing as no further feedback - assume above suggestion is working

from swagger-stats.

Related Issues (20)

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.