TypeScript-MERN-Starter
TypeScript-MERN-Starter copied to clipboard
Directory for shared code between client and server
Hi, loving your project so much, it really helps me to get into full stack development much easier.
I have a question about project structure, it seems like the common part for both frontend and backend is inside the client/core/src/models
directory, could you please explain why did you choose this approach instead of having a separate common
module in the project root directory?
And also if you have 5 minutes, could you please explain, why are we returning { redirected: false, to: targetTo }
when response type is text/html
?
https://github.com/shanhuiyang/TypeScript-MERN-Starter/blob/33bd7317c5d4ab1fc86daa7d0832af3e969b0009/client/core/src/shared/fetch.ts#L60-L66
Hi @hamboomger , intuitively we would like to create a common
folder, which can be located at the same directory with client
and server
.
The problem is, we built our client
folder using expo/react-script so that we can get rid of many beginer-unfriendly configurations, e.g. webpack.
However this brings side effect that expo/react-script cannot recognize its parent folder. Then we have to make some trade-off like currently we do.
@hamboomger , because for any unhandlable routes the server responds the index.html directly, this means server leave any routes it cannot process to the client. Look at the condition here
if (contentType && contentType.startsWith(RESPONSE_CONTENT_TYPE.HTML) && response.request.responseURL) {
This means the case that server has the redirected url which it cannot handled happens, so client should take over the redirect action.
Usually this case happens in OAuth2 interaction.
By the way, I also would like to create a common
folder as you suggested. So I will keep this issue opened and find a time to resolve this issue.
@shanhuiyang oh okay, now it makes sense to me. Thank you for reply :)