Code Monkey home page Code Monkey logo

edifice-tiptap-transformer's Introduction

Rich content transformer

In Docker

docker-compose up -d content-transformer --build

Without Docker

Installation

pnpm i

Customization

Execute the following command :

cp .env.template .env

Then modify .env file to suit your needs (all variables are optional and can be removed) :

  • PORT (default: 3000): port number on which the service is listening for transformation request
  • METRICS_PORT (default: 3001): port number on which the service is listening to serve the metrics
  • NB_THREADS (default: number of CPUs): number of concurrent services that will handle transformation requests. In development environments it is best to set this value to 1. In production, it should be set to the number of available CPUs (or removed from .env file, which will have the same effect)
  • MAX_BODY_SIZE (default: 2mb): the maximum size of a request body. Beyond the specified limit, the request will be rejected.

Build

pnpm run build

Local run

pnpm run dev

Call samples

To transform an HTML to JSON:

curl -L -X POST 'http://localhost:3000/transform' -H 'Content-Type: application/json' -d '{
    "requestedFormats": ["json"],
    "contentVersion": 0,
    "htmlContent": "<span>Le lorem ipsum est, en imprimerie, une suite de mots sans signification utilisée à titre provisoire pour calibrer une mise en page<br><h1>Hello world</h1><br><a href=\"https://www.website.com\">Website</a>"
}'

To transform an HTML to PLAIN TEXT:

curl -L -X POST 'http://localhost:3000/transform' -H 'Content-Type: application/json' -d '{
    "requestedFormats": ["plainText"],
    "contentVersion": 0,
    "htmlContent": "<span>Le lorem ipsum est, en imprimerie, une suite de mots sans signification utilisée à titre provisoire pour calibrer une mise en page<br><h1>Hello world</h1><br><a href=\"https://www.website.com\">Website</a>"
}'

To clean an HTML:

curl -L -X POST 'http://localhost:3000/transform' -H 'Content-Type: application/json' -d '{
    "requestedFormats": ["html"],
    "contentVersion": 0,
    "htmlContent": "<span>Le lorem ipsum est, en imprimerie, une suite de mots sans signification utilisée à titre provisoire pour calibrer une mise en page<br><h1>Hello world</h1><br><a href=\"https://www.website.com\">Website"
}'

To transform a JSON to HTML and PLAIN TEXT:

curl -L -X POST 'http://localhost:3000/transform' -H 'Content-Type: application/json' -d '{
    "requestedFormats": [
        "html",
        "plainText"
    ],
    "contentVersion": 0,
    "jsonContent": {
        "type": "doc",
        "content": [
            {
                "type": "paragraph",
                "attrs": {
                    "textAlign": "left"
                },
                "content": [
                    {
                        "type": "text",
                        "text": "Le lorem ipsum est, en imprimerie, une suite de mots sans signification utilisée à titre provisoire pour calibrer une mise en page"
                    }
                ]
            }
        ]
    }
}'

To access metrics:

curl -L -X GET 'http://localhost:3000/metrics'

Healthcheck :

curl -L -X GET 'http://localhost:3000/healthcheck'

Load testing

Description

Load testing are run by launching load-tester container. This container can be customized by changing its environment variables :

  • ROOT_URL, the root URL of the content transformer to load test (shoul be kept to http://content-transformer:3000 to test your local service)
  • DATA_ROOT_PATH, should not be changed
  • DURATION, the duration of the test
  • VUS, the number of virtual users (see official documentation for more information)

Execution

docker-compose up -d content-transformer --build # To start your container with the latest version of your local source
docker-compose run --rm load-tester run src/index.js # Starts the tests

Extension

To add more files to the test set, add html files in test/data/big or test/data/small (depending on its size) and make sure to change the way smallHtmls and bigHtmls are loaded in index.ts.

edifice-tiptap-transformer's People

Contributors

ccreusat avatar jcbe-ode avatar juniorode avatar mariusode avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.