Welcome to my profile :) here you'll find a bunch of unfinished half-baked side projects (I'm pretty good at doing those)
I can do stuff in:
- F#
- Javascript/Typescript
- C#
- Kotlin
and to a lesser extent:
- Java
- Python
Bix, an F# micro-framework for cross-runtime JavaScript backends
License: MIT License
Describe the bug
I have a simple handler that sets the status code to 500 and returns a text body. This works as expected, however when I add a sleep, the body is returned correctly, but the status is 200.
Router.get (
"/status",
(fun next ctx -> promise {
do! Promise.sleep 1000 // <- adding this line causes the status set below to be ignored
return! (setStatusCode 500 >=> sendText "error") next ctx
})
Adapter
Runtime And Version
tried this with
{
"name": "expressfable",
"version": "1.0.0",
"description": "",
"main": "express.fs.js",
"scripts": {
"bix": "dotnet fable watch --run bun --hot ./bix.fs.js"
},
"author": "",
"license": "ISC",
"type":"module",
"dependencies": {
}
}
// npm init type module, npm add express, dotnet tool install fable, dotnet fable express.fsx, node express.fs.js
#r "nuget: Bix.Bun, 1.0.0-beta-004"
#r "nuget: Fable.Core"
#r "nuget: Feliz.ViewEngine"
#r "nuget: Feliz.ViewEngine.Htmx"
#r "nuget: Feliz.Bulma"
open Bix
open Bix.Router
open Bix.Bun
open Bix.Types
open Bix.Handlers
open Feliz.ViewEngine
open Feliz.ViewEngine.Htmx
module View =
let buttonOne =
Html.button [
prop.className "button is-primary"
prop.text "NEW BUTTON"
hx.post "/button-one"
hx.swap "innerHtml"
]
let buttonOneHtml =
buttonOne
|> Render.htmlView
let view =
Html.html [
Html.head [
Html.link [
prop.rel "stylesheet"
prop.href "https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"
]
Html.script [
prop.src "https://unpkg.com/[email protected]"
]
]
Html.body [
Html.h1 [
prop.className "hero is-primary"
prop.text "Hello Feliz from express!"
]
Html.section [
Html.p "here is a button..."
buttonOne
]
]
]
|> Render.htmlView
let buttonTwo =
Html.button [
prop.className "button is-error"
prop.text "FROM HTMX"
hx.post "/button-two"
]
|> Render.htmlView
module Handlers =
let home: HttpHandler = sendText View.view
let b1: HttpHandler = sendText View.buttonOneHtml
let b2: HttpHandler = sendText View.buttonTwo
let server =
Server.Empty
|> Server.withDevelopment true
|> Server.withPort 5000
|> Server.withRouter (
Router.Empty
|> Router.get ("/", Handlers.home)
|> Router.get ("/button-one", Handlers.b1)
|> Router.get ("/button-two", Handlers.b2)
)
|> Server.run
let mode =
if server.development then
"Development"
else
"Production"
printfn $"Mode: {mode}"
printfn $"Server started at http://{server.hostname}:5000"
Fetch's Response constructor allows returning a stream. It would be useful to expose it for case such as streaming react responses as in this example: https://bun.sh/guides/ecosystem/ssr-react.
Is your feature request related to a problem? Please describe.
The default router we have is fairly straight forward but it might become verbose and annoying to write for larger applications, it also doesn't help to figure out the structure of a web application
Describe the solution you'd like
The way Bix uses routes is similar to the EndpointRouter from Saturn, we define a list of routes and then we match on them via URLPattern, Ideally we should be able to create a similar router we might not have pipelines and plugs at the beginning but at least routers and controllers should be present
let todoController: RouteDefinition list =
controller {
// operation: HttpContext -> Promise<BixResponse>
find (ctx -> BixResponse) // get /todos
findOne (id -> ctx -> BixResponse) // get /todos/:id
update (ctx -> BixResponse) // put /todos
updateOne (id -> ctx -> BixResponse) // put /todos/:id
create (ctx -> BixResponse) // post /todos
delete (ctx -> BixResponse) // delete /todos
}
let routes: RouteDefinition list =
router {
// verbOperation -> string -> HttpHandler
get url HttpHandler
post url HttpHandler
put url HttpHandler
patch url HttpHandler
delete url HttpHandler
custom verb url HttpHandler
forward url handler // ideal
// alternative in case the above proves to be complicated
controller "/todos" todoController
}
Describe alternatives you've considered
A plain Giraffe style of routing
Additional context
Add any other context or screenshots about the feature request here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.