Middleware in ES2015
I have a question about the use of middleware in ES2015. Typescript accepts interfaces but javascript does not, what can be done about it?
This in ES2015 cannot be done, what would be the correct syntax? For example in the documentation this:
import { Middleware, NestMiddleware } from '@nestjs/common';
@Middleware()
export class LoggingMiddleware implements NestMiddleware {
resolve(): (req, res, next) => void {
return (req, res, next) => {
console.log('Request...');
next();
}
}
}
what can be done about it?
Nothing, this is only checked by typescript compiler.
@juandav Check how the NestMiddleware interface is compiled to es6:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
This is the whole file called nest-middleware.interface.js
Btw I recommend to write code in TypeScript using nest.js is perfect combination.
Regards.
Hi @juandav, As @cojack mentioned - just remove typings. In your case:
mport { Middleware, NestMiddleware } from '@nestjs/common';
@Middleware()
export class LoggingMiddleware {
resolve() {
return (req, res, next) => {
console.log('Request...');
next();
}
}
}
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.