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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16.x, 18.x, 20.x, 22.x]
node: [20.x, 22.x]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ node_modules
*-lock.*
.vscode
lib/
.github/instructions/wmt-copilot.instructions.md
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]

This is an imaginatively named, configurable web server using Fastify atop Node.js.
This is an imaginatively named, configurable web server using Fastify 5.x atop Node.js.

The aim is to provide a standardized node web server that can be used to serve your web
application without the need for duplicating from another example, or starting from scratch.
Expand All @@ -11,7 +11,7 @@ The intention is that you will extend via configuration, such that this provides
functionality of a Fastify web server, and within your own application you will add on the
features, logic, etc unique to your situation.

This module requires Node v16.x.x+.
This module requires Node v20.x.x+ and supports Fastify 5.x.

## Table Of Contents <!-- omit in toc -->

Expand Down Expand Up @@ -212,7 +212,6 @@ Configure electrode provided options.
- A function to install event listeners for the electrode server startup lifecycle.

- The following events are supported:

- `config-composed` - All configurations have been composed into a single one
- `server-created` - Fastify server created
- `plugins-sorted` - Plugins processed and sorted by priority
Expand Down Expand Up @@ -450,11 +449,9 @@ The electrode server exports a single API.

- `config` is the [electrode server config](#configuration-options)
- `decors` - Optional extra `config` or array of `config`. In case you have common config you want to put inside a dedicated module, you can pass them in here.

- If it's an array like `[ decor1, decor2, decor3 ]` then each one is composed into the main config. ie: something similar to `_.merge(mainConfig, decor1, decor2, decor3)`.

- `callback` is an optional errback with the signature `function (err, server)`

- where `server` is the Fastify server

- **Returns:** a promise resolving to the Fastify server if callback is not provided
Expand Down Expand Up @@ -496,7 +493,7 @@ identity (no compression)

```js
server: {
bodyLimit: 1048576; //new size limit
bodyLimit: 1048576; // new size limit in bytes (1MB)
}
```

Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xarc/fastify-server",
"version": "4.0.10",
"version": "5.0.0",
"description": "A configurable Fastify web server",
"main": "lib/index.js",
"types": "./lib/index.d",
Expand Down Expand Up @@ -45,19 +45,19 @@
],
"license": "Apache-2.0",
"engines": {
"node": ">= 14.0.0"
"node": ">= 22.0.0"
},
"files": [
"lib",
"src"
],
"dependencies": {
"@fastify/static": "^7.0.4",
"@fastify/static": "^8.2.0",
"async-eventemitter": "^0.2.4",
"chalk": "^4.1.0",
"electrode-confippet": "^1.7.0",
"fastify": "^4.29.0",
"fastify-plugin": "^4.5.0",
"fastify": "^5.6.1",
"fastify-plugin": "^5.0.1",
"lodash": "^4.17.21",
"require-at": "^1.0.6",
"tslib": "^2.1.0",
Expand All @@ -68,17 +68,18 @@
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/jest": "^29.5.11",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.16",
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@xarc/run": "^1.1.1",
"eslint": "^7.16.0",
"eslint-config-walmart": "^2.2.1",
"eslint-plugin-filenames": "^1.1.0",
"intercept-stdout": "^0.1.2",
"jest": "^29.7.0",
"mitm": "^1.2.0",
"npm-run-all": "4.1.5",
"prettier": "3.2.4",
"prettier": "^3.6.0",
"run-verify": "^1.2.1",
"source-map-support": "^0.5.19",
"superagent": "^9.0.2",
Expand Down
27 changes: 22 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ export type {
} from "fastify";
/* eslint-enable max-len */

export type ServerInfo = {
address: string;
port: number;
};
export type ServerInfo = { address: string; port: number };

export interface ElectrodeFastifyInstance extends FastifyInstance {
info: ServerInfo;
Expand Down Expand Up @@ -204,7 +201,27 @@ export type ElectrodeServerConfig = {
* ```
*/
plugins?: PluginsConfig;
/** options to be passed to fastify verbatim */
/**
* options to be passed to fastify verbatim
*
* **Note for Fastify 5 migration:**
* - `requestIdHeader` now defaults to `false` instead of `"request-id"`
* - Router options like `maxParamLength`, `ignoreTrailingSlash`, etc. should be
* moved under `routerOptions` to avoid deprecation warnings
* - Example:
* ```js
* {
* server: {
* requestIdHeader: false, // explicit default in Fastify 5
* routerOptions: {
* maxParamLength: 1000,
* ignoreTrailingSlash: false,
* caseSensitive: true
* }
* }
* }
* ```
*/
server?: FastifyServerOptions;
/** settings specific to Electrode's add-ons for the fastify server */
electrode?: ElectrodeOptions;
Expand Down
5 changes: 2 additions & 3 deletions test/sample/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable */

"use strict";
const fastifyPlugin = require("fastify-plugin");
const path = require("path");
Expand Down Expand Up @@ -60,4 +58,5 @@ const config = {
});
}
};
require("../../")(config);
const { electrodeServer } = require("../../");
electrodeServer(config);
12 changes: 11 additions & 1 deletion test/spec/check-node-env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ describe("process-env-abbr", function () {
checkNodeEnv();
});

it("should do nothing for undefined NODE_ENV", function () {
delete process.env.NODE_ENV;
checkNodeEnv();
});

it("should do nothing for null NODE_ENV", function () {
process.env.NODE_ENV = null as any;
checkNodeEnv();
});

it("should do nothing for full NODE_ENV", function () {
["production", "staging", "development"].forEach(x => {
["production", "staging", "development", "qa", "test"].forEach(x => {
process.env.NODE_ENV = x;
checkNodeEnv();
});
Expand Down
Loading