Using templates disallows html

d. My complete Caddyfile or JSON config:

https://cdn.example.com {
        import cloudflare
        root * /opt/FileServer

        basicauth /games/* {}
        basicauth /cdn/PasswordProtected/* {}

        file_server /* browse {
                index index.html
        }


        templates
        @mdcheck path *.md
        rewrite @mdcheck /assets/templates/markdown.html
}

3. The problem I’m having:

when loading html, i get an 500 error. for no reason and the logs says its templates fault

4. Error messages and/or full log output:

{
    "level": "error",
    "ts": 1597504167.888089,
    "logger": "http.log.error",
    "msg": "template: /games/Game/:81462: unexpected \"{\" in command",
    "request": {
      "method": "GET",
      "uri": "/games/Game/",
      "proto": "HTTP/1.1",
      "remote_addr": "108.162.245.95:35446",
      "host": "cdn.example.com",
      "headers": {
        "Cf-Ipcountry": [
          "US"
        ],
        "Authorization": [
          "Basic c2hpdG51Z2dpdDp3ZWxjb21ldG9oZWxseW91c2hpdG51Z2dpdA=="
        ],
        "Upgrade-Insecure-Requests": [
          "1"
        ],
        "Accept": [
          "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
        ],
        "Cdn-Loop": [
          "cloudflare"
        ],
        "Referer": [
          "https://cdn.example.com/games/"
        ],
        "Accept-Language": [
          "en-US,en;q=0.9"
        ],
        "Cookie": [
          "__cfduid=d8c55d4000c6014a93d06c0967202fd551595633270; cf_chl_prog=a23; cf_clearance=fbb5b298a9459ff929a35f08080f87c5cb3be9b3-1597528534-0-1za8e8445fzc2376061z74a1b618-250"
        ],
        "Cf-Ray": [
          "5c363d5eaa4be462-SEA"
        ],
        "X-Forwarded-Proto": [
          "https"
        ],
        "Cf-Visitor": [
          "{\"scheme\":\"https\"}"
        ],
        "User-Agent": [
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36"
        ],
        "Sec-Fetch-User": [
          "?1"
        ],
        "Cf-Connecting-Ip": [
          "<my IP>"
        ],
        "Connection": [
          "Keep-Alive"
        ],
        "Cache-Control": [
          "no-cache"
        ],
        "Sec-Fetch-Site": [
          "same-origin"
        ],
        "Sec-Fetch-Dest": [
          "document"
        ],
        "Accept-Encoding": [
          "gzip"
        ],
        "X-Forwarded-For": [
          "<my IP>"
        ],
        "Pragma": [
          "no-cache"
        ],
        "Sec-Fetch-Mode": [
          "navigate"
        ],
        "Cf-Request-Id": [
          "0495c4af2c0000e462e1344200000001"
        ]
      },
      "tls": {
        "resumed": false,
        "version": 772,
        "ciphersuite": 4867,
        "proto": "",
        "proto_mutual": true,
        "server_name": "cdn.example.com"
      }
    },
    "duration": 0.025344732,
    "status": 500,
    "err_id": "svtdsnmt9",
    "err_trace": "templates.(*Templates).executeTemplate (templates.go:305)"
  }

5. What I already tried:

I have no clue what to try except disabling my templates, but i need those to render markdown

I think you’re passing content that isn’t meant to be templated through the templating handler. This is exactly what request matching is for - only enable templating when it makes sense for your application.

the config isnt supposed to be being passed, i thought my config covered that?

Just putting templates makes that handler get enabled for every request. You need to add a matcher to it to exclude it from other requests.

so kinda like what i have for @mdcheck,?

yep, just took my @mdcheck and applied it. it works

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.