For performance reasons of a relatively complex Nestjs application, we have chosen to use Fastify as our HTTP provider.
We are at a stage where we need to version out api and are running into problems after following instructions on the standard Nestjs guide:
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(fastifyInstance),
{},
);
app.enableVersioning();
The error received is:
Property 'enableVersioning' does not exist on type 'NestFastifyApplication'.ts(2339)
I haven't been able to find a solution anywhere and thought I'd ask and see if anyone else has had the same problem and found a solution.
looks like you need to upgrade #nestjs/common because enableVersioning does exists in NestFastifyApplication:
https://github.com/nestjs/nest/blob/d5b6e489209090544a4f39c4f4a716b9800ca6a8/packages/platform-fastify/interfaces/nest-fastify-application.interface.ts#L16
https://github.com/nestjs/nest/blob/d5b6e489209090544a4f39c4f4a716b9800ca6a8/packages/common/interfaces/nest-application.interface.ts#L47
Related
Installed the google cloud pub sub following instructions from the following link,
https://cloud.google.com/pubsub/docs/reference/libraries
Imported that as the following,
const { PubSub } = require("#google-cloud/pubsub");
const projectId = "projectXYZ";
const pubSubClient = new PubSub({ projectId });
export async function publishMessage(topicName, data) {
return await pubSubClient.topic(topicName).publish(JSON.stringify(data));
}
this leads to the following error,
Now, what I have observed is that the code below the import has no significance in this issue, since this error still appears even if I only import on the first line.
Am I missing something or required to install something more that just the package?
Any help is deeply appreciated.
Thank you in advance.
Library maintainer here! I'm guessing from the stack trace that you're using webpack on your app? Right now we don't have webpack and rollup support - there are a few weird things like what you see above. Your code looks okay. We'd like to get webpack and similar tools working at some point for server-side usage, but it hasn't gone very high on the priority list just yet. I think the previous assumption was that people were trying to use it in a web browser, which we don't recommend for a number of reasons (most prominently, security concerns with GCP credentials). But I've been seeing a lot of issues with users trying to use webpack on the server side to make their Cloud Functions more compact, which seems pretty legit. I'll bring it up in our next team sync.
If you're not using webpack, then that sounds like something that might be filed over at the issue tracker.
I have been using sqlite3 for most of my fullstack applications (node/express, django/drf + svelte on the front end as the consumer of the api endpoints) and have been trying to figure out how to integrate sqlite3.
As far as I know, better-sqlite3 is a synchronous library.
I notice you're using await with better-sqlite3. Removing await might solve your problem.
index.json.ts didn't work for me for some reason. I had to change it to list.json.ts.
Also, they changed the endpoint handler to all uppercase GET in this discussion.
In quarkus, is there a way to add a simple annotation, to expose underlying gRPC implementation as REST/json also? I.e two views with one implementation.
Springboot seem to have ProtobufJsonFormatHttpMessageConverter.
https://medium.com/#thinhda/build-service-that-provides-http-and-grpc-api-with-spring-9e7cff7aa17a
I belive proto syntax allows annotation for rest endpoint
syntax = "proto3";
package pn.api;
//import "google/protobuf/timestamp.proto";
//import "google/api/annotations.proto";
option java_package = "pn.api.protobuf";
option java_outer_classname = "Proto";
service SearchService{
rpc search(SearchRequest) returns (SearchResponse){
// option (google.api.http) = { get: "/v1/search/{queryObj}" };
};
}
No.
There is no way to do it. If you think that's beneficial, feel free to create an issue in Github Issues (https://github.com/quarkusio/quarkus/issues) and we can discuss it there.
In the issue, please focus on what would be a benefit of adding such a feature.
I have a working ordinary Hapi application that I'm planning to migrate to Swagger. I installed swagger-node using the official instructions, and chose Hapi when executing 'swagger project create'. However, I'm now confused because there seem to be several libraries for integrating swagger-node and hapi:
hapi-swagger: the most popular one
hapi-swaggered: somewhat popular
swagger-hapi: unpopular and not that active but used by the official Swagger Node.js library (i.e. swagger-node) as default for Hapi projects
I though swagger-hapi was the "official" approach, until I tried to find information on how do various configurations on Hapi routes (e.g. authorization, scoping, etc.). It seems also that the approaches are fundamentally different, swagger-hapi taking Swagger definition as input and generating the routes automatically, whereas hapi-swagger and hapi-swaggered seem to have similar approach with each other by only generating Swagger API documentation from plain old Hapi route definitions.
Considering the amount of contributors and the number of downloads, hapi-swagger seems to be the way to go, but I'm unsure on how to proceed. Is there an "official" Swagger way to set up Hapi, and if there is, how do I set up authentication (preferably by using hapi-auth-jwt2, or other similar JWT solution) and authorization?
EDIT: I also found swaggerize-hapi, which seems to be maintained by PayPal's open source kraken.js team, which indicates that it might have some kind of corporate backing (always a good thing). swaggerize-hapi seems to be very similar to hapi-swagger, although the latter seems to provide more out-of-the-box functionality (mainly Swagger Editor).
Edit: Point 3. from your question and understanding what swagger-hapi actually does is very important. It does not directly serves the swagger-ui html. It is not intended to, but it is enabling the whole swagger idea (which the other projects in points 1. and 2. are actually a bit reversing). Please see below.
It turns out that when you are using swagger-node and swagger-hapi you do not need all the rest of the packages you mentioned, except for using swagger-ui directly (which is used by all the others anyways - they are wrapping it in their dependencies)
I want to share my understanding so far in this hapi/swagger puzzle, hope that these 8 hours that I spent can help others as well.
Libraries like hapi-swaggered, hapi-swaggered-ui, also hapi-swagger - All of them follow the same approach - that might be described like that:
You document your API while you are defining your routes
They are somewhat sitting aside from the main idea of swagger-node and the boilerplate hello_world project created with swagger-cli, which you mentioned that you use.
While swagger-node and swagger-hapi (NOTE that its different from hapi-swagger) are saying:
You define all your API documentation and routes **in a single centralized place - swagger.yaml**
and then you just focus on writing controller logic. The boilerplate project provided with swagger-cli is already exposing this centralized place swagger.yaml as json thru the /swagger endpoint.
Now, because the swagger-ui project which all the above packages are making use of for showing the UI, is just a bunch of static html - in order to use it, you have two options:
1) to self host this static html from within your app
2) to host it on a separate web app or even load the index.html directly from file system.
In both cases you just need to feed the swagger-ui with your swagger json - which as said above is already exposed by the /swagger endpoint.
The only caveat if you chose option 2) is that you need to enable cors for that end point which happened to be very easy. Just change your default.yaml, to also make use of the cors bagpipe. Please see this thread for how to do this.
As #Kitanotori said above, I also don't see the point of documenting the code programmatically. The idea of just describing everything in one place and making both the code and the documentation engine to understand it, is great.
We have used Inert, Vision, hapi-swagger.
server.ts
import * as Inert from '#hapi/inert';
import * as Vision from '#hapi/vision';
import Swagger from './plugins/swagger';
...
...
// hapi server setup
...
const plugins: any[] = [Inert, Vision, Swagger];
await server.register(plugins);
...
// other setup
./plugins/swagger
import * as HapiSwagger from 'hapi-swagger';
import * as Package from '../../package.json';
const swaggerOptions: HapiSwagger.RegisterOptions = {
info: {
title: 'Some title',
version: Package.version
}
};
export default {
plugin: HapiSwagger,
options: swaggerOptions
};
We are using Inert, Vision and hapi-swagger to build and host swagger documentation.
We load those plugins in exactly this order, do not configure Inert or Vision and only set basic properties like title in the hapi-swagger config.
Currently I have a project using WebAPI and EF with Breeze, it works fine with Metadata stuffs for validation on server but when migrating to NodeJS and MongoDB, I get stuck for trying get Metadata from MongoDB. I checked out zza BMEAN app but I just saw on this project:
app.get('/breeze/Breeze/Metadata', getMetadata);
function getMetadata(req, res, next) {
next({
statusCode: 404,
message: "No metadata from the server; metadata is defined on the client"
});
}
I also read all document about Breeze/MongoDB but still doesn't help me to get Metadata for this.
The main point is I just want to change backend with BMEAN instead of WebAPI+EF+Breeze, don't need to change code on client.
Thanks
The metadata is provided by EF, not by MongoDB. If you are using a CodeFirst approach with EF then you should already have a DBContext.
This talks about how to use the DBContext -
http://www.breezejs.com/documentation/entity-framework-dbcontext
This talks about how to use EF as a design tool to build your meta data from classes -
http://www.breezejs.com/documentation/ef-design-tool
Odds are you already have what you need to generate the metadata it is just extending that and exposing a service to provide it to the client.
PW Kad's answer is correct, but to clarify, there is no way to get metadata from a MongoDB database because the database itself has an indeterminate structure. So you have to tell your client what the structure is. If you want to use the same client code for EF and Mongo then saving the metadata provided by the EFContext in your Mongo project makes a lot of sense. In other cases simply define the metadata directly on the client via Breeze's metadata api calls.