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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摑Coding Notes #24

Open
crupest opened this issue Jun 2, 2020 · 8 comments
Open

馃摑Coding Notes #24

crupest opened this issue Jun 2, 2020 · 8 comments

Comments

@crupest
Copy link
Owner

crupest commented Jun 2, 2020

I love and hate coding at the same time! 馃ぃ

@crupest crupest pinned this issue Jun 2, 2020
@crupest
Copy link
Owner Author

crupest commented Jun 2, 2020

Forwarded Headers And Docker

When you deploy aspnet core app with docker and use reverse proxy with forwarded header middleware in app, there is a problem that forwarded header middleware may not regard forwarded headers or replace the http context.

I made a basic investigation. Here is the reason I figure out and it may not be completely correct.

Aspnet core began to ignore forwarded headers when the original request ip is not in the allowed list from some version. By default allowed ip is only loopback. However it seems when running in docker a individual network is established and requests from proxy server are like external requests so aspnet core ignore forwarded headers.

The solution is to explicitly make aspnet core trust the requests. Like this

if (string.Equals(System.Environment.GetEnvironmentVariable("ASPNETCORE_FORWARDEDHEADERS_ENABLED"), "true", StringComparison.OrdinalIgnoreCase))
{
    var options = new ForwardedHeadersOptions
    {
        ForwardedHeaders = ForwardedHeaders.XForwardedFor |
        ForwardedHeaders.XForwardedProto
    };
    // Only loopback proxies are allowed by default.
    // Clear that restriction because forwarders are enabled by explicit 
    // configuration.
    options.KnownNetworks.Clear();
    options.KnownProxies.Clear();
    app.UseForwardedHeaders(options);
}

Remember to define environment variable ASPNETCORE_FORWARDEDHEADERS_ENABLED as true in docker image!

@crupest crupest added the good first issue Good for newcomers label Jun 7, 2020
@crupest
Copy link
Owner Author

crupest commented Jun 16, 2020

image
Guess what? They do not define the environment variable in official base docker image in fact.

@crupest
Copy link
Owner Author

crupest commented Aug 6, 2020

The source map generated with eval-source-map in webpack is totally a mass and not even able to be used.
Use eval-cheap-module-source-map instead and at least you can make breakpoint line by line.

@crupest crupest removed the good first issue Good for newcomers label Nov 16, 2020
@crupest
Copy link
Owner Author

crupest commented May 12, 2021

Be careful when using react hooks and rxjs. Hooks may create a new observable for each update making some function like throttle not work properly.

@crupest
Copy link
Owner Author

crupest commented May 17, 2021

Be careful with signalr behind nginx. It needs special configuration. See this for example.

@crupest crupest transferred this issue from crupest/Timeline Aug 2, 2023
@crupest crupest changed the title 馃搩 Caveat Records 馃摑Coding Notes Aug 2, 2023
@crupest crupest pinned this issue Aug 2, 2023
@crupest
Copy link
Owner Author

crupest commented Aug 2, 2023

A lesson learned at the cost of blood, never refactor thoroughly at one time. Do it slowly and progressively!

@crupest
Copy link
Owner Author

crupest commented Aug 16, 2023

There is currently a bug in parceljs. If you want to proxy ws in dev server, you should use a different hmr port from dev server port. See details in parcel-bundler/parcel#6994. Hope the bug can be fixed soon.

(I won't tell you that I spent several hours to find the problem.馃槶)

@crupest
Copy link
Owner Author

crupest commented Aug 30, 2023

Some tips about reactjs:

  • When your array state variable does not work well, try to figure out it is a new array or an old array with different elements. Although experienced developer knows this rule very much, there are cases you make such mistake carelessly.
  • Events of elements in reactjs are bubbled as in jsx. If you use a portal, they are still bubbled as the structure in jsx because reactjs will do the magic for you.
  • If you can't use jsx, check if your file is .tsx or .ts.

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

1 participant