Skip to content
This repository was archived by the owner on Aug 10, 2020. It is now read-only.

Commit c9c389e

Browse files
committed
update example http server with the latest example
1 parent 8e8a459 commit c9c389e

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

examples/node-http-server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"devDependencies": {
3-
"bs-platform": "0.6.2"
3+
"bs-platform": "0.7.1"
44
},
55
"scripts" : {
66
"build" : "bsc -c test_http_server.ml"

examples/node-http-server/test_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.6.2 , PLEASE EDIT WITH CARE
1+
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.7.1 , PLEASE EDIT WITH CARE
22
'use strict';
33

44
var Pervasives = require("bs-platform/lib/js/pervasives");

examples/node-http-server/test_http_server.ml

+29-25
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,47 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
[@@@bs.config{non_export = true; obj_type_auto_uncurry = true}]
26-
27-
let port = 3000
28-
let hostname = "127.0.0.1"
29-
let create_server http =
30-
let server = http##createServer (fun [@uncurry] (req, resp) ->
31-
resp##statusCode_set 200;
32-
resp##setHeader("Content-Type", "text/plain");
33-
resp##end_ "Hello world\n"
34-
)
35-
in
36-
server##listen(port, hostname, fun [@uncurry] () ->
37-
Js.log ("Server running at http://"^ hostname ^ ":" ^ string_of_int port ^ "/")
38-
)
25+
[@@@bs.config{no_export; bs_class_type}]
3926

4027
type req
4128

42-
type resp = [%bs.obj:<
43-
statusCode_set : int -> unit ;
44-
setHeader : string * string -> unit ;
45-
end_ : string -> unit
46-
> ]
29+
class type _resp = object
30+
method statusCode : int [@@bs.set]
31+
method setHeader : string -> string -> unit
32+
method _end : string -> unit
33+
end
4734

48-
type server = [%bs.obj:<
49-
listen : int * string * (unit -> unit) -> unit
50-
> ]
35+
type resp = _resp Js.t
5136

37+
class type _server = object
38+
method listen : int -> string -> (unit -> unit [@bs]) -> unit
39+
end
40+
type server = _server Js.t
5241

42+
class type _http = object
43+
method createServer : (req -> resp -> unit [@bs] ) -> server
44+
end
5345

54-
type http = [%bs.obj:<
55-
createServer : (req * resp -> unit ) -> server
56-
> ]
46+
type http = _http Js.t
5747

5848

5949
external http : http = "http" [@@bs.val_of_module ]
6050

6151

52+
let port = 3000
53+
let hostname = "127.0.0.1"
54+
let create_server (http : http) =
55+
let server = http##createServer begin fun [@bs] req resp ->
56+
resp##statusCode #= 200;
57+
resp##setHeader "Content-Type" "text/plain";
58+
resp##_end "Hello world\n"
59+
end
60+
in
61+
server##listen port hostname begin fun [@bs] () ->
62+
Js.log ("Server running at http://"^ hostname ^ ":" ^ string_of_int port ^ "/")
63+
end
64+
65+
6266
let () =
6367
create_server http
6468

examples/reason-demo/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"scripts" : {
99
"build" : "source dependencyEnv && bsc -pp ./node_modules/reason/refmt_impl.native -impl hello.re"
10-
},
11-
"name" : "test"
10+
}
11+
, "name" : "test"
1212
}

0 commit comments

Comments
 (0)