Node.JS – Foal framework – version 2.4 is here

Version 2.4 of Foal has been released! Here are the improvements that it brings.

$data references for validation

Version 2.4 allows you to enable the AJV $data option so that you can use the verified data values as validators for other valu…


This content originally appeared on DEV Community and was authored by Loïc Poullain

Version 2.4 of Foal has been released! Here are the improvements that it brings.

$data references for validation

Version 2.4 allows you to enable the AJV $data option so that you can use the verified data values as validators for other values.

config/default.json

{
  "settings": {
    "ajv": {
      "$data": true
    }
  }
}

Example of auth controller

import { Context, Post, ValidateBody } from '@foal/core';

export class AuthController {
  @Post('/signup')
  @ValidateBody({
    type: 'object',
    properties: {
      username: { type: 'string' },
      password: { type: 'string' },
      // "password" and "confirmPassword" should be identical.
      confirmPassword: {
        const: {
          $data: '1/password',
        },
        type: 'string',
      },
    }
    required: [ 'username', 'password', 'confirmPassword' ],
    additionalProperties: false
  })
  signup(ctx: Context) {
    // Do something.
  }
}

Cache option for file downloading

Starting from version 2.4 the Disk.createHttpResponse method accepts an optional parameter to specify the value of the Cache-Control header.

import { Context, dependency, Get } from '@foal/core';
import { Disk } from '@foal/storage';

import { User } from '../entities';

export class ProfileController {
  @dependency
  disk: Disk;

  @Get('/avatar')
  async readProfileImage(ctx: Context<User>) {
    return this.disk.createHttpResponse(ctx.user.avatar, {
      cache: 'no-cache'
    });
  }

Bug fixes

See issue #930.

Contributors

@ZakRabe


This content originally appeared on DEV Community and was authored by Loïc Poullain


Print Share Comment Cite Upload Translate Updates
APA

Loïc Poullain | Sciencx (2021-05-25T13:48:06+00:00) Node.JS – Foal framework – version 2.4 is here. Retrieved from https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/

MLA
" » Node.JS – Foal framework – version 2.4 is here." Loïc Poullain | Sciencx - Tuesday May 25, 2021, https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/
HARVARD
Loïc Poullain | Sciencx Tuesday May 25, 2021 » Node.JS – Foal framework – version 2.4 is here., viewed ,<https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/>
VANCOUVER
Loïc Poullain | Sciencx - » Node.JS – Foal framework – version 2.4 is here. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/
CHICAGO
" » Node.JS – Foal framework – version 2.4 is here." Loïc Poullain | Sciencx - Accessed . https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/
IEEE
" » Node.JS – Foal framework – version 2.4 is here." Loïc Poullain | Sciencx [Online]. Available: https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/. [Accessed: ]
rf:citation
» Node.JS – Foal framework – version 2.4 is here | Loïc Poullain | Sciencx | https://www.scien.cx/2021/05/25/node-js-foal-framework-version-2-4-is-here/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.