[!WARNING]
This work is in progress!
@enhance/app-core
"Core"
WIP: goals
mainly:
Create an intermediary library between @enhance/arc-plugin-enhance
and @enhance/ssr
-
scope: create router from pre-loaded routes Map. marshall pre-defined element functions. return a method
routeAndRender()
that does:-
req
→ { route, execute api, render template, return } →result
-
- Agnostic to Architect (mostly - see below about i/o)
- this library doesn't consider many Arc things or Arc-specific parts of
arc-plugin-enhance
.
- this library doesn't consider many Arc things or Arc-specific parts of
- more easily tested
- adaptable to other Node.js servers - even other runtimes like Deno and the browser
- there are no Node.js dependencies in this library
also...
- use
@architect/function#http
-style input and output- adapters could be used to convert to/from other formats like native
IncomingMessage
andServerResponse
- the advantag here is that implementation is above Core
- adapters could be used to convert to/from other formats like native
- outsource routing to external dep (not a hard requirement, but many benefits)
- will require some adapting to fit Enhance path param API
- don't swallow user-land exceptions
- the Core consumer can handle errors as it sees fit
- Core router doesn't render errors, just throws
- only throws on missing or incomplete route:
err.message
is"404"
- if user-land code throws, log the exception and throw
- only throws on missing or incomplete route:
- don't search for head file - but allow it to be provided
- don't load state for api fn (so no preflight)
- but allow additional state at request-time for
routeAndRender()
- also allow initial router state to be provided
- but allow additional state at request-time for
- expose decent type defs for configuration and returned values
notes
- the main method is
routeAndRender()
, butrender()
is also very helpful- and
elements
override inrender()
could be a perf vector
- and
- the
radix3
router (currently implemented) is a good router candidate- it will never be a bottleneck
- but it uses
:
to denote params, Enhance uses$
next
- [ ] fix session and state passing
- [x] handle path params
- [ ] add middleware considerations
- [x] expand options/config to allow pre-loaded routes, handlers, pages, and elements
- [x] swap linter config
- [x] drop into existing arc-plugin-enhance as sidecar, run tests
samples
check out the smoke-test for a few examples of how to use this library