[V2] Use markdown in place of html?

I just want to know if its possible to make caddy use a standard markdown file, apply a template, and have it display markdown files as if they were html.

Absolutely - just serve your template file for requests to markdown files. Use the template directive and you can render markdown.

If you want a more advanced example, you can see how the Caddy website does this for its docs: GitHub - caddyserver/website: The Caddy website

Yeah i cant get it to work at all,
the caddyfile im using

localhost:2019
root * out
templates

the location of the markdown file out/index.md
and the caddy run log

2020/07/18 00:00:07.769 INFO   admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"
]}
2020/07/18 00:00:07.769 INFO   serving initial configuration
2020/07/18 00:00:12.440 INFO   admin.api       received request        {"method": "GET", "host": "localhost:2019", "uri": "/", "remote_addr": "127.0.0.1:55858", "headers": {"Accept":
["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.5"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"]}}
2020/07/18 00:00:12.579 INFO   admin.api       received request        {"method": "GET", "host": "localhost:2019", "uri": "/favicon.ico", "remote_addr": "127.0.0.1:55858", "headers":
 {"Accept":["image/webp,*/*"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.5"],"Cache-Control":["max-age=0"],"Connection":["keep-alive"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"]}}

You need to enable the file server, or there won’t be any origin of content.

I may be mistaken but I don’t think Caddy will serve index.md as an index file by default, you may also need to configure the index subdirective of file_server. By default it just looks for index.html and index.txt.

Well it isnt serving anything, just a 404

PS D:\_Workspace\merith.tk\www> caddy run
2020/07/20 22:07:57.951 INFO   admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["[::1]:2019", "127.0.0.1:2019", "localhost:2019"]}
2020/07/20 22:07:57.951 INFO   serving initial configuration
2020/07/20 22:08:02.950 INFO   admin.api       received request        {"method": "GET", "host": "127.0.0.1:2019", "uri": "/", "remote_addr": "127.0.0.1:53399", "headers": {"Accept":["text/html,application/xhtml+xml,
application/xml;q=0.9,image/webp,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate"],"Accept-Language":["en-US,en;q=0.5"],"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; 
Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"]}}

ALl of the files in question

## Caddyfile
localhost:2019 {
root * out
templates
file_server index
}
## index.html
<!DOCTYPE html>
<html>
	<head>
		<title>Welcome to example.com</title>	
	</head>
	<body>
		<h1>Welcome to example.com</h1>
		<p>
			This site is just a place holder to show i can manage a server and keep it alive and functioning consistantly.<br>
			However i do have a selfhosted git service located at <a href="https://git.example.com">https://git.example.com</a>
		</p>
	</body>
</html>
## out/index.md
# Welcome to Example.com
This site is just a place holder to show i can manage a server and keep it alive and functioning consistantly.
However i do have a selfhosted git service located at [git.example.com](https://git.example.com)

Removed from initial glance because i am emberassed i lost my temper at folks who are trying to help me over something they had basically no influence on

That’s very disrespectful. We’re offering our time to help and you come back shouting expletives.

As I said in my comment, Caddy won’t recognize index.md as an index file unless you configure the file_server directive as such.

file_server {
	index index.md
}

But that said, rendering markdown requires using the template functions as @matt said Modules - Caddy Documentation

As the template directive documentation describes, a full working example of a markdown site is available to you right here: website/index.html at master · caddyserver/website · GitHub

Rendering markdown in Caddy involves having an index.html that acts as the layout, which you then render the markdown content into. Markdown on its own can only be rendered as HTML content, not as a full HTML document.

I am sorry, I am just very frustrated as something as simple as serving a single HTML file should’ve been simple to me, I have had quite a stressful day, and it kinda just released all at once right there and I had to walk away from my computer so I didn’t break it. being autistic doesn’t help with stress, so I am sorry that I blew up at you guys, my complaints about the docs are still holding true, they aren’t the best and need improvements to make it on par with v1 docs

And the example shown doesn’t work anyways, this is my caddy version:v2.1.1 h1:X9k1+ehZPYYrSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

Well, root * / is setting the root path to literally / as the base, which would be your C:\ drive probably, as you’re running on Windows.

Try again with root * out as you had before, which is the path relative to your current working directory, plus out.

Did not work,

http://localhost
root * html
file_server {
	index index.md index.html
}

the file layout

/Caddyfile
/html/index.md
/html/index.html

That exact Caddyfile works perfectly fine for me. Infact, when I tried to load http://localhost it triggered a download for the index.md file because the browser doesn’t know how to render .md files by default.

Found the issue
caddyserver listens on both port 80 and 2019 on this config, for no reason. other than what i can gather from the logs, to open an admin API which most users may or may not even want at all by default. yet another complaint i have about v2, logs are in a less than ideal format, i prefer either straight logs like v1, or straight JSON, not a mix of both, makes it harder to parse

So the site works on port 80, which there was only one indication that it is running on port 80 while there are, and i am not kidding, four different indications that it is listening on port 2019

The admin API is necessary to do graceful config reloads with caddy reload. It’s also how Caddy receives shutdown signals when running caddy stop (as a counterpart to caddy start). It’s at the core of how Caddy works.

okay that makes sense, still dont like that it isnt more appearnt in the CONSOLE ONLY logs, that main webserver port is 80, and not 2019. I mean that is just not a good idea to have port 80 showing only once when the admin api port is shown four times. or not even allow logging to a file (and yes, i have looked at the docs, have not found a way to do that yet, nor should i have to look at source code to find it)

1 Like

Well… huh, how new is that? it wasnt there when i was looking for it last time.

It’s always been there. You probably didn’t scroll down far enough. The examples are always at the bottom of the directives pages.

Well damn, thanks for pointing that out,

is there a way to disable the admin api?

Yes, but why?