Giter VIP home page Giter VIP logo

fastify-formbody's Introduction

@fastify/formbody

CI NPM version NPM downloads JavaScript Style Guide

A simple plugin for Fastify that adds a content type parser for the content type application/x-www-form-urlencoded.

This branch targets Fastify v4. Please refer to this branch and related versions for Fastify ^2.0.0 compatibility.

For Fastify v3 support, please use @fastify/formbody ^6.0.1.

Install

npm i @fastify/formbody

Example

Given the following code:

const fastify = require('fastify')()

fastify.register(require('@fastify/formbody'))

fastify.post('/', (req, reply) => {
  reply.send(req.body)
})

fastify.listen({ port: 8000 }, (err) => {
  if (err) throw err
})

And a POST body of:

foo=foo&bar=bar&answer=42

The sent reply would be the object:

{
  foo: 'foo',
  bar: 'bar',
  answer: 42
}

Options

The plugin accepts an options object with the following properties:

  • bodyLimit: The maximum amount of bytes to process before returning an error. If the limit is exceeded, a 500 error will be returned immediately. When set to undefined the limit will be set to whatever is configured on the parent Fastify instance. The default value is whatever is configured in fastify (1048576 by default).
  • parser: The default parser used is the querystring.parse built-in. You can change this default by passing a parser function e.g. fastify.register(require('@fastify/formbody'), { parser: str => myParser(str) })

Upgrading from 4.x

Previously, the external qs lib was used that did things like parse nested objects. For example:

  • Input: foo[one]=foo&foo[two]=bar
  • Parsed: { foo: { one: 'foo', two: 'bar' } }

The way this is handled now using the built-in querystring.parse:

  • Input: foo[one]=foo&foo[two]=bar
  • Parsed: { 'foo[one]': 'foo', 'foo[two]': 'bar' }

If you need nested parsing, you must configure it manually by installing the qs lib (npm i qs), and then configure an optional parser:

const fastify = require('fastify')()
const qs = require('qs')
fastify.register(require('@fastify/formbody'), { parser: str => qs.parse(str) })

License

Licensed under MIT

fastify-formbody's People

Contributors

anonrig avatar cemremengu avatar cmawhorter avatar crisli avatar delvedor avatar dependabot-preview[bot] avatar dependabot[bot] avatar eomm avatar ethan-arrowood avatar fdawgs avatar frikille avatar ghostd avatar github-actions[bot] avatar greenkeeper[bot] avatar jsumners avatar lependu avatar mcollina avatar nwoltman avatar onosendi avatar pmmmwh avatar salmanm avatar serayaeryn avatar sinchang avatar uzlopak avatar vincent178 avatar wlinna avatar zekth avatar

Stargazers

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

Watchers

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

fastify-formbody's Issues

Publish new patch version?

🚀 Feature Proposal

Not really a feature, but would you mind publishing a new version of this plugin? Particulary, to bump it's dependency on fastify-plugin from ^2.0.0 to ^3.0.0.

Motivation

To remove the "fastify not found, proceeding anyway" messages in stdout that are generated by fastify-plugin version < 3.

Example

N/A

Example doesn't work

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.2.0

Plugin version

7.0.1

Node.js version

16.2.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Monterey 12.4

Description

Example
Given the following code:

const fastify = require('fastify')()

fastify.register(require('@fastify/formbody'))

fastify.post('/', (req, reply) => {
  reply.send(req.body)
})

fastify.listen(8000, (err) => {
  if (err) throw err
})

The given example fails to work with

AvvioError [Error]: Plugin must be a function or a promise. Received: 'object'
    at assertPlugin (*/node_modules/avvio/boot.js:207:11)
    at Boot._addPlugin (*/node_modules/avvio/boot.js:240:12)
    at Boot.use (*/node_modules/avvio/boot.js:216:25)
    at Object.server.<computed> [as register] (*/node_modules/avvio/boot.js:40:14)
    at runFastify (*/node_modules/fastify-cli/start.js:138:17)
    at async main (*/node_modules/fastify-cli/lib/watch/fork.js:40:13) {
  code: 'AVV_ERR_PLUGIN_NOT_VALID'
}

Steps to Reproduce

fastify generate project
cd project
copy example code into app.js
install plugin
run

Expected Behavior

Example code works.

Also, using fastify generate project and adding fastify.register(require('@fastify/formbody')) to app.js or to routes/root.js doesn't seem to work either.
Seems like no matter where I put it in the code it doesn't work so is there an issue with using fastify generate?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Don't update dependencies with only a patch version change

npm by default allows patch version updates to happen transparently. When you update the fastify version, fastify checks itself for incompatible version numbers. Therefore, if I depend on both this package and fastify, I will randomly get messages like this:

Error: fastify-plugin - expected '>=1.0.0-rc.1' fastify version, '0.39.1' is installed

Incompatible (really any) dependency version updates MUST be included in something larger than a patch release.

On a side note, is an update to an RC build really necessary in the first place?

An in-range update of request is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 2.84.0 of request was just published.

Branch Build failing 🚨
Dependency request
Current Version 2.83.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

request is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 6 commits.

  • d77c839 Update changelog
  • 4b46a13 2.84.0
  • 0b807c6 Merge pull request #2793 from dvishniakov/2792-oauth_body_hash
  • cfd2307 Update hawk to 7.0.7 (#2880)
  • efeaf00 Fixed calculation of oauth_body_hash, issue #2792
  • 253c5e5 2.83.1

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

415 Unsupported Media Type: application/x-www-form-urlencoded

🐛 Bug Report

When I try to POST my /session page (basically my login page) with the needed data, the server gets me the following error:
{"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE","error":"Unsupported Media Type","message":"Unsupported Media Type: application/x-www-form-urlencoded"}

To Reproduce

Steps to reproduce the behavior:

I have 5 files that can be needed to reproduce the bug:

index.js

// Use .env
require('dotenv').config();

// Import modules
const fastify = require('fastify');

// Create app
const app = fastify();

// Launch RestAPI routes
app.register(require("./api/routes"));

// Register fastify modules
app.register(require('fastify-static'), {
    root: __dirname+"/views",
});
app.register(require('fastify-formbody'));
app.register(require('fastify-cookie'));
app.register(require('fastify-session'), {secret: process.env.SESSION_SECRET});

// Listen
app.listen(process.env.PORT || 3000, (error) => {
    if (error) throw error;
});

views/login.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello!</title>
    <script>
        window.onload = () => {
            const urlParams = new URLSearchParams(window.location.search);
            const msg = urlParams.get("message");
            const prefill = urlParams.get("prefill");
            if (prefill) {
                document.getElementById("username").value = prefill;
            }
            if (msg) {
                document.getElementById("message").value = msg;
            }
        }
    </script>
</head>
<body>
    <center>
        <h1>Hey!</h1>
        <h3>Please login using your creditentials</h3>
        <h4 id="message" style="color: red;"></h4>
        <form action="/session" method="POST">
            <input type="text" name="username" placeholder="Username" id="username">
            <input type="password" name="password" placeholder="Password" id="password">
            <br/>
            <input type="submit" value="Log in">
        </form>
    </center>
</body>
</html>

api/routes.js

module.exports = (fastify, opts, done) => {
    fastify.get("/login", require('./routes/loginPage'));
    fastify.post("/session", require('./routes/session'));
    done();
};

api/routes/loginPage.js

module.exports = (req, res) => {
    res.sendFile("login.html");
}

api/routes/session.js

module.exports = (req, res) => {
    console.log(req.body);
    const { username, password } = req.body;
    if (!username || !password) {
        let url = "/login?message=Some%20fields%20are%20missing";
        if (username) url+=`&prefill=${username}`;
        res.redirect(url);
        return;
    }
}

Then, after installing the packages (npm i --s fastify fastify-formbody fastify-static fastify-cookie fastify-session dotenv), do node index, then go to http://127.0.0.1:3000/login, type anything and press Login. This should give you the error.

Expected behavior

Wellll, as my login page is not done, I test it without putting the password, so it should redirect me to http://127.0.0.1:3000/login?message=Some%20fields%20are%20missing&prefill=myusername. But it doesnt

Your Environment

  • node version: 14.4.0
  • fastify version: 3.7.0
  • os: Windows

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

npm package still pointing "[email protected]"

Hello,

Following this PR, master branch includes fastify ^3.0.0-alpha.1 as devDependencies but when installing with npm ( npm install), it's still using fastify 2.0.0-rc.3 as devDependencies.

As fastify v3 is not yet released as default version maybe that's on purpose. For now I just install the package directly using your repo.

Thank you.

Argument of type FastifyPluginCallback<...> is not assignable to parameter of type FastifyPluginCallback<...>

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.5.3

Plugin version

7.1.0

Node.js version

v16.16.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.5

Description

Registering imported FastifyFormbody to Fastify instance gives casting errors.

Here full casting error:


No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProvider>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProviderDefault>' is not assignable to parameter of type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProvider>'.
      Types of parameters 'instance' and 'instance' are incompatible.
        Type 'FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyBaseLogger, FastifyTypeProvider>' is not assignable to type 'FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault>'.
          Types of property 'log' are incompatible.
            Type 'FastifyBaseLogger' is not assignable to type 'FastifyLoggerInstance'.
              Type 'FastifyBaseLogger' is missing the following properties from type 'LoggerExtras<LoggerOptions>': version, levels, useLevelLabels, customLevels, and 21 more.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<FormBodyPluginOptions, Server, FastifyTypeProvider>, opts?: FastifyRegisterOptions<FormBodyPluginOptions> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProviderDefault>' is not assignable to parameter of type 'FastifyPluginAsync<FormBodyPluginOptions, Server, FastifyTypeProvider>'.
  Overload 3 of 3, '(plugin: FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProvider> | FastifyPluginAsync<FormBodyPluginOptions, Server, FastifyTypeProvider> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProviderDefault>' is not assignable to parameter of type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProvider> | FastifyPluginAsync<FormBodyPluginOptions, Server, FastifyTypeProvider> | Promise<...> | Promise<...>'.
      Type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProviderDefault>' is not assignable to type 'FastifyPluginCallback<FormBodyPluginOptions, Server, FastifyTypeProvider>'.ts(2769)

Steps to Reproduce

import FastifyFormbody from '@fastify/formbody'

// Casting error occurs here
server.register(FastifyFormbody)

Expected Behavior

No casting error should occur, it should be exactly compatible types.

fastify-formbody has been deprecated.

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.29.0

Plugin version

idk

Node.js version

14.18.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Linux Mint 20.2 Cinnamon

Description

I dont import/install fastify-formbody in any place of my project, but I got the following error:

(node:31444) [FST_MODULE_DEP_FASTIFY-FORMBODY] FastifyWarning.fastify-formbody: fastify-formbody has been deprecated. Use @fastify/[email protected] instead.
(Use `node --trace-warnings ...` to show where the warning was created)

Its prob a import from another lib.

Steps to Reproduce

Install the libs with the following versions and try to run the code.
My package.json file:

  "dependencies": {
    "@fastify/compress": "^5.0.0",
    "@fastify/cors": "^7.0.0",
    "@fastify/helmet": "^8.1.0",
    "@fastify/request-context": "^3.0.0",
    "@fastify/static": "5.0.2",
    "@fastify/swagger": "^6.1.0",
    "@nestjs/axios": "^0.0.8",
    "@nestjs/common": "^8.4.6",
    "@nestjs/config": "^2.0.1",
    "@nestjs/core": "^8.4.6",
    "@nestjs/platform-fastify": "^8.4.6",
    "@nestjs/swagger": "^5.2.1",
    "@nestjs/terminus": "^8.0.6",
    "@newrelic/winston-enricher": "^3.1.1",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.13.2",
    "cli-color": "^2.0.2",
    "fastify": "3.29.0",
    "lodash": "^4.17.21",
    "newrelic": "^8.13.2",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.5",
    "winston": "^3.7.2"
  },
  "devDependencies": {
    "@commitlint/cli": "^17.0.1",
    "@commitlint/config-conventional": "^17.0.0",
    "@compodoc/compodoc": "^1.1.19",
    "@nestjs/cli": "^8.2.6",
    "@nestjs/schematics": "^8.0.11",
    "@nestjs/testing": "^8.4.5",
    "@types/cli-color": "^2.0.2",
    "@types/jest": "^27.5.1",
    "@types/lodash": "^4.14.182",
    "@types/newrelic": "^7.0.3",
    "@types/node": "^17.0.36",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.26.0",
    "@typescript-eslint/parser": "^5.26.0",
    "commitizen": "^4.2.4",
    "eslint": "^8.16.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-prettier": "^4.0.0",
    "husky": "^8.0.1",
    "is-ci": "^3.0.1",
    "jest": "^27.5.1",
    "lint-staged": "^12.4.3",
    "prettier": "^2.6.2",
    "sonarqube-scanner": "^2.8.1",
    "source-map-support": "^0.5.21",
    "supertest": "^6.2.3",
    "ts-jest": "^27.1.5",
    "ts-loader": "^9.3.0",
    "ts-node": "^10.8.0",
    "tsconfig-paths": "^4.0.0",
    "typescript": "^4.7.2"
  },

My main.ts file

require('newrelic');

import compression from '@fastify/compress';
import cors from '@fastify/cors';
import helmet from '@fastify/helmet';
import { fastifyRequestContextPlugin } from '@fastify/request-context';
import {
  ClassSerializerInterceptor,
  INestApplication,
  Logger,
  LogLevel,
  ValidationPipe,
  VersioningType,
} from '@nestjs/common';
import { NestFactory, Reflector } from '@nestjs/core';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { useContainer } from 'class-validator';
import fastify from 'fastify';
import { AppModule } from './app.module';
import {
  fastifyRequestIdHookHandler,
  HttpExceptionFilter,
  REQUEST_ID_HEADER_KEY,
  WinstonLogger,
} from './common';
import {
  PROJECT_DESCRIPTION,
  PROJECT_NAME,
  PROJECT_VERSION,
} from './constants';


/**
 * Default port number.
 */
const DEFAULT_PORT = 8080;

/**
 * Default base url endpoint for api.
 */
const DEFAULT_API_PREFIX = '/api';

/**
 * Default api version.
 */
const DEFAULT_API_VERSION = '1';

/**
 * Default url endpoint for Swagger UI.
 */
const DEFAULT_SWAGGER_PREFIX = '/docs';

/**
 * Default bootstrap log level.
 */
const DEFAULT_BOOTSTRAP_LOG_LEVEL = 'warn';

/**
 * Setup the Swagger (UI).
 *
 * @param app
 */

const loggerInstance = new Logger('main');
export const setupSwagger = (app: INestApplication) => {
  const options = new DocumentBuilder()
    .setTitle(PROJECT_NAME)
    .setDescription(PROJECT_DESCRIPTION)
    .setVersion(PROJECT_VERSION)
    .build();

  const document = SwaggerModule.createDocument(app, options);
  const path = process.env.SWAGGER_PREFIX || DEFAULT_SWAGGER_PREFIX;

  SwaggerModule.setup(path, app, document);
};

/**
 * Bootstrap the app.
 */
async function bootstrap() {
  const fastifyInstance = fastify({
    ignoreTrailingSlash: true,
    requestIdHeader: REQUEST_ID_HEADER_KEY,
  });

  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(fastifyInstance),
    {
      logger: [
        (process.env.LOG_LEVEL || DEFAULT_BOOTSTRAP_LOG_LEVEL) as LogLevel,
      ],
      abortOnError: false,
    },
  );

  app.enableVersioning({
    type: VersioningType.URI,
    defaultVersion: process.env.API_VERSION || DEFAULT_API_VERSION,
  });
  loggerInstance.debug(process.env.NEW_RELIC_LICENSE_KEY);
  app.register(fastifyRequestContextPlugin);
  app.useLogger(app.get(WinstonLogger));
  app.setGlobalPrefix(process.env.PREFIX || DEFAULT_API_PREFIX);

  fastifyInstance.addHook('onRequest', fastifyRequestIdHookHandler);
  setupSwagger(app);

  app.register(cors);
  app.register(compression);
  app.register(helmet, {
    contentSecurityPolicy: {
      directives: {
        defaultSrc: [`'self'`],
        styleSrc: [`'self'`, `'unsafe-inline'`],
        imgSrc: [`'self'`, 'data:', 'validator.swagger.io'],
        scriptSrc: [`'self'`, `https: 'unsafe-inline'`],
      },
    },
  });

  useContainer(app.select(AppModule), { fallbackOnErrors: true });

  app.useGlobalPipes(
    new ValidationPipe({
      transform: true,
      whitelist: true,
      forbidUnknownValues: true,
      transformOptions: {
        enableImplicitConversion: true,
      },
    }),
  );
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalInterceptors(
    new ClassSerializerInterceptor(app.get<Reflector>(Reflector), {
      enableImplicitConversion: true,
    }),
  );
  await app.listen(process.env.PORT || DEFAULT_PORT, '0.0.0.0');
}

// Start the app
bootstrap().catch((error) => loggerInstance.error(error));

Expected Behavior

Run without the error:

(node:32394) [FST_MODULE_DEP_FASTIFY-FORMBODY] FastifyWarning.fastify-formbody: fastify-formbody has been deprecated. Use @fastify/[email protected] instead.
(Use `node --trace-warnings ...` to show where the warning was created)

Use node builtin qs for parsing or add to readme noting the differences

🚀 Feature Proposal

Fastify defaults to using the builtin qs for parsing and I expected this plugin to behave the same.

The readme should at least call this fact out and it'd be nice if it be changed to mirror the behavior of fastify with defaulting to node built-in, but allowing optional custom parser.

Motivation

It's unexpected that the same data passed via querystring and this plugin would be parsed differently.

GET /?hello[one]=a&hello[two]=b is transformed into { 'hello[one]': 'a', 'hello[two]': 'b' }
POST / with body hello[one]=a&hello[two]=b is transformed into { hello: { one: a, two: b } }

Example

By using the same parser, both req.query and req.body would have identical output for the same input which feels right to me.

Does this plugin only echo the request body?

I try to use this plugin with the demo code in the README.md.

My testing result is that only request body echoes back, even I change the logic of my handler.

fastify.register(require('fastify-formbody'), {}, (err) => {
  if (err) throw err
})

fastify.post('/', (req, reply) => {
  console.log(req.body); // not log here.
  reply.send({}) // should return an empty json, but still the content of request body.
})

fastify.listen(9001, (err) => {
  if (err) throw err;
  console.log('server listen on 9001');
});

Issue v5 release

The next branch should be ready for issuing a release to coincide with fastify@5.

Cannot use this plugin on fastify 3.x.x

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.29.0

Plugin version

7.0.1 - 7.0.0

Node.js version

16.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

ArchLinux

Description

On task startup I obtain this error:

fastify-plugin: @fastify/formbody - expected '4.x' fastify version, '3.29.0' is installed

I think that this check is wrong (this version must be compatible with Fastify 3.xx)

Steps to Reproduce

const Fastify = require("fastify");
const Formbody = require('@fastify/formbody');
const server = Fastify({
      connectionTimeout: 20 * 1000,
      logger: false
});
server.register(Formbody);
server.listen(3000,"0.0.0.0",(err,address)=>{
    if (err)
        throw err;
   else 
       console.log( "Server is active");
});

Expected Behavior

Plugin works as expected using Fastify v3.xx

ChainAlert: npm package release (5.3.0) has no matching tag in this repo

Dear fastify-formbody maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new version (5.3.0) of fastify-formbody was published without a matching tag in this repo.

As part of our efforts to fight software supply chain attacks, we would like to verify this release is known and intended, and not a result of an unauthorized activity.

If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

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.