tdeekens / promster

⏰A Prometheus exporter for Hapi, express and Marble.js servers to automatically measure request timings 📊

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript error with createMidleware function

natoehv opened this issue · comments

Hi everybody!

I started to work with the new typescript integration (I'm using Express), and I got an error with the createMidleware function
image
theapp variable is defined as Express.Application,

TS Error:
Type 'Application' is missing the following properties from type 'TApp': setTimeout, maxHeadersCount, timeout, headersTimeout, and 9 more.ts(2740)

Should I change the typing of the application?

thanks you!

Thanks for opening.

TApp just extends Server from http. What are you passing in? Otherwise you could also get away with casting it. https://github.com/tdeekens/promster/blob/main/packages/express/modules/middleware/middleware.ts#L16

I'm using an express application:

const applyMiddleware = ({ app, path, regexPath, rewritePath }: PrometheusConfig) => {
  app.use(createMiddleware({
    app,
    options: {
      normalizePath: (originalpath) => {
        if (regexPath && !!regexPath.exec(originalpath)) {
          return rewritePath || 'customPath';
        }
        return originalpath;
      },
    },
  }));
...
}
export declare interface PrometheusConfig {
  app: express.Application;
  path: string;
  regexPath?: RegExp;
  rewritePath?: string;
}

and I use it:

const app = express();
const appProm = applyMiddleware({ app, path: promPath });

PD: I can't cast to TApp, because it doesn't export :(

Would it help you if we'd export it? Maybe try it with a fork. If it works I'd be happy to see a PR.

exporting the class did not work, but if a change in the type of TApp, what do you think?

#500

Awesome. Thanks for contributing.

Will be published from CI.

thank you @tdeekens 👍 now is working fine 🥇