This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
build: create directory for shared client and server code #216
Merged
Conversation
This file contains 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
LoneRifle
approved these changes
Sep 6, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm otherwise
apologies for force-pushing after review but have to clean up commit history |
Also swaps out existing User API type for a type declared in the shared folder for testing.
mantariksh
force-pushed
the
build/shared
branch
from
September 7, 2021 07:58
01de349
to
65ba0f2
Compare
mantariksh
force-pushed
the
build/shared
branch
from
September 7, 2021 08:15
65ba0f2
to
563d944
Compare
@LoneRifle requesting another review for 563d944! |
LoneRifle
approved these changes
Sep 7, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm otherwise
Merge when ready |
Merged
This was referenced Apr 24, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem
API types should be shared between the frontend and backend to prevent duplication of code. In other words, the frontend service which calls an API and the backend controller which returns the response should share the same type for the shape of data returned.
However, the build pipelines for frontend and backend are currently completely separate. This means code cannot easily be shared between the frontend and backend.
Part of #218
Solution
The idea is to rewire the build pipeline to accommodate a
shared
folder at the top level, from which the frontend and backend can both import code.The changes for the frontend were more involved due to the intricacies of
create-react-app
. The solution was to use the "Outside of root" section ofreact-app-rewire-alias
. This allowed us to alias the top-levelshared
folder to~shared
when importing in the frontend.The backend was more straightforward and just involved changes to
server/tsconfig.json
.In order to test that the build pipeline works, I swapped out the existing
BaseUserDto
type which previously lived inclient
and replaced it with aUserBaseDto
type inshared
. In the backend, I updated theUser
model type to inherit fromUserBaseDto
. This pattern will be applied to the rest of the models and API types in a subsequent PR.