TypeScript-MERN-Starter icon indicating copy to clipboard operation
TypeScript-MERN-Starter copied to clipboard

Directory for shared code between client and server

Open hamboomger opened this issue 4 years ago • 5 comments

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?

hamboomger avatar Mar 23 '20 11:03 hamboomger

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

hamboomger avatar Mar 23 '20 13:03 hamboomger

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.

shanhuiyang avatar Mar 30 '20 13:03 shanhuiyang

@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.

shanhuiyang avatar Mar 30 '20 13:03 shanhuiyang

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 avatar Mar 30 '20 13:03 shanhuiyang

@shanhuiyang oh okay, now it makes sense to me. Thank you for reply :)

hamboomger avatar Mar 30 '20 17:03 hamboomger