Fastify Nestjs Cors bug - nestjs

I found below cors warning when use fastify nestjs server (#nestjs/platform-fastify of 8.4.5 version)
[FST_MODULE_DEP_FASTIFY-CORS] FastifyWarning.fastify-cors: fastify-cors has been deprecated. Use #fastify/cors#7.0.0 instead.
(Use node --trace-warnings ... to show where the warning was created)
how to solve this?

It was addressed in this pull request and I think it will be deployed in the upcoming version 9.0.0

Related

Which version of JHipster is supported by the JHipster Blueprint generator?

Here is the link to the generator's repo : https://github.com/jhipster/generator-jhipster-blueprint
So I am trying to develop a blueprint. I have followed the steps in the readme for local development. When I try to run "jhipster -d --blueprints TestQuestion", this is the message I get :
DEBUG! Found blueprint generator-jhipster-TestQuestion and server with namespace jhipster-TestQuestion:server
WARNING! Error adding current blueprint templates as alternative for JHipster templates.
Error: The Namespace jhipster-TestQuestion:server may not be correct. Please check your configuration and ensure your blueprint folder start with "generator-". Detail: Error: Error parsing namespace jhipster-TestQuestion:server
at module.exports.jhipsterTemplatePath (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster/generators/generator-base.js:201:13)
at new JHipsterBaseBlueprintGenerator (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster/generators/generator-base-blueprint.js:68:49)
at new JHipsterServerGenerator (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster/generators/server/index.js:65:5)
at new module.exports (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-Test/generators/server/index.js:7:9)
at Environment.instantiate (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js:801:23)
at Environment.create (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js:773:17)
at JHipsterServerGenerator.composeWith (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1326:42)
at JHipsterServerGenerator._composeBlueprint (/usr/local/lib/node_modules/generator-jhipster/generators/generator-base-blueprint.js:516:43)
at async JHipsterServerGenerator.composeWithBlueprints (/usr/local/lib/node_modules/generator-jhipster/generators/generator-base-blueprint.js:413:34)
at async JHipsterServerGenerator._postConstruct (/usr/local/lib/node_modules/generator-jhipster/generators/server/index.js:96:7)
ERROR! jhContext.setupServerOptions is not a function
TypeError: jhContext.setupServerOptions is not a function
at new module.exports (/home/dev/Documents/JavaProjects/JHipster/generator-jhipster-Test/generators/server/index.js:18:19)
at Environment.instantiate (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js:801:23)
at Environment.create (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-environment/lib/environment.js:773:17)
at JHipsterServerGenerator.composeWith (/usr/local/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/index.js:1326:42)
at JHipsterServerGenerator._composeBlueprint (/usr/local/lib/node_modules/generator-jhipster/generators/generator-base-blueprint.js:516:43)
at async JHipsterServerGenerator.composeWithBlueprints (/usr/local/lib/node_modules/generator-jhipster/generators/generator-base-blueprint.js:413:34)
at async JHipsterServerGenerator._postConstruct (/usr/local/lib/node_modules/generator-jhipster/generators/server/index.js:96:7)
at async JHipsterAppGenerator.compose (/usr/local/lib/node_modules/generator-jhipster/generators/app/index.js:431:11)
(node:183468) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./generators/" in the "exports" field module resolution of the package at /home/dev/Documents/JavaProjects/JHipster/generator-jhipster-Test/node_modules/generator-jhipster/package.json.
Update this package.json to use a subpath pattern like "./generators/*".
(Use `node --trace-deprecation ...` to show where the warning was created)
https://github.com/jhipster/generator-jhipster-blueprint/issues/225
This issue asked the same question, but one year ago. It said that the blueprint generator did not support JHipster v7 at the time, and so that's why it did not work.
Which brings me to my question : Which version of JHipster is supported by the JHipster Blueprint generator?
I have JHipster 7.8.1, so if you also know how to downgrade my version, I would appreciate it a lot.
The blueprint generator was added in JHipster v7.7.0 so you should be fine to use it with 7.8.1. You can check out the following recently-released blueprints that are based on 7.8.1.
https://github.com/jhipster/generator-jhipster-native
https://github.com/jhipster/generator-jhipster-ionic

Express application crashes when it is built with webpack

I am trying to use graphql-upload in a typescript express app (graphql api) built with webpack. When I run with ts-node my app works fine. But when I compile with webpack and then run I get a weird error when I try to upload a file.
My setup
Typescript app
Apollo server / Typegraphql
Build with webpack
My Code
(stripped down to the essentials)
https://github.com/ziggy6792/graphql-file-uploads
My Problem
When I run with ts-node yarn start:ts:node then run yarn test an image gets uploaded no problem
But then I build with webpack yarn start then run yarn test I get the following error
/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:56105
if (!isObject(operations) && !Array.isArray(operations))
^
TypeError: isObject is not a function
at Busboy.<anonymous> (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:56105:18)
at Busboy.emit (node:events:378:20)
at Busboy.module.exports../node_modules/busboy/lib/main.js.Busboy.emit (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:32204:33)
at PartStream.onEnd (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:32528:15)
at PartStream.emit (node:events:390:22)
at Dicer.onPart (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:32386:13)
at Dicer.emit (node:events:378:20)
at Dicer.module.exports../node_modules/dicer/lib/Dicer.js.Dicer.emit (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:45439:35)
at Dicer.module.exports../node_modules/dicer/lib/Dicer.js.Dicer._oninfo (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:45540:12)
at SBMH.<anonymous> (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:45486:10)
[nodemon] app crashed - waiting for file changes before starting...
My Attempts to solve
I am not sure if this actually a problem with graphql-upload or webpack or something else. I also noticed that my issue looks similar to this issue, but I didn't really understand if there were any fixes to that issue and if indeed it is the same issue I am facing.
I tried to upgrade webpack (branch upgraded-packages) but this made the problem worse as I get this issue when I start the server
TypeError: Cannot read property 'graphql' of undefined
at getPeerDependencyGraphQLRequirement (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:104216:44)
at Object.ensureInstalledCorrectGraphQLPackage (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:104221:32)
at Function.checkForErrors (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103346:27)
at Function.generateFromMetadataSync (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103325:14)
at Function.generateFromMetadata (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103315:29)
at Object.buildSchema (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103940:61)
at /Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:99831:41
at Generator.next (<anonymous>)
at /Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:99819:71
at new Promise (<anonymous>)
Any help would be greatly appreciated.
My best guess at the problem
From reading the linked issue it seems like isObject seems to ship ECMA Script modules with a newer version. Webpack might pick the ES modules version, but this version differs in the sense that the default export is now default and Apollo Server would have to import it as such or call isObject.default. In this changelog they say it might be breaking for users using bundlers.
Your two options now:
You could use yarn force the dependency to a previous version of isobject:
{
...
"resolutions": {
"graphql-file-uploads/isobject": "3.0.1"
}
}
Or you could simply not bundle your app and use TypeScript for building instead. You lose the benefits of bundling, but you are using an environment that is much more common for running node apps. Furthermore you will use TypeScript as a compiler just like ts-node unifying your development and production tooling.
You can compile using TypeScript like this:
yarn tsc 'src/**/*.ts'
In your TSConfig you should configure the output so that it also emits files to /dist.

Module #google-cloud/speech not supported for Vue JS?

I'm playing with the Google Cloud API Speech-to-Text Node client library. Works quite well, and well described in their documentation.
Problems come when I wanted to use it in a VueJS : it simply seems not to be supported.
First attempt :
npm run serve returns
ERROR Failed to compile with 3 errors 11:35:13
This dependency was not found:
* http2 in ./node_modules/#grpc/grpc-js/build/src/channel.js, ./node_modules/#grpc/grpc-js/build/src/subchannel.js and 1 other
But http2 is a core module in Node now, and when I run node -p http2 I do get results.
Second attempt :
npm i http2
npm run serve returns
WARNING Compiled with 1 warnings 11:41:07
warning in ./node_modules/http2/lib/protocol/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
In browser, console provides error
Uncaught Error: not supported
at Root.loadSync (root.js?ee6e:234)
at Object.loadSync (index-light.js?071f:69)
at Object.eval (index.js?f193:244)
at eval (index.js:250)
at Object../node_modules/#grpc/proto-loader/build/src/index.js (app.js:1383)
at __webpack_require__ (app.js:724)
at fn (app.js:101)
at Object.eval (grpc.js?6f5f:34)
at eval (grpc.js:288)
at Object../node_modules/google-gax/build/src/grpc.js
My Vue App is basic and can be retrieved using vue-cli by running vue create app. I then added in the HelloWorld Component the basic code displayed in the quickstart guide.
My theory is : VueJS can't use google-gax module due to gRPC. What do you think ?
Currently the Google Cloud API client libraries such as the one you are using cannot be used from the browser. As you noted, those libraries use gRPC, which in turn uses http2. The problem is that currently no major browser allows JavaScript libraries to use the full functionality of the HTTP/2 protocol, so there is currently no complete browser shim for the Node http2 module.
The http2 module you got from npm is a different library with a different API. It most likely also does not work in the browser for the same reason.

hsts deprecated The "includeSubdomain" paramter is deprecated

I have a loopback 3 application. When I start the application with . node I get this in my console.
hsts deprecated The "includeSubdomain" parameter is deprecated. Use "includeSubDomains" (with a capital D) instead. node_modules/loopback/lib/server-app.js:74:25
I searched in my node_modules folder, but there isn't a loopback folder. So how can I fix this?
It's due to the helmet config in middleware.json. Just open it, then find and replace includeSubdomain to includeSubDomains.
I am having same error too,
But just viewing on PM2 logs to see that.
Do you use Loopback with PM2 or inside a Docker container?
I dont have this error with running "NODE . "

Nestjs server does not serve socket.io client

I have a split app using nestjs on the server and an Angular app as the client. Setting up websockets with socket.io seemed pretty easy using the #nestjs/websockets module and on the client I used ngx-socket-io. I used this repo as basis. Now when I update the project's #nestjs/websockets dependency to the latest version I get
CORS errors and
an error that the client couldn't load the socket.io client js file
I expected CORS problems and after the update, I could fix them by adding
app.enableCors({
origin: 'http://localhost:4200',
credentials: true,
});
to my main.ts file, but I don't know why the client file is not served. With the version of the repo (5.7.x) there are neither CORS errors nor problems with serving the file.
I tried a couple of settings of #WebSocketGateway(), moving to a different port, setting serveClient (even though it should be true by default), but nothing seemed to work. Any advice?
thanks
In my case
I replaced
app.useWebSocketAdapter(new WsAdapter(app));
from
import { WsAdapter } from '#nestjs/platform-ws';
with
app.useWebSocketAdapter(new IoAdapter(app));
in main .ts from
import { IoAdapter } from '#nestjs/platform-socket.io';
Worked like a charm!
The problem was that nestjs did separate the lower level platform (socket.io, express, fastify, ...) from the nestjs modules. The websocket module requires to install an underlying platform, for socket.io
npm install --save #nestjs/platform-socket.io
To serve the socket.io client file it seems like there also needs to be an HTTP platform installed, for express
npm install --save #nestjs/platform-express
More info in the migration guide for v6.
I had the same problem. i was opening the client side of the application in the web-browser, but directly from my filesystem (i would double click on the file index.html next to the little dummy fake-front-end.js on my desktop for example...). It seems that the CORS problem would persist until i actually accessed the index.html through a proper server. So i created a route on my backend, to serve the index.html, and the fake-front-end.js.
There is a section about CORS on the socket.io officual documentation. And there is a section on the nestjs website, but both didnt really helped in my case.

Resources