fix(templates): boot the Fastify starter on an empty PORT and a prod install - #31
Merged
Merged
Conversation
…install
Two ways the Fastify starter came up wrong, both outside what the build and lint
catch.
PORT was read with `??`, which only guards null and undefined. An empty `PORT=`
in .env reached `Number("")`, which is 0, and Fastify binds port 0 to a random
free port, so the API started somewhere nobody was looking instead of on 3000.
Reading it with `||` treats the empty value as missing, matching the Express
starter.
pino-pretty moves to dependencies. The logger wires it up for any NODE_ENV other
than production, so `npm ci --omit=dev`, the usual shape of a staging deploy,
left the transport target unresolvable and the process died on startup. It is a
runtime dependency in every environment that loads it.
Verified with npm run validate, and with npm ci, npm run build, and npm run lint
in the template. Confirmed pino-pretty resolves under `npm ci --omit=dev` with
NODE_ENV=staging, and that an empty PORT now falls back to 3000.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two ways the Fastify starter came up wrong. Neither is caught by the build or by lint, and both were found reviewing #28 after it merged.
Empty
PORTbound a random portPORTwas read with??, which only guardsnullandundefined. An emptyPORT=in.envreachedNumber(""), which is0, and Fastify binds port 0 to a random free port. The API started, reported success, and listened somewhere nothing was pointed at.Reading it with
||treats the empty value as missing, which is what the Express starter already does.PORTPORT=PORT=8080pino-prettywas a dev dependency loaded at runtimeThe logger wires up the
pino-prettytransport for anyNODE_ENVother thanproduction. With the package indevDependencies,npm ci --omit=dev, which is the usual shape of a staging deploy, left the transport target unresolvable and the process died on startup.It moves to
dependencies, since every environment that loads it needs it at runtime. Production still emits JSON and never loads the transport.Verification
npm run validatepassesnpm ci,npm run build,npm run lintintemplates/api/fastifyall cleanpino-prettyresolves undernpm ci --omit=devwithNODE_ENV=stagingPORTnow falls back to 3000Patch changeset included.