Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

build: create directory for shared client and server code #216

Merged
merged 7 commits into from
Sep 7, 2021

Conversation

mantariksh
Copy link
Collaborator

@mantariksh mantariksh commented Sep 6, 2021

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 of react-app-rewire-alias. This allowed us to alias the top-level shared 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 in client and replaced it with a UserBaseDto type in shared. In the backend, I updated the User model type to inherit from UserBaseDto. This pattern will be applied to the rest of the models and API types in a subsequent PR.

Copy link
Contributor

@LoneRifle LoneRifle left a comment

Choose a reason for hiding this comment

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

lgtm otherwise

server/src/models/users.model.ts Show resolved Hide resolved
@mantariksh
Copy link
Collaborator Author

oops

Screenshot 2021-09-06 at 3 44 05 PM

@mantariksh
Copy link
Collaborator Author

mantariksh commented Sep 6, 2021

had to update path of server's index.js for npm start, fixed in 8828f46 and 5d4b8dc

@mantariksh
Copy link
Collaborator Author

apologies for force-pushing after review but have to clean up commit history

@mantariksh
Copy link
Collaborator Author

@LoneRifle requesting another review for 563d944!

Copy link
Contributor

@LoneRifle LoneRifle left a comment

Choose a reason for hiding this comment

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

lgtm otherwise

server/tsconfig.json Outdated Show resolved Hide resolved
shared/types/user.ts Outdated Show resolved Hide resolved
@LoneRifle
Copy link
Contributor

Merge when ready

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants