Giter Site home page Giter Site logo

angelmunoz / bix Goto Github PK

View Code? Open in Web Editor NEW
31.0 31.0 1.0 94 KB

Bix, an F# micro-framework for cross-runtime JavaScript backends

License: MIT License

F# 100.00%
bun cloudflare cloudflare-workers deno fable fable-compiler framework fsharp javascript node

bix's Introduction

Hi there ๐Ÿ‘‹

wakatime

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

ko-fi

bix's People

Contributors

angelmunoz avatar joprice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

joprice

bix's Issues

incorrect status when sleeping in bun http handler

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

  • Bix
  • Bix.Bun
  • Bix.Deno
  • Bix.Cloudflare

Runtime And Version

  • Node ->
  • Bun -> 1.1.8
  • Deno ->
  • Cloudflare ->

cannot find URLPattern

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": {
  }
}
image
// 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"

Saturn Style Router

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.