-
Notifications
You must be signed in to change notification settings - Fork 12
Issue 17 : Running Dash.NET from scripts #24
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
Conversation
src/Dash.NET.Giraffe/DashApp.fs
Outdated
let configureCors (builder : CorsPolicyBuilder) = | ||
builder.WithOrigins(sprintf "http://%s:8080" loadedApp.Config.HostName) | ||
builder.WithOrigins(sprintf "http://%s:5001" args.[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is a quick workaround now, but this needs to be properly typed so that we can create DUs for Giraffe/Suave specific configs. Binding the first entry in an arbitrary string array is very confusing, at least it was for me when testing. I would suggest to add overloads for DashApp.run in Both Dash.NET.Giraffe and Dash.NET.Suave like this:
type DashSuaveConfig = { Port: int ; ...}
type DashGiraffeConfig = { Port: int ; ...}
type DashApp with
static member run (args: string []) (gConfig: DashGiraffeConfig ) (dApp: DashApp) = ...
static member run (args: string []) (sConfig: DashSuaveConfig ) (dApp: DashApp) = ...
/// | ||
/// POST /_dash-update-component -> handles callback requests and returns serialized callback JSON responses. | ||
|
||
static member toWebPart (app:DashApp) : WebPart = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like the only thing we need separately in Dash.NET.Giraffe and Dash.NET.Suave eventually is the toWebPart
/ toHttpHandler
(and run, see above) functions right? if so, we can keep all of the functions above in Dash.NET core and just add these as extension methods
Hey @ademar cool stuff overall! moving the comments from #17 here:
It works for me when i use the
I get that for http, but https works fine. Not sure where the exact misconfig is located though
As we use Feliz.Rngine for components, it would be awesome if we could use it in both
See above basically, most of the duplication seems to be in the respective As in my review comments, it looks to me like the only real difference is in
Agreed on passing as args, but i would model the specific configs via types, see also my review comment Overall i think this is ready to merge besides the backend specific config modeling, i would suggest we add that before merging as it can become very confusing using the string [] args. Things like using Feliz.Engine can be added downstream, depends on how fast we want to package Dash.NET.Suave. (@jackparmer i suspect you want this out fast though? 😆) |
Thanks! I'll take care of these today. |
:) |
Hi @kMutagene I've made the configuration into typed records and have added the CORS headers to the Suave app. I have also splitted the Let me know what you think. I spent some time trying to move the Views to the Feliz engine but it looks like it might take some time for me to wrap my head around it. |
@ademar lgtm! I realized that there is different behavior between Suave and Giraffe implementations regarding Json serialization: Dash.NET/src/Dash.NET/DashComponents/ComponentBase.fs Lines 115 to 122 in 4c2559e
While these properties are uppercase in that record type, the dash renderer expect the Json properties to be lowercase: This problem does not appear when using giraffe (which per default is also using Newtonsoft.Json, that's why I'm confused now). It is fixable by adding JsonPropertyAttributes to the record types, but i think it should be investigated why the json configs are different (@plt-joey worked a lot with components, maybe they have some insights here). So in general I would say that this can be merged, but the serialization issue should be addressed separately before the release of a package (otherwise the suave app cannot render some components). Let's make sure to file an issue and use the exact same Json serializer options for both apps, or this will be a nightmare to maintain, especially if there might be more backend implementations in the future |
Giraffe uses camel casing serialization by default as seen here https://github.com/giraffe-fsharp/Giraffe/blob/master/src/Giraffe/Json.fs#L36 I've added the same settings in the last commit to this PR which solves the issue (ref #26 ). |
@ademar okay awesome, ill merge this now, thanks for the great work! 🎉 |
This PR executes the plan outlined on issue #17.
Mainly it moves server dependencies to its own projects Dash.NET.Giraffe and introduces Dash.NET.Suave that allows us to launch Dash applications under F# interactive and dotnet interactive. I've posted a more detailed description of the work under the issue.
Feedback is welcome.