Skip to content

Commit

Permalink
Merge pull request #79 from the-man-with-a-golden-mind/render_and_set
Browse files Browse the repository at this point in the history
Add render and set
  • Loading branch information
ncthbrt authored Jul 5, 2020
2 parents 39f9c09 + d3df5c6 commit 27d302e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions example/Index.re
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ let makeSuccessJson = () => {
};

let app = express();
/*
If you would like to set view engine
App.set(app, "view engine", "pug");
*/

App.disable(app, ~name="x-powered-by");

Expand Down Expand Up @@ -165,6 +169,14 @@ App.deleteWithMany(
|],
);

/* If you have setted up view engine then you can uncomment that "get"
App.get(app, ~path="/render") @@
Middleware.from((_, _) => {
let dict: Js.Dict.t(string) = Js.Dict.empty();
Response.render("index", dict, ());
});
*/

App.get(app, ~path="/baseUrl") @@
Middleware.from((next, req) =>
switch (Request.baseUrl(req)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Express.re
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ module Response = {
[@bs.send.pipe: t] external setType : (string) => t = "type";
[@bs.send.pipe: t] external setLinks : Js.Dict.t(string) => t = "links";
[@bs.send.pipe: t] external end_ : complete = "end";
[@bs.send.pipe: t] external render: (string, Js.Dict.t(string), 'a) => complete = "render";
};

module Next: {
Expand Down Expand Up @@ -695,6 +696,7 @@ module App = {
let listen = (app, ~port=3000, ~hostname="0.0.0.0", ~onListen=(_) => (), ()) =>
listen_(app, port, hostname, onListen);
[@bs.send] external disable: (t, ~name: string) => unit = "";
[@bs.send] external set: (t, string, string) => unit = "set";
};

let express = App.make;
Expand Down
2 changes: 2 additions & 0 deletions src/Express.rei
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ module Response: {
let setType: (string, t) => t;
let setLinks: (Js.Dict.t(string), t) => t;
let end_: t => complete;
let render: (string, Js.Dict.t(string), 'a, t) => complete;
};

module Next: {
Expand Down Expand Up @@ -389,6 +390,7 @@ module App: {
) =>
HttpServer.t;
let disable: (t, ~name: string) => unit;
let set: (t, string, string) => unit;
};


Expand Down

0 comments on commit 27d302e

Please sign in to comment.