These are chat archives for synrc/n2o

Apr 2019
Martin Rodriguez
Apr 17 18:22
Hello everyone, I am trying to run this project:
I already updated it with the current version of n2o (at least compiles without errors), the index.htm file is not static, it's a DTL template, then, a blank page appears in the browser if I call it this way:
http://localhost:8001/app/index.htm, or this other way: http://localhost:8001/
So, what is the correct url or what should I fix?
Thank you.
Martin Rodriguez
Apr 17 22:06

My routes.erl file:

-export([init/2, finish/2]).

finish(State, Ctx) -> {ok, State, Ctx}.
init(State, #cx{req=Req}=Cx) ->
Path = case n2ouno:ver() of
cow1 -> n2o_cowboy:path(Req); % cowboy 1.0
cow2 -> #{path:=P}=Req, P % cowboy 2.5
Fix = route_prefix(Path),
n2o:info(?MODULE,"Route: ~p~n",[{Fix,Path}]),
{ok, State, Cx#cx{path=Path,module=Fix}}.

route_prefix(<<"/ws/",P/binary>>) -> route(P);
route_prefix(<<"/",P/binary>>) -> route(P);
route_prefix(P) -> route(P).

route(<<>>) -> index;
route(<<"index",/binary>>) -> index; % github static
/binary>>) -> post;
route(<<"app/index",/binary>>) -> index; % priv static
/binary>>) -> post;
route(_) -> index.

My base.htm file:

<!DOCTYPE html>

<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Erlang blog example{% endblock %}</title>

<!-- Bootstrap -->
<link href="" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]> <script src="//"></script> <script src="//"></script> <![endif]-->
.container {
max-width: 40em;
<div class="container">
{% block content %}{% endblock %}

<script src='n2o/utf8.js?v=1'></script>
<script src='n2o/bert.js?v=1'></script>
<script src='n2o/heart.js?v=1'></script>
<script src='n2o/ieee754.js?v=1'></script>
<script src='n2o/n2o.js?v=1'></script>
<script>host = location.hostname === '' ? '' : location.hostname;
port = 8001;</script>
<script src='n2o/ftp.js?v=1'></script>
<script src='n2o/nitro.js?v=1'></script>
<script>protos = [$bert]; N2O_start();</script>

<script src="//"></script>
<script src=""></script>

My index.htm file:

{% extends "base.htm" %}
{% block title %}Latest posts{% endblock %}
{% block content %}

<h1>Latest posts</h1>
{{ posts }}
{% endblock %}

My index.erl file:


posts() -> [

    #h2{body = #link{body = P#post.title, url = "/post?id=" ++ nitro:to_list(}},
    #p{body = P#post.text}
  ]} || P <- posts:get()].

main() -> #dtl{file="index", app=n2ouno, ext="htm", bindings=[{posts, posts()}]}.