This library enables webserver functionality for apps based off of @digital-alchemy
, binding configuration variables to Nest and automatically setting up common middleware.
The general goals of this library will stick around in the future, but some parts of the code are tuned to my specific uses.
Since web isn't a primary focus for @digital-alchemy
right now, cleaning everything up hasn't been a high priority.
These elements are opt-in (like the Nest auth guards), so they should not have an effect unless explicitly used.
If you have opinions on what you'd like to see from this library, open an issue
The options provided to @QuickScript(options)
, and Bootstrap(module,options)
have http?: boolean
as an option.
This is set to false by default.
Enabling will request the bootstrap process set up nest with an express server
Add ServerModule
to list of imports.
After configuration, this library is intended to not have be interacted with by the developer. Everything should happen automagically, and leave the app in a good to go & open for business state.
The following middleware is automatically set up
- csurf
- cors
- compression
- nest validation pipe
- cookie parser
- json body parser
Every request is assigned a unique id, and will get logged upon completion
Open up ports for listening after the application has confirmed initilization. Has built in support for ssl certs, just provide file path to load from.
The built in auth flow is mostly intended for local development and other non-public production uses.
Adding @AuthStack
annotation to a controller will attach the guards.
The built in AdminKeyGuard
looks for the x-admin-key
header, and will compare that value with the one provided in the configuration
The following configuration options are utilized by this library.
; default configuration
[libs.server]
BODY_SIZE=100kb
COMPRESSION=true
CSURF=false
; 1 billion, then reset to 0
MAX_REQUEST_ID=1000000000
PORT=7000
default value: ""
Leave blank to disable. If this value is provided via x-admin-key header, the request will be authorized
default value: "100kb"
Max json body size for incoming requests
default: true
Wire in compression middleware
default value: ""
CORS origin for the server. Set to blank to disable middleware
default value: 1_000_000_000
Rollover point for request ids
default value: 7000
Port to attach webserver to
default value: undefined
File path, required if SSL_PORT is active
default value: undefined
File path, required if SSL_PORT is active
default value: undefined