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

Directory for shared code between client and server #104

Open
hamboomger opened this issue Mar 23, 2020 · 5 comments
Open

Directory for shared code between client and server #104

hamboomger opened this issue Mar 23, 2020 · 5 comments

Comments

@hamboomger
Copy link

hamboomger commented Mar 23, 2020

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
Copy link
Author

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?

if (contentType && contentType.startsWith(RESPONSE_CONTENT_TYPE.HTML) && response.request.responseURL) {
// Drop the html because we use client routing instead of server routing
let targetTo: string = response.request.responseURL;
if (targetTo.startsWith(getHostUrl())) {
targetTo = targetTo.substring(getHostUrl().length);
}
return Promise.resolve({ redirected: false, to: targetTo });

@shanhuiyang
Copy link
Owner

shanhuiyang commented Mar 30, 2020

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
Copy link
Owner

shanhuiyang commented Mar 30, 2020

@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
Copy link
Owner

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.

@hamboomger
Copy link
Author

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

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

No branches or pull requests

2 participants