Giter Club home page Giter Club logo

caddy-embed's Introduction

Caddy embedded file system

This Caddy plugin embeds your site directly into your web server's binary.

NOTE: This plugin requires building Caddy from source on your own machine because you need to add your own content to the files directory before compiling. The go command is required and I recommend using xcaddy to build. You cannot download this plugin from the Caddy website, for example, and expect it to have your site embedded within it.

Note

This is not an official repository of the Caddy Web Server organization.

Instructions

  1. Clone this repo: git clone https://github.com/mholt/caddy-embed.git && cd caddy-embed
  2. Replace the contents of the files subfolder with your site.
  3. Build Caddy with your locally-cloned copy of this plugin: xcaddy build --with github.com/mholt/caddy-embed=.

Now wherever your server goes, your site goes with it. Serve it up like this:

example.com

file_server {
	fs embedded
}

You can customize the //go:embed directive in the source before building if you want to choose other files or folders to embed. See the Go embed package docs.

Site root

Somewhat annoyingly, when you use //go:embed to add a folder, Go embeds the folder to the root of the virtual file system, without a way to configure Go to add its contents to the root. Because our directive is //go:embed files, that means all filenames have to be prefixed with files/. This is unintuitive as you would expect your site root, for example, to be at index.html, not files/index.html.

To counter this behavior, this module automatically "subs the FS" to trim that top-level folder prefix as long as the embedded directory is named files, and it is not moved or renamed by you.

I would recommend simply doing as the instructions say, and putting your content into the files folder. You can put multiple folders in there if you want more than one. But you are always welcome to do your own thing and change the go:embed directive, etc. If you do that, the automatic prefix stripping won't work for you.

If you are using file_server and want to have the contents of a top-level folder be accessed from the root of the file system, and if you customize the //go:embed directive, you can still strip the root folder name like this:

file_server {
	fs embedded
	root myfolder
}

where myfolder is the name of the folder you added to the go:embed directive. This is only applicable if you are customizing the //go:embed directive and want to strip the top-level folder from the path.

In summary: For most people, this module will "just work" and you do not need to set or change the site root.

caddy-embed's People

Contributors

mholt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

caddy-embed's Issues

The build process wont stop

On my machine the build take about 9 hour and still running, so I terminate it. Do you know why this is happen?

image

I'm using Ubuntu 22.04.2 LTS, go version 1.20.6, xcaddy v0.3.4

Step to reproduce

  1. Install xcaddy: sudo apt install xcaddy
  2. Clone the repo: git clone https://github.com/mholt/caddy-embed.git && cd caddy-embed
  3. Build Caddy with plugin: xcaddy build --with github.com/mholt/caddy-embed=.

I tried reinstall xcaddy with go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest and the output still the same. Do you think is xcaddy bug?

Consider moving to `xcaddy` project

Currently, this approach has some UX problems. It requires cloning this repo and copying the files to embed to inside of the repo. This is awkward for various reasons, such as fighting with git with the files directory, having to clone at all meaning you have some extra directory sitting around, having to copy your files yourself (i.e. needing to write a script/Makefile to automate it), needing to modify module.go if you want to rename the embed, etc.

My suggestion is that we could move this to the https://github.com/caddyserver/xcaddy project, where it would be a build flag, i.e. xcaddy build --embed <path>. Then xcaddy would create the module.go file itself into a temp dir, optionally change the //go:embed line to use a different base path (maybe with another flag like --embed-dir), copy the given path (files to embed) to inside of the temp dir, then invoke the build as normal.

I think this would be significantly better UX, because there would be no need for messing around with git, no copying files by hand, no need to write your own build script to make it work as a repeated command. It would just become an argument to the xcaddy build command they (probably) already use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.