Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [22.x, 24.x]

steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand All @@ -43,14 +43,25 @@ jobs:
needs: [build]
if: ${{ startsWith(github.ref, 'refs/tags/') }}
steps:
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
check-latest: true
show-progress: false
- name: Use Node.js 24
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
check-latest: true
node-version: 24
registry-url: 'https://registry.npmjs.org'
registry-url: https://registry.npmjs.org
- run: npm i
- run: npm publish --access public
- name: Determine npm publish tag
id: npm-tag
run: |
VERSION=$(node -p "require('./package.json').version")
if echo "$VERSION" | grep -qE '[-]'; then
echo "tag=next" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
- run: npm publish --access public --tag ${{ steps.npm-tag.outputs.tag }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- `lc39` now supports NodeJS from v22 and above
- Migrate to Fastify@5 and related dependencies. While there are no breaking changes in this library, you might want to get more details about the changes by checking the [Fastify Migration Guide](https://www.fastify.io/docs/latest/Guides/Migration-Guide-V5/)

### Fixed

- use `reply.elapsedTime` instead of the deprecated `reply.getResponseTime()` to get the elapsed time of the request
Expand Down Expand Up @@ -143,7 +146,7 @@ Metrics options are changed. Below there are the main changes. For other configu

* migrated `@fastify/swagger` to `v8`, so that `@fastify/swagger-ui` package is now required to continue exposing Swagger UI
* upgraded fastify plugins to support latest fastify version
* upgraded library dependencies
* upgraded library dependencies

### Changed

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Launch Complex 39

[![Node.js CI][action-status-svg]][github-action]
[![javascript style guide][standard-mia-svg]][standard-mia]
[![javascript style guide][standard-mia-svg]][standard-mia]
[![Coverage Status][coverall-svg]][coverall-io]
[![NPM version][npmjs-svg]][npmjs-com]

Expand All @@ -24,13 +24,15 @@ To install the package you can run:
npm install @mia-platform/lc39 --save
```

It is possible to install the next version of the package, which use fastify v3. The version is a release candidate,
so it is not yet a stable version and should not be used in production environments (next updates could be breaking).
To try it, you can run:
The following table shows the supported versions of Fastify for each version of lc39:

```sh
npm install @mia-platform/lc39@next --save
```
| lc39 version | Fastify version |
|--------------|-----------------|
| v9 | 5.x.x |
| v8 | 4.x.x |
| v6 | 3.x.x |

You can check the [CHANGELOG](./CHANGELOG.md) for more details about the changes in each version.

We recommend to install the module locally on every one of your project to be able to
update them indipendently one from the other. To use the locally installed instance you
Expand Down
4 changes: 2 additions & 2 deletions lib/launch-fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const fp = require('fastify-plugin')
const fastifySwagger = require('@fastify/swagger')
const fastifySwaggerUI = require('@fastify/swagger-ui')
const fastifySensible = require('@fastify/sensible')
const lget = require('lodash.get')
const { get: lget } = require('lodash')

const absolutePath = require('./absolute-path')
const customLogger = require('./custom-logger')
Expand Down Expand Up @@ -97,7 +97,7 @@ async function launchFastifyWithFile(file, options, address) {
return launchFastify(serviceModule, options, address)
}

async function launchFastify(serviceModule, options, address) {
async function launchFastify(serviceModule, /** @type {import('fastify').FastifyHttpOptions} */ options, address) {
const moduleOptions = serviceModule.options || {}
const mergedOptions = {
exposeDocumentation: true,
Expand Down
46 changes: 41 additions & 5 deletions lib/options-extractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@
function defaultFastifyOptions() {
return {
return503OnClosing: false,
ignoreTrailingSlash: false,
caseSensitive: true,
routerOptions: {
ignoreTrailingSlash: false,
caseSensitive: true,
},
// /**
// * @deprecated
// * The router options for caseSensitive, ignoreTrailingSlash property access is deprecated.
// * Please use "options.routerOptions" instead
// */
// caseSensitive: true,
// /**
// * @deprecated
// * The router options for caseSensitive, ignoreTrailingSlash property access is deprecated.
// * Please use "options.routerOptions" instead
// */
// ignoreTrailingSlash: false,
// use “legacy” header version with prefixed x- for better compatibility with existing enterprises infrastructures
requestIdHeader: 'x-request-id',
// set 30 seconds to
Expand All @@ -31,18 +45,40 @@ function defaultFastifyOptions() {
}
}

function exportFastifyOptions(moduleOptions) {
return { ...defaultFastifyOptions(), ...moduleOptions }
function exportFastifyOptions(/** @type {import('fastify').FastifyServerOptions} options */ moduleOptions) {
// NOTE: solves deprecation issue of caseSensitive and ignoreTrailingSlash properties in Fastify 5
// by moving them inside routerOptions, as expected from Fastify@6
const { caseSensitive, ignoreTrailingSlash } = moduleOptions || {}
const defaultOptions = defaultFastifyOptions()

const opts = {
...defaultOptions,
...moduleOptions,
routerOptions: {
...moduleOptions.routerOptions,
caseSensitive: caseSensitive || defaultOptions.routerOptions.caseSensitive,
ignoreTrailingSlash: ignoreTrailingSlash || defaultOptions.routerOptions.ignoreTrailingSlash,
},
}

delete opts.caseSensitive
delete opts.ignoreTrailingSlash

return opts
}

function exportServiceOptions(options) {
const fastifyPluginOptions = {}
const { prefix, envVariables } = options
const { prefix, envVariables, validationCompiler } = options

if (prefix) {
fastifyPluginOptions.prefix = prefix
}

if (validationCompiler) {
fastifyPluginOptions.validationCompiler = validationCompiler
}

Object
.keys(envVariables || {})
.forEach(key => { fastifyPluginOptions[key] = envVariables[key] })
Expand Down
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mia-platform/lc39",
"version": "8.0.2",
"version": "9.0.0-rc.5",
"description": "The Mia-Platform Node.js service launcher",
"keywords": [
"cli",
Expand Down Expand Up @@ -40,33 +40,32 @@
"test:types": "tsd"
},
"dependencies": {
"@fastify/sensible": "^5.5.0",
"@fastify/swagger": "^8.12.0",
"@fastify/swagger-ui": "^1.10.1",
"@opentelemetry/auto-instrumentations-node": "^0.49.1",
"@opentelemetry/sdk-node": "^0.52.1",
"@opentelemetry/sdk-trace-base": "^1.25.1",
"@fastify/sensible": "^6.0.4",
"@fastify/swagger": "^9.7.0",
"@fastify/swagger-ui": "^5.2.5",
"@opentelemetry/auto-instrumentations-node": "^0.70.1",
"@opentelemetry/sdk-node": "^0.212.0",
"@opentelemetry/sdk-trace-base": "^2.5.1",
"commander": "^11.1.0",
"dotenv": "^16.3.1",
"dotenv-expand": "^11.0.3",
"fastify": "^4.28.1",
"fastify-metrics": "^10.3.3",
"fastify-plugin": "^4.5.1",
"lodash.get": "^4.4.2",
"prom-client": "^14.2.0"
"fastify": "^5.7.4",
"fastify-metrics": "^12.1.0",
"fastify-plugin": "^5.1.0",
"lodash": "^4.17.23",
"prom-client": "^15.1.3"
},
"devDependencies": {
"@mia-platform/eslint-config-mia": "^3.0.0",
"ajv": "^8.17.1",
"ajv": "^8.18.0",
"eslint": "^8.53.0",
"semver": "^7.6.3",
"split2": "^4.2.0",
"swagger-parser": "^10.0.3",
"tap": "^21.0.1",
"tsd": "^0.31.1"
},
"engines": {
"node": ">=14"
"node": ">=22"
},
"eslintConfig": {
"extends": "@mia-platform/eslint-config-mia"
Expand Down
12 changes: 10 additions & 2 deletions tests/documentation-routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ test('Test Fastify creation with no prefix', async assert => {
url: '/documentation/static/index.html',
})

assert.strictSame(textResponse.statusCode, 200)
assert.strictSame(textResponse.headers['content-type'], 'text/html; charset=utf-8')
assert.strictSame(textResponse.statusCode, 302)
assert.strictSame(textResponse.headers.location, '/documentation/')

const htmlResponse = await fastifyInstance.inject({
method: 'GET',
url: '/documentation/',
})

assert.strictSame(htmlResponse.statusCode, 200)
assert.strictSame(htmlResponse.headers['content-type'], 'text/html; charset=utf-8')
assert.matchSnapshot(JSON.parse(jsonResponse.body))

const { statusCode } = await fastifyInstance.inject({
Expand Down
Loading
Loading