Echo JS 0.11.0

<~>

tracker1 comments

tracker1 1644 days ago. link 1 point
Interresting approach(es)... for recent applications, I've been using Koa, just because the middleware and context handling are much better than everything else.

I create an EnvironmentContext on startup that contains my settings (based on environment variables), configuration (based on application configurations) additional services (database client, redis client etc) and a general logger (bunyan, with console and optionally ES and Seq sinks).

The AppContext extends EnvironmentContext and my first middleware (begin-request) adds the environment context, adds methods for RequestInfo and ResponseInfo and wraps the logger methods to include RequestInfo for each log statement, and the final output being the general error logging middleware then the response middleware (which doesn't output, if error middleware already did).  I also add additional providers for easy apiResult and apiError responses as well as for Role based authentication (Jwt bearer tokens).

It works pretty well... made the switch to TS to make context handling easier... I also have it generically typed Context<TBody, TParams, TQueryString> so that I can have typed instances in my route handlers.

Each of my route handlers returns an array, so that it can include parameter/body/query validators (Joi or Yup), with the Role validation where all the routes are mounted.

Hoping to get permission to put the Configuration Service, which only delivers build configuration(s) output on Github in the next month or so.
tracker1 1644 days ago. link 1 point
Decent start on these things... might be worth digging in a bit deeper in a few areas.

I would suggest taking the next steps, which would be adding unit tests with an effort for high (>80%) code coverage, I find Jest is easiest to configure, and has some nice integrations for React apps.  This will help you to understand how to make your code more modular/accessible.

From there, would create Dockerfile(s) and docker compose files to make it easier to stand up an instance for local testing/usage.  You could go another step and setup an integration test project to work with this using puppeteer or Playwright.

After that, would circle around and look into Redux patterns as well as possibly GraphQL services.  Once you've started writing tests for your applications, it's much easier to see how helpful Redux as a control flow pattern can really help.  There are other options, but I find Redux + thunks extension cover most of the bases for most applications, and allow for horizontal feature growth without blowing out complexity.
tracker1 1649 days ago. link 1 point
It's a little more wordy than it needs to be.  The "title" example is contrived and doesn't need useEffect.  Multiple calls for useEffect should be avoided, in fact too many hook calls in components can be detrimental to performance in general, for some things, it should be closer to the top level and integrated with Redux, or whatever you use for state management.
tracker1 1651 days ago. link 1 point
In practice, I'm generally using Redux for almost everything.  Two areas I am not is specifically strings/language and sometimes with Forms.  I use context for language, and may use state or context for forms.

One thing that is a side effect I explicitly do with language/strings is that the current/selected language as well as the current language strings are accessible as globals in the language/strings module(s).  This is only so that they are accessible in error messages/conditions that might be in an Action or Reducer.  It's "sloppy" but effective.

For the components, I use "useStrings()" which gets the current strings from context.

I also use the browser language events as well as an override in the UI that override is set in redux and those events update the current strings to use in context and globally.
tracker1 1652 days ago. link 1 point
I'm not seeing anything regarding access restrictions... I would emphatically *NOT* use this unless everything the account in use has access to is meant to be public, and has no write access to the database.
tracker1 1653 days ago. link 1 point
No access security restrictions, don't put this on anything where all data in the database is meant to be anything other than publicly accessible.
tracker1 1653 days ago. link 2 points
updated to target url, and blocked gitconnected.
tracker1 1660 days ago. link 1 point
Cool.. would be cool if react components were supported... I've leaned so heavily on material-ui the past few years, I'd rather not go without it.  Though bootstrap is easy enough to integrate with just the (S)CSS from source.
tracker1 1660 days ago. link 1 point
When creating a crypto key from a known value would use pbkdf2 @ 10000 or higher iterations for the encryption key from known key, MD5 is *NOT* sufficient.  

When an IV or salt is used, it should be unique to each encode.  Can be added to the encrypted output or stored separately... re-using the IV allows for a broader attack surface, especially if the encoded content is simlar, such as JSON encoded objects, etc.
[more]