wbhob / nest-middlewares Goto Github PK
View Code? Open in Web Editor NEWCommon, injectable middlewares for NestJS
License: MIT License
Common, injectable middlewares for NestJS
License: MIT License
node_modules/@nest-middlewares/morgan/index.d.ts:4:63 - error TS2314: Generic type 'Options<Request, Response>' requires 2 type argument(s).
4 static configure(format: string | morgan.FormatFn, opts?: morgan.Options): void;
~~~~~~~~~~~~~~
node_modules/@nest-middlewares/morgan/index.d.ts:5:67 - error TS2314: Generic type 'Morgan<Request, Response>' requires 2 type argument(s).
5 static token(name: string, callback: morgan.TokenCallbackFn): morgan.Morgan;
~~~~~~~~~~~~~
I'm trying to use the ServeStaticMiddleware, but I don't know how to do it.
Can you post an example?
It would be nice to have a Store implementation for typeorm in the express-session middleware.
Installing the middleware as per the documentation results in the below error.
Please also refer the attached logs.
npm install --save @nest-middlewares/helmet
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @nestjs/[email protected]
npm ERR! node_modules/@nestjs/common
npm ERR! @nestjs/common@"^8.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @nestjs/common@"^6.0.0" from @nest-middlewares/[email protected]
npm ERR! node_modules/@nest-middlewares/helmet
npm ERR! @nest-middlewares/helmet@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/abhilash.panickar/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/abhilash.panickar/.npm/_logs/2021-11-13T20_44_04_211Z-debug.log
你好,能否写一个更详细的教程?能写个简单的例子最好。
I know its small but someone (yours truly 🥇) didn't understand the ctrl+c
crtl+v
bug:
in the serve-static readme (and my guess its for all of them) you write
HelmetMiddleware.configure( /* options as per helmet docs */ )
HelmetMiddleware
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @nest-middlewares/[email protected]
for the project I'm working on.
we are using nest.js 8, will soon switch to 9, so a dependency to v6 is not really useful, nor necessary: I forced install, and serve-favicon v6.0.1 works well with nest.js v8.4.7.
Here is the diff that solved my problem:
diff --git a/node_modules/@nest-middlewares/serve-favicon/package.json b/node_modules/@nest-middlewares/serve-favicon/package.json
index 4ea913c..7b50dd8 100644
--- a/node_modules/@nest-middlewares/serve-favicon/package.json
+++ b/node_modules/@nest-middlewares/serve-favicon/package.json
@@ -24,7 +24,7 @@
},
"homepage": "https://github.com/wbhob/nest-middlewares#readme",
"peerDependencies": {
- "@nestjs/common": "^6.0.0"
+ "@nestjs/common": "<9.0.0"
},
"dependencies": {
"@types/express": "^4.16.0",
This issue body was partially generated by patch-package.
Hello :)
Just to inform that on the last version of @nest-middlewares/[email protected] the are some errors due to way of importing things from dist folder inside node_modules.
But there is a problem because nowthere is no "dist" folder in node_modules.
I don't know a solution for this because i'm not familiar with javascript modules and how to generate them in typescript.
But i think it's about the dependencies of nest-middleware/helmet ?
Here are the files that lead errors :
node_modules/@nest-middlewares/helmet/content-security-policy.d.ts:2
node_modules/@nest-middlewares/helmet/dns-prefetch-control.d.ts:2
node_modules/@nest-middlewares/helmet/expect-ct.d.ts:2
node_modules/@nest-middlewares/helmet/frameguard.d.ts:2
node_modules/@nest-middlewares/helmet/hsts.d.ts:2
node_modules/@nest-middlewares/helmet/referrer-policy.d.ts:2
Thanks in advance for your contributions to this package,
Have a great day,
TypeScript Errors on the Config function claiming that that bearToken doesn't have the property Options. Apparently, bearerToken.BearerTokenOptions this does exist.
In @nest-middlewares/express-session
, always new session object is created per routing when options
was applied.
nest-middlewares/packages/express-session/index.ts
Lines 15 to 16 in 077baf8
And express-session
creates new instance of MemorySession
if option.store
wasn't specified.
https://github.com/expressjs/session/blob/10607bdb780204b91a8cf90e4ce27726619b8285/index.js#L99-L100
So the app can't keep values in the session.
I suspect the value of expressSession
should be cached in the class ExpressSessionMiddleware
.
please check out thread nestjs/nest#1204
@next-middlewares/express-session uses bad typings, looks like referenced interface was removed since nest 5.0.0
With the latest version of nestjs it spits out an error:
WARNING!!
The @Middleware() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.
CorsMiddleware.configure({})`
This throws unhandled promise rejection exception.
Passing null instead seems to do the trick
CorsMiddleware.configure(null)`
Also the Readme in CorsMiddleware uses HelmetMiddleware instead of CorsMiddleware. I assume this is a minor bug.
Is the MiddlewaresConsumer
any different that MiddlewareConsumer
(without s). Cause I couldnt find such class.
I desperately need some form of documentation on how to implement nest-middlewares/express-session
but my Google-fu has failed me.
Hi,
great middleware, be nice if the following was supported also
Nest Js v6.0.0
(nestjs/nest#1486) is in release candidate. I think few changes has occur for the middlewares.
Is there a plan to update to v6.0.0
packages in this repository ?
Hi, I think there are a few issues with CorsMiddleware source code:
https://github.com/wbhob/nest-middlewares/blob/master/packages/cors/index.ts
Line 8 this.options = opts;
should be CorsMiddleware.options = opts;
Line 17 cors()(req, res, next);
should be wrapped with else
, otherwise cors may be applied twice.
I'm the maintainer of Helmet. I plan to release the next major version this Sunday, 2020-08-22.
Is there anything I can do to help get @nest-middlewares/helmet
upgraded to helmet@4
?
If you'd like to try out the release candidate now, you can install it with npm install helmet@next
. If you'd rather discuss things outside of this issue, feel free to reach out to me another way.
Hope I can be helpful!
Trying to install @nest-middlewares/morgan give the following dependency error.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @nest-middlewares/[email protected]
npm ERR! Found: @nestjs/[email protected]
npm ERR! node_modules/@nestjs/common
npm ERR! @nestjs/common@"^10.0.0" from the root project
npm ERR! peer @nestjs/common@"^10.0.0" from @nestjs/[email protected]
npm ERR! node_modules/@nestjs/core
npm ERR! @nestjs/core@"^10.0.0" from the root project
npm ERR! peer @nestjs/core@"^10.0.0" from @nestjs/[email protected]
npm ERR! node_modules/@nestjs/platform-express
npm ERR! @nestjs/platform-express@"^10.0.0" from the root project
npm ERR! 2 more (@nestjs/core, @nestjs/testing)
npm ERR! 1 more (@nestjs/testing)
npm ERR! 2 more (@nestjs/platform-express, @nestjs/testing)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @nestjs/common@"^9.0.0" from @nest-middlewares/[email protected]
npm ERR! node_modules/@nest-middlewares/morgan
npm ERR! @nest-middlewares/morgan@"^7.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @nestjs/[email protected]
npm ERR! node_modules/@nestjs/common
npm ERR! peer @nestjs/common@"^9.0.0" from @nest-middlewares/[email protected]
npm ERR! node_modules/@nest-middlewares/morgan
npm ERR! @nest-middlewares/morgan@"^7.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Thanks for this collection, it looks really helpful!
While using [email protected]
with nestjs/[email protected]
, [email protected]
and I encountered the following error:
node_modules/@nest-middlewares/cors/index.d.ts(7,5): error TS2416: Property 'resolve' in type 'CorsMiddleware' is not assignable to the same property in base type 'NestMiddleware'.
Type '(...args: any[]) => RequestHandler' is not assignable to type '(...args: any[]) => MiddlewareFunction<any, any, any> | Promise<MiddlewareFunction<any, any, any>>'.
Type 'RequestHandler' is not assignable to type 'MiddlewareFunction<any, any, any> | Promise<MiddlewareFunction<any, any, any>>'.
Type 'RequestHandler' is not assignable to type 'Promise<MiddlewareFunction<any, any, any>>'.
Property 'finally' is missing in type 'RequestHandler'.
Edit: Just make resolve
return an ExpressMiddleware
and it works fine, i.e:
@Injectable()
export class CorsMiddleware implements NestMiddleware {
public static configure(opts: cors.CorsOptions) {
this.options = opts;
}
private static options: cors.CorsOptions;
public resolve(...args: any[]): ExpressMiddleware {
if (CorsMiddleware.options) {
return cors(CorsMiddleware.options);
}
return cors();
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.