Skip to content

Commit

Permalink
Merge pull request #2466 from kuzzleio/2.25.0-proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko authored May 24, 2023
2 parents 4c56549 + 02ab881 commit 0560fc4
Show file tree
Hide file tree
Showing 40 changed files with 1,287 additions and 620 deletions.
2 changes: 1 addition & 1 deletion .ci/scripts/run-test-arm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ nvm use $NODE_VERSION

npm run build

node -r ts-node/register docker/scripts/start-kuzzle-dev.ts &
node -r ts-node/register docker/scripts/start-kuzzle-test.ts &

echo "[$(date)] - Starting Kuzzle..."

Expand Down
4 changes: 2 additions & 2 deletions .ci/scripts/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ tar xf kuzzle-*.tgz
echo "[$(date)] - Starting Kuzzle..."

# Use the built package for functional tests
sed -i 's/require("..\/..\/index")/require("..\/..\/package\/index")/g' docker/scripts/start-kuzzle-dev.js
sed -i 's/require("..\/..\/index")/require("..\/..\/package\/index")/g' docker/scripts/start-kuzzle-test.js

node -r ts-node/register docker/scripts/start-kuzzle-dev.js --enable-plugins functional-test-plugin &
node -r ts-node/register docker/scripts/start-kuzzle-test.js --enable-plugins functional-test-plugin &

./bin/wait-kuzzle

Expand Down
3 changes: 2 additions & 1 deletion .ci/test-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ x-kuzzle-config: &kuzzle-config
image: kuzzleio/kuzzle-runner:${NODE_VERSION:-16}
command: >
bash -c "
node ./docker/scripts/start-kuzzle-dev.js --enable-plugins kuzzle-plugin-cluster,functional-test-plugin
node ./docker/scripts/start-kuzzle-test.js --enable-plugins kuzzle-plugin-cluster,functional-test-plugin
"
volumes:
- "..:/var/app"
Expand All @@ -26,6 +26,7 @@ x-kuzzle-config: &kuzzle-config
- kuzzle_server__protocols__mqtt__developmentMode=false
- kuzzle_http__accessControlAllowOrigin=localhost
- kuzzle_limits__loginsPerSecond=50
- kuzzle_server__protocols__http__additionalContentTypes=*json:["application/x-yaml"]
- NODE_ENV=development
- NODE_VERSION=${NODE_VERSION:-}
- DEBUG=none
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ kuzzle-*.tgz
/index.js
docker/scripts/functional-tests-controller.js
docker/scripts/start-kuzzle-dev.js
docker/scripts/start-kuzzle-test.js
features-sdk/support/application/functional-tests-app.js
lib/api/openApiGenerator.js
lib/api/openapi/OpenApiManager.js
Expand Down
10 changes: 10 additions & 0 deletions .kuzzlerc.sample
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,15 @@
// protocols can be extended and configured in this section.
"protocols": {
"http": {
// * additionalContentTypes:
// Enables Kuzzle to accept additional Content-Types.
// Note: This relies on the implementation of a
// "protocol:http:beforeParsingPayload" pipe that implements
// the formatting of the additional content types to JSON.
// The default content types are:
// * application/json
// * application/x-www-form-urlencoded
// * multipart/form-data
// * allowCompression:
// Enable support for compressed requests, using the
// Content-Encoding header
Expand All @@ -421,6 +430,7 @@
// allocate as many decoders to handle the incoming request.
// * maxFormFileSize:
// Maximum size of requests sent via http forms
"additionalContentTypes": [],
"allowCompression": true,
"enabled": true,
"maxEncodingLayers": 3,
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ Learn how to [Write an Application](https://docs.kuzzle.io/core/2/guides/getting

Train yourself and your teams to use Kuzzle to maximize its potential and accelerate the development of your projects.
Our teams will be able to meet your needs in terms of expertise and multi-technology support for IoT, mobile/web, backend/frontend, devops.
:point_right: [Get a quote](https://hubs.ly/H0jkfJ_0)
:point_right: [Get a quote](https://kuzzle.io/pricing/)

## Public Roadmap

You can consult the public roadmap on Trello. Come and vote for the features you need!
:point_right: [Kuzzle Public Roadmap](https://trello.com/b/za9vOgRh/kuzzle-public-roadmap)

## Contributing to Kuzzle

Expand All @@ -132,7 +128,6 @@ Check our [contributing documentation](./CONTRIBUTING.md) to know about our codi
* Visit our [blog](https://blog.kuzzle.io/) to be informed about what we are doing
* Come chat with us on [Discord](http://join.discord.kuzzle.io)
* Ask technical questions on [stack overflow](https://stackoverflow.com/search?q=kuzzle)
* Check out our [public roadmap](https://trello.com/b/za9vOgRh/kuzzle-public-roadmap) and vote for the upcoming features

## License

Expand Down
9 changes: 9 additions & 0 deletions doc/2/api/errors/error-codes/services/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@ description: Error codes definitions
| services.statistics.not_available<br/><pre>0x01040001</pre> | [InternalError](/core/2/api/errors/error-codes#internalerror) <pre>(500)</pre> | Statistics module is not available. | The statistics module is not enabled. See "config.stats.enabled". |

---


### Subdomain: 0x0105: koncorde

| id / code | class / status | message | description |
| --------- | -------------- | --------| ----------- |
| services.koncorde.elastic_translation_error<br/><pre>0x01050001</pre> | [BadRequestError](/core/2/api/errors/error-codes#badrequesterror) <pre>(400)</pre> | An error occured while translating a Koncorde filter to an Elasticsearch query: %s | An error occured while translating a Koncorde filter to an Elasticsearch query |

---
13 changes: 12 additions & 1 deletion doc/2/api/protocols/http/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,21 @@ The listening port can be modified under the `server.port` section of the [confi
// gzip, deflate, identity
// Note: "identity" is always an accepted value, even if
// compression support is disabled
"allowCompression": true
"allowCompression": true,

// Enables Kuzzle to accept additional Content-Types.
// Note: This relies on the implementation of a
// "protocol:http:beforeParsingPayload" pipe that implements
// the formatting of the additional content types to JSON.
// The default content types are:
// * application/json
// * application/x-www-form-urlencoded
// * multipart/form-data
"additionalContentTypes": [],
},
}
```
::: warning
HTTP and WebSocket protocols share the same underlying server instance.
Modifying the listening port will impact these two protocols.
Expand Down
90 changes: 90 additions & 0 deletions doc/2/guides/advanced/content-types/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
code: false
type: page
order: 900
title: Additional Content Types | Kuzzle Advanced | Guide | Core
meta:
- name: description
content: Support additional content types
- name: keywords
content: Kuzzle, Documentation, kuzzle write pluggins, General purpose backend, opensource, content-type, iot, backend
---

# Additional Content Types

<SinceBadge version="2.25.0" />

By default, Kuzzle supports common HTTP content types like JSON and form data.

However, there may be cases where you need to support additional content types such as YAML.

This documentation guide will explain how to extend Kuzzle's capabilities to handle custom content types.

## Configuring Kuzzle

The `server.protocols.http.additionalContentTypes` configuration setting in the [kuzzlerc configuration file](/core/2/guides/advanced/configuration) allows you to specify additional content types that Kuzzle should support.

It takes an array of strings, where each string represents a content type.

```javascript
"server": {
"protocols": {
"http": {
// Enables Kuzzle to accept additional Content-Types.
// Note: This relies on the implementation of a
// "protocol:http:beforeParsingPayload" pipe that implements
// the formatting of the additional content types to JSON.
"additionalContentTypes": [
"application/x-yaml"
]
}
}
}
```

:::info
The default content types are:

- application/json
- application/x-www-form-urlencoded
- multipart/form-data
:::

## Implementing the `protocol:http:beforeParsingPayload` pipe

To convert the payload of the custom content type to a format that Kuzzle can handle (e.g., JSON), you need to implement the `protocol:http:beforeParsingPayload` pipe.

This pipe intercepts the incoming HTTP request, allowing you to modify the payload before Kuzzle parses it.

The `protocol:http:beforeParsingPayload` pipe is a function that takes an object as an argument, containing two properties:

- `message`: An object of type HttpMessage, containing information about the HTTP request.
- `payload`: A Buffer containing the raw payload data.

Your implementation should return an object containing a single `payload` property, which holds the converted payload.

Here's an example implementation of the `protocol:http:beforeParsingPayload` pipe, converting YAML to JSON:

```typescript
const yamlToJsonPipe = ({
message,
payload,
}: {
message: HttpMessage;
payload: Buffer;
}): { payload: string } => {
if (message.headers["content-type"] !== "application/x-yaml") {
return { payload };
}

const convertedPayload = YAML.parse(payload.toString());

return { payload: JSON.stringify(convertedPayload) };
};
```

That pipe can then be registered in your backend:

```typescript
app.pipe.register("protocol:http:beforeParsingPayload", yamlToJsonPipe);
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions doc/2/guides/getting-started/run-kuzzle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ In this guide we will use Docker and Docker Compose to run those services.

### Prerequisites

- [Node.js <= 16](https://nodejs.org/en/download/)
- [Node.js <= 18](https://nodejs.org/en/download/)
- [Docker](https://docs.docker.com/engine/install/)
- [Docker Compose](https://docs.docker.com/compose/install/)
- [Kourou](https://github.com/kuzzleio/kourou)

::: info
It's recommanded to use Node Version Manager to avoid rights problems when using Node.js and dependencies.
It is recommended to use Node Version Manager to avoid rights problems when using Node.js and dependencies.
You can install NVM with the one-liner script documented on [NVM Github repository](https://github.com/nvm-sh/nvm#install--update-script)
:::

Expand Down Expand Up @@ -76,7 +76,7 @@ playground/
└── tsconfig.json
```

The `app.ts` file contain the basic code to run a Kuzzle application. This file is meant to be executed with Node.js as any application.
The `app.ts` file contains the basic code to run a Kuzzle application. This file is meant to be executed with Node.js like any other app.

```ts
import { Backend } from "kuzzle";
Expand All @@ -91,7 +91,7 @@ app
.catch(console.error);
```

We can now run our first application with `npm run docker:dev`
We can now run our first application with: `npm run docker:dev`

::: info
Under the hood, the command `npm run docker:dev` uses [nodemon](https://nodemon.io/) and [ts-node](https://www.npmjs.com/package/ts-node) inside the Docker container to run the application.
Expand All @@ -101,25 +101,27 @@ Now visit [http://localhost:7512](http://localhost:7512) with your browser. You

### Admin Console

We can also use the [Admin Console](https://next-console.kuzzle.io) which allows to manage your data, your users and your rights.
You can also use the [Admin Console](https://next-console.kuzzle.io) which allows you to manage your data, your users and your rights.

::: info
The Admin Console is a [Single Page Application](https://en.wikipedia.org/wiki/Single-page_application) written in Vue.js and using the [Javascript SDK](/sdk/js/7).
No data related to your connection to Kuzzle will pass through our servers.
:::

First, we need to setup a new connection to a Kuzzle application. Open the [Admin Console](http://next-console.kuzzle.io) in your browser and then fill the form as follow:
First, we need to setup a new connection to a Kuzzle application. Open the [Admin Console](http://next-console.kuzzle.io) in your browser and then fill the form as follows:

![Admin Console create connection form](./admin-console-create-connection.png)

Click on `Create Connection` and then select your connection on the dropdown menu.
Click on `Create Connection`, then select your connection on the dropdown menu.

When asked for credentials, just choose `Login as Anonymous`.

You are now connected to your local Kuzzle application with the Admin Console! Everything is empty but we are gonna change that in the next section.
You are now connected to your local Kuzzle application using the Admin Console! Right now you can see that it is devoid of any data or configuration, but we are going to change that in the next section of this guide.

![Admin Console home page](./admin-console-home-page.png)

::: info
The minimum rights required by an user to connect to the Kuzzle Admin Console are:
The minimum rights required for an user to connect to the Kuzzle Admin Console are:

```js
{
Expand Down
Loading

0 comments on commit 0560fc4

Please sign in to comment.