Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/1309: API version separation in NodeJS backend #1318

Merged
merged 15 commits into from
Apr 13, 2023

Conversation

jacobwod
Copy link
Member

Pretty massive but should work.

Some new keys in .env can be used to customise the functionality, but my primary intention is not to require any new keys, so please test with your current .env.

- v1 and v2 have their own dirs
- I appended a .v2 to all logger definitions for API V2 controllers/services
- I removed the obsolete endpoints from V2
- Added the new endpoints: PUT and DELETE /mapconfig/{name} instead of /mapconfig/create/{name} and /mapconfig/delete/{name}. This was already changed in the API spec so we will now conform to that
- This is by no means complete (at least I think there's room for improvement). See this as a proposal for future structure inside the Backend dir and please let me know what you think in #1309.
- Separation of API requires either duplicating a lot of functionality (common to the API versions) or drawing a line somewhere and saying 'hey, this part of code should be shared between versions'.
- That's what I'm attemptign to do here and opinions are welcome.
- The 'line' is currently drawn at 'stuff that don't expose /api/vN endpoint should be shared'. So we share the error handler, logger and detailed logger middlewares. The proxy middlewares and perhaps even the static files exposer middleware will be placed inside each API's version. That will come in a future commit.
- Added a key in .env, API_VERSIONS. It can contain a comma-separated list of integers that corespond to API versions. By default any empty value or no value at all means that all API versions are enabled.
- Added a apiVersions constant both in server.js and as an Express app variable, so we can do app.get(apiVersions) anywhere and get the array. Nice.
- Moved two product proxies (FME Server and Sokigo FB) to helper methods. Inside of them, we iterate and import required proxies dynamically.
- Another iteration takes place to set up the OpenAPI Validator middleware and expose the specification, depending on which versions are required. Also nice.
- There were issues with it: seemingly the last middleware to be setup got all logging messages to it, which is unintended.
- The logging we setup ourselves in the middlewares is fine though. Since we take care of both success and error and log
then correctly, there was no use for HPM's internal logging.
…n check.

- The generic proxy is not really versioned as it merely exposes some endpoints using HTTP Proxy Middleware. But we do expose proxies for each of the enabled versions of API to keep it consistent with previous Hajk versions.
- The check added at startup ensure that we only attempt to initialize valid API versions. Those are, for now, kept in const ALLOWED_API_VERSIONS but could be moved further on.
- The static routes are still exposed outside the /api/vN, but the code used is dynamically imported.
- Admin can specify a certain version of active API versions to use. Default value is the highest (latest) active API version.
@jacobwod jacobwod added this to the 3.x milestone Apr 11, 2023
@jacobwod jacobwod self-assigned this Apr 11, 2023
Copy link
Member

@Hallbergs Hallbergs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful!

@Hallbergs Hallbergs linked an issue Apr 12, 2023 that may be closed by this pull request
@jacobwod jacobwod merged commit 0d56eb1 into develop Apr 13, 2023
@jacobwod jacobwod deleted the feature/1309-api-v1-v2-separation-in-nodejs-backend branch April 13, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overhaul of the OpenAPI specifications
2 participants