Skip to content
This repository has been archived by the owner on Nov 13, 2018. It is now read-only.

Add express example #5

Open
nojaf opened this issue Jul 5, 2017 · 6 comments
Open

Add express example #5

nojaf opened this issue Jul 5, 2017 · 6 comments

Comments

@nojaf
Copy link
Member

nojaf commented Jul 5, 2017

I'd like to see an express example using the latest and greatest fable.

@alfonsogarciacaro
Copy link
Member

Actually we want to create a samples-node repo with express and other server-side samples. However, I haven't used Fable wit express myself that much. Maybe someone else has more experience? @et1975?

@nojaf
Copy link
Member Author

nojaf commented Jul 5, 2017

That sounds great.
It is currently rather confusing to get dotnet fable webpack to output some javascript.

App.fsx:

#r "C:\temp\FableInterop\packages\Fable.Core\lib\netstandard1.6\Fable.Core.dll"
#r "C:\temp\FableInterop\packages\Fable.Import.Express\lib\netstandard1.6\Fable.Import.Express.dll"

open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import

let app = express.Invoke()

app.get
  (U2.Case1 "/", 
    fun (req:express.Request) (res:express.Response) _ ->
      res.send(sprintf "Hello") |> box)
|> ignore

// Get PORT environment variable or use default
let port =
  match unbox Node.``process``.env?PORT with
  | Some x -> x | None -> 8080

// Start the server on the port
app.listen(port, unbox (fun () ->
  printfn "Server started: http://localhost:%i/" port))
|> ignore
   [0] ./FableInterop.fsproj 0 bytes {0} [built] [2 warnings] [4 errors]

WARNING in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(1,0): (1,79) warning FSHARP: 'C:   emp\FableInterop\packages\Fable.Core\lib
etstandard1.6\Fable.Core.dll' is not a valid assembly name

WARNING in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(2,0): (2,99) warning FSHARP: 'C:   emp\FableInterop\packages\Fable.Import.Express\lib
etstandard1.6\Fable.Import.Express.dll' is not a valid assembly name

ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(11,10): (11,17) error FSHARP: The value, namespace, type or module 'express' is not defined. Maybe you want one of the following:
   exp

ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(13,0): (13,7) error FSHARP: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program poi
nt to constrain the type of the object. This may allow the lookup to be resolved.

ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(21,19): (21,30) error FSHARP: The value, constructor, namespace or type 'process' is not defined. Maybe you want one of the following:
   Process

ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(25,0): (25,10) error FSHARP: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program po
int to constrain the type of the object. This may allow the lookup to be resolved.
Closing server...

I'm also not really a seasoned fsharp dev, so I might just be missing a very basic thing here.

@alfonsogarciacaro
Copy link
Member

Can you please try adding @ in front of the path strings?

#r @"C:\temp\FableInterop\packages\Fable.Core\lib\netstandard1.6\Fable.Core.dll"
#r @"C:\temp\FableInterop\packages\Fable.Import.Express\lib\netstandard1.6\Fable.Import.Express.dll"

That makes them verbatim strings, meaning \t won't be interpreted as a tab character.

@nojaf
Copy link
Member Author

nojaf commented Jul 5, 2017

No luck

@alfonsogarciacaro
Copy link
Member

Ok, we'll try to add a Express sample that works with latest Fable :) Maybe @fable-compiler/documentation, @MangelMaxime can help with that? 😉

@et1975
Copy link
Member

et1975 commented Jul 5, 2017

I've started porting our elmish-ws sample to latest Fable, it uses Express for websockets, will try to wrap it up soon.

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

No branches or pull requests

3 participants