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
14 changes: 14 additions & 0 deletions .changesets/109.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- feat(deps): Upgrade (#109) by @Tobbe

This PR is a breaking change. It upgrades Fastify from v4 to v5, so if you're
running CedarJS in a serverful environment you should look through your Fastify
specific code.

Note: For v5 Fastify changed how you pass in a custom logger. CedarJS already
had that code somewhat customized, so for this PR we kept the unified `logger`
option we already had, so there should be no change for you in that regards,
but we will probably break this appart in the future to match what Fastify is
doing

See [the Fastify v5 migration docs](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/)
for all the details.
8 changes: 4 additions & 4 deletions packages/adapters/fastify/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
},
"dependencies": {
"@cedarjs/project-config": "workspace:*",
"@fastify/http-proxy": "9.5.0",
"@fastify/static": "6.12.0",
"@fastify/url-data": "5.4.0",
"@fastify/http-proxy": "11.1.2",
"@fastify/static": "8.2.0",
"@fastify/url-data": "6.0.3",
"fast-glob": "3.3.2"
},
"devDependencies": {
"@cedarjs/framework-tools": "workspace:*",
"fastify": "4.28.1",
"fastify": "5.3.3",
"tsx": "4.19.3",
"typescript": "5.6.2",
"vitest": "2.1.9"
Expand Down
20 changes: 10 additions & 10 deletions packages/adapters/fastify/web/src/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/html; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/html; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(path.join(getPaths().web.dist, `${url}.html`), 'utf-8'),
)
Expand All @@ -66,7 +66,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/html; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/html; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(path.join(getPaths().web.dist, `${url}.html`), 'utf-8'),
)
Expand All @@ -83,7 +83,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/html; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/html; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(path.join(getPaths().web.dist, `${url}.html`), 'utf-8'),
)
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/html; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/html; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(path.join(getPaths().web.dist, url), 'utf-8'),
)
Expand All @@ -135,7 +135,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/html; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/html; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(path.join(getPaths().web.dist, '200.html'), 'utf-8'),
)
Expand All @@ -153,7 +153,7 @@ describe('redwoodFastifyWeb', () => {

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe(
'application/javascript; charset=UTF-8',
'application/javascript; charset=utf-8',
)
expect(res.body).toBe(
fs.readFileSync(
Expand All @@ -172,7 +172,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/css; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/css; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(
path.join(getPaths().web.dist, relativeFilePath),
Expand All @@ -191,7 +191,7 @@ describe('redwoodFastifyWeb', () => {

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe(
'application/json; charset=UTF-8',
'application/json; charset=utf-8',
)
expect(res.body).toBe(
fs.readFileSync(
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/markdown; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/markdown; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(
path.join(getPaths().web.dist, relativeFilePath),
Expand All @@ -238,7 +238,7 @@ describe('redwoodFastifyWeb', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/plain; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/plain; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(
path.join(getPaths().web.dist, relativeFilePath),
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/fastify/web/src/webFallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('webFallback', () => {
})

expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toBe('text/html; charset=UTF-8')
expect(res.headers['content-type']).toBe('text/html; charset=utf-8')
expect(res.body).toBe(
fs.readFileSync(path.join(getPaths().web.dist, url), 'utf-8'),
)
Expand Down
9 changes: 5 additions & 4 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
"@cedarjs/internal": "workspace:*",
"@cedarjs/project-config": "workspace:*",
"@cedarjs/web-server": "workspace:*",
"@fastify/multipart": "8.3.1",
"@fastify/url-data": "5.4.0",
"@fastify/multipart": "9.0.3",
"@fastify/url-data": "6.0.3",
"chalk": "4.1.2",
"chokidar": "3.6.0",
"dotenv-defaults": "5.0.2",
"fast-glob": "3.3.2",
"fast-json-parse": "1.0.3",
"fastify": "4.28.1",
"fastify-raw-body": "4.3.0",
"fastify": "5.3.3",
"fastify-raw-body": "5.0.0",
"lodash": "4.17.21",
"pretty-bytes": "5.6.0",
"pretty-ms": "7.0.1",
Expand All @@ -57,6 +57,7 @@
"@types/qs": "6.9.16",
"@types/split2": "4.2.3",
"@types/yargs": "17.0.33",
"memfs": "4.17.2",
"pino-abstract-transport": "1.2.0",
"tsx": "4.19.3",
"typescript": "5.6.2",
Expand Down
1 change: 0 additions & 1 deletion packages/api-server/src/__tests__/createServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ describe('createServer', () => {
level: 30,
msg: 'incoming request',
req: {
hostname: 'localhost:80',
method: 'GET',
remoteAddress: '127.0.0.1',
url: '/hello',
Expand Down
25 changes: 20 additions & 5 deletions packages/api-server/src/createServerHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ export interface CreateServerOptions {
/** The prefix for all routes. Defaults to `/` */
apiRootPath?: string

// TODO: This should probably be split, to match Fastify's way of doing things
/** Logger instance or options */
logger?: FastifyServerOptions['logger']
logger?:
| FastifyServerOptions['logger']
| FastifyServerOptions['loggerInstance']

/**
* Options for the fastify server instance.
Expand Down Expand Up @@ -74,23 +77,29 @@ type ResolvedOptions = Required<
}
>

function isCustomLoggerInstance(
logger:
| FastifyServerOptions['logger']
| FastifyServerOptions['loggerInstance'],
): logger is FastifyServerOptions['loggerInstance'] {
return !!logger && typeof logger === 'object' && 'info' in logger
}

export function resolveOptions(
options: CreateServerOptions = {},
args?: string[],
) {
options.parseArgs ??= true

const defaults = getDefaultCreateServerOptions()

options.logger ??= defaults.logger
const logger = options.logger ?? defaults.logger

// Set defaults.
const resolvedOptions: ResolvedOptions = {
apiRootPath: options.apiRootPath ?? defaults.apiRootPath,

fastifyServerOptions: options.fastifyServerOptions ?? {
requestTimeout: defaults.fastifyServerOptions.requestTimeout,
logger: options.logger ?? defaults.logger,
bodyLimit: defaults.fastifyServerOptions.bodyLimit,
},
configureApiServer:
Expand All @@ -100,9 +109,15 @@ export function resolveOptions(
}

// Merge fastifyServerOptions.

resolvedOptions.fastifyServerOptions.requestTimeout ??=
defaults.fastifyServerOptions.requestTimeout
resolvedOptions.fastifyServerOptions.logger = options.logger

if (isCustomLoggerInstance(logger)) {
resolvedOptions.fastifyServerOptions.loggerInstance = logger
} else {
resolvedOptions.fastifyServerOptions.logger = logger
}

if (options.parseArgs) {
const { values } = parseArgs({
Expand Down
2 changes: 1 addition & 1 deletion packages/web-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@cedarjs/project-config": "workspace:*",
"chalk": "4.1.2",
"dotenv-defaults": "5.0.2",
"fastify": "4.28.1",
"fastify": "5.3.3",
"fs-extra": "11.2.0",
"yargs": "17.7.2"
},
Expand Down
Loading
Loading