Skip to content

Cookbook: "Start a Web Server and render HTML template" with dream and cohttp #3185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dinakajoy
Copy link
Contributor

open Cohttp
open Cohttp_lwt_unix

let template = {|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should show an example building templates with raw strings without any escaping. It's a very easy way to open up the server to injection attacks. There are multiple options for safer HTML templating/generation libraries that can be used.

@@ Dream.logger
@@ Dream.router [
Dream.get "/" (fun _ -> Dream.html template);
Dream.any "/" (fun _ -> Dream.empty `Not_Found);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave this out as Dream will just handle this automatically.

@dinakajoy dinakajoy requested a review from yawaramin July 1, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants