├── .gitattributes
├── srv
├── .init.lua
├── redbean.css
└── index.html
├── LICENSE
├── .gitignore
├── .vscode
└── tasks.json
├── README.md
└── Makefile
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.sh text eol=lf
2 |
--------------------------------------------------------------------------------
/srv/.init.lua:
--------------------------------------------------------------------------------
1 | -- https://redbean.dev/#usage
2 |
3 | -- Uncomment this to launch a browser on start
4 | --LaunchBrowser("/")
5 |
--------------------------------------------------------------------------------
/srv/redbean.css:
--------------------------------------------------------------------------------
1 | html {
2 | font-family: sans-serif;
3 | font-size: 14pt;
4 | }
5 |
6 | body {
7 | max-width: 700px;
8 | min-width: 700px;
9 | margin: 0 auto 0 auto;
10 | }
11 |
12 | pre,
13 | code {
14 | font-family: monospace;
15 | font-size: 12pt;
16 | }
17 |
18 | p {
19 | text-align: justify;
20 | }
21 |
22 | .indent {
23 | margin-left: 1em;
24 | }
25 |
26 | h1,
27 | h2 {
28 | margin: 1.5em 0 1.5em 0;
29 | }
30 |
31 | h1 strong {
32 | font-size: 14pt;
33 | }
34 |
35 | footer {
36 | margin-top: 12em;
37 | margin-bottom: 3em;
38 | font-size: 14pt;
39 | }
40 |
41 | .logo {
42 | float: right;
43 | }
44 |
--------------------------------------------------------------------------------
/srv/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
redbean
4 |
5 |
6 |
7 |
8 | redbean
9 | distributable static web server
10 |
11 |
12 |
13 | Here's what you need to know about redbean:
14 |
15 |
16 | - million qps on modern pc
17 |
- container is executable zip file
18 |
- userspace filesystem w/o syscall overhead
19 |
- kernelspace zero-copy gzip encoded responses
20 |
- executable runs on linux, bsd, mac, and windows
21 |
22 |
23 |
24 | redbean is based on αcτµαlly pδrταblε εxεcµταblε
25 | and cosmopolitan.
26 |
27 | redbean is authored by Justine Tunney who's on
28 | GitHub and
29 | Twitter.
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pid
2 | *.log
3 | definitions
4 |
5 | ### REDBEAN-TEMPLATE
6 | # executables shouldn't be in a public git repo
7 | *.com
8 | *.com.template
9 |
10 | ### Created by https://www.gitignore.io
11 | ### Vim ###
12 | # Swap
13 | [._]*.s[a-v][a-z]
14 | # comment out if you don't need vector files
15 | !*.svg
16 | [._]*.sw[a-p]
17 | [._]s[a-rt-v][a-z]
18 | [._]ss[a-gi-z]
19 | [._]sw[a-p]
20 |
21 | # Session
22 | Session.vim
23 | Sessionx.vim
24 |
25 | # Temporary
26 | .netrwhist
27 | *~
28 | tmp
29 | .tmp
30 | # Auto-generated tag files
31 | tags
32 | # Persistent undo
33 | [._]*.un~
34 |
35 | ### Emacs ###
36 | # -*- mode: gitignore; -*-
37 | *~
38 | \#*\#
39 | /.emacs.desktop
40 | /.emacs.desktop.lock
41 | *.elc
42 | auto-save-list
43 | tramp
44 | .\#*
45 |
46 | # Org-mode
47 | .org-id-locations
48 | *_archive
49 |
50 | # flymake-mode
51 | *_flymake.*
52 |
53 | # eshell files
54 | /eshell/history
55 | /eshell/lastdir
56 |
57 | # elpa packages
58 | /elpa/
59 |
60 | # reftex files
61 | *.rel
62 |
63 | # AUCTeX auto folder
64 | /auto/
65 |
66 | # cask packages
67 | .cask/
68 | dist/
69 |
70 | # Flycheck
71 | flycheck_*.el
72 |
73 | # server auth directory
74 | /server/
75 |
76 | # projectiles files
77 | .projectile
78 |
79 | # directory configuration
80 | .dir-locals.el
81 |
82 | # network security
83 | /network-security.data
84 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "redbean init",
6 | "detail": "Fetch redbean, zip and SQLite.",
7 | "type": "shell",
8 | "group": "build",
9 | "command": "./build.sh init",
10 | "windows": {
11 | "command": "wsl ./build.sh init"
12 | },
13 | "problemMatcher": []
14 | },
15 | {
16 | "label": "redbean pack",
17 | "detail": "Pack \"./srv/\" into a new redbean, overwriting the old.",
18 | "type": "shell",
19 | "group": {
20 | "kind": "build",
21 | "isDefault": true
22 | },
23 | "command": "./build.sh pack",
24 | "windows": {
25 | "command": "wsl ./build.sh pack"
26 | },
27 | "problemMatcher": []
28 | },
29 | {
30 | "label": "redbean run",
31 | "detail": "Pack, then execute with a customizable command.",
32 | "type": "shell",
33 | "group": "build",
34 | "command": "./build.sh run",
35 | "windows": {
36 | "command": "wsl ./build.sh run"
37 | },
38 | "problemMatcher": []
39 | },
40 | {
41 | "label": "redbean clean",
42 | "detail": "Delete all downloaded and generated files",
43 | "type": "shell",
44 | "group": "none",
45 | "command": "./build.sh clean",
46 | "windows": {
47 | "command": "wsl ./build.sh clean"
48 | },
49 | "problemMatcher": []
50 | }
51 | ]
52 | }
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Template for Redbean Projects
2 |
3 | This repo contains two options for managing your project: a shell script, and a
4 | Makefile.
5 |
6 | To make your redbean launch a browser on start, uncomment
7 | `LaunchBrowserOnStart()` in `srv/.init.lua`.
8 |
9 | M1 Mac users should use the default `MODE` instead of `asan-`, this can be set
10 | in the top of your Makefile/build.sh
11 |
12 | ### build.sh
13 |
14 | - `build.sh init`: download Redbean, zip, and sqlite
15 | - `build.sh pack`: put contents of `srv/` into a fresh redbean, overwriting
16 | previously existing bean.
17 | - `build.sh run`: pack and then execute custom command found at top of file
18 |
19 | Stock redbeans are hidden with dots. Executables are excluded in the
20 | `.gitignore`. Since they are *Actually Portable*, you *could* disable this
21 | behavior and commit the executables directly, if you're ok with keeping them in
22 | the git store. Also remember that binaries have a certain risk profile of their
23 | own.
24 |
25 | ### Makefile
26 |
27 | You can also use `make` to do the above.
28 |
29 | - `make` will do `make download` + `make add`
30 | - `make download` will download all of the requirements.
31 | - `make add` zips the contents of `/srv` into your `redbean.com`.
32 | - `make start` or `make start-daemon` will start the webserver (in foreground and background, respectively)
33 |
34 | See also: `make stop-daemon`, `make restart-daemon`, `make log`, `make ls`
35 |
36 | ### Roadmap
37 |
38 | - Build.sh
39 | - **INIT**: `build.sh init [-s for sqlite?]`
40 | - [x] Fetch Redbean, save as read-only stock build.
41 | - [x] Also fetch zip & sqlite
42 | - [ ] make sqlite opt-in
43 | - [ ] *Verify checksums for known versions/generate checksums for new
44 | ones*
45 | - **PACK** (default with no arguments)
46 | - [x] force copy stock redbean to writable file. Zip contents of `srv/`
47 | into zip
48 | - [ ] user-specified actions: if one script named `packer*` exists and is
49 | executable, run it
50 | - [ ] *if sqlite.com and `default.sqlite` exist, force copy
51 | `default.sqlite` to `db.sqlite`*
52 | - **RUN**
53 | - [x] pack and then execute command specified in variable
54 |
55 | ### Notable contributions
56 |
57 | - VSCode integration by [Danny Robinson
58 | (stellartux)](https://github.com/stellartux)
59 | - Makefile by [Jared Miller (shmup)](https://github.com/shmup)
60 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # /*─────────────────────────────────────────────────────────────────╗
2 | # │ To the extent possible under law, Jared Miller has waived │
3 | # │ all copyright and related or neighboring rights to this file, │
4 | # │ as it is written in the following disclaimers: │
5 | # │ • http://unlicense.org/ │
6 | # ╚─────────────────────────────────────────────────────────────────*/
7 | .PHONY: all clean test log ls log start start-daemon restart-daemon stop-daemon
8 |
9 | # Change redbean to whatever you want
10 | PROJECT=redbean
11 | REDBEAN=${PROJECT}.com
12 | REDBEAN_VERSION=2.2
13 | # leave empty for default, or use one of tiny-, asan-, original-, static-, unsecure-, original-tinylinux-
14 | # asan mode currently not working on M1 Macs
15 | #REDBEAN_MODE=
16 | REDBEAN_MODE=asan-
17 | REDBEAN_DL=https://redbean.dev/redbean-${REDBEAN_MODE}${REDBEAN_VERSION}.com
18 |
19 | SQLITE3=sqlite3.com
20 | SQLITE3_DL=https://redbean.dev/sqlite3.com
21 | ZIP=zip.com
22 | ZIP_DL=https://redbean.dev/zip.com
23 | UNZIP=unzip.com
24 | UNZIP_DL=https://redbean.dev/unzip.com
25 | DEFINITIONS=definitions/redbean.lua
26 | DEFINITIONS_DL=https://raw.githubusercontent.com/jart/cosmopolitan/2.2/tool/net/definitions.lua
27 |
28 | NPD=--no-print-directory
29 |
30 | all: download add
31 |
32 | download: ${REDBEAN} ${SQLITE3} ${ZIP} ${UNZIP} ${DEFINITIONS}
33 |
34 | ${REDBEAN}.template:
35 | curl -s ${REDBEAN_DL} -o $@ -z $@ && \
36 | chmod +x $@
37 |
38 | ${REDBEAN}: ${REDBEAN}.template
39 | cp ${REDBEAN}.template ${REDBEAN}
40 |
41 | ${SQLITE3}:
42 | curl -s ${SQLITE3_DL} -o $@ -z $@
43 | chmod +x ${SQLITE3}
44 |
45 | ${ZIP}:
46 | curl -s ${ZIP_DL} -o $@ -z $@
47 | chmod +x ${ZIP}
48 |
49 | ${UNZIP}:
50 | curl -s ${UNZIP_DL} -o $@ -z $@
51 | chmod +x ${UNZIP}
52 |
53 | ${DEFINITIONS}:
54 | mkdir -p definitions
55 | curl -s ${DEFINITIONS_DL} -o $@ -z $@
56 |
57 | add: ${ZIP} ${REDBEAN}
58 | cp -f ${REDBEAN}.template ${REDBEAN}
59 | cd srv/ && ../${ZIP} -r ../${REDBEAN} `ls -A`
60 |
61 | ls: ${UNZIP}
62 | @./${UNZIP} -vl ./${REDBEAN} | grep -v \
63 | 'usr/\|.symtab'
64 |
65 | log: ${PROJECT}.log
66 | tail -f ${PROJECT}.log
67 |
68 | start: ${REDBEAN}
69 | ./${REDBEAN} -vv
70 |
71 | start-daemon: ${REDBEAN}
72 | @(test ! -f ${PROJECT}.pid && \
73 | ./${REDBEAN} -vv -d -L ${PROJECT}.log -P ${PROJECT}.pid && \
74 | printf "started $$(cat ${PROJECT}.pid)\n") \
75 | || echo "already running $$(cat ${PROJECT}.pid)"
76 |
77 | restart-daemon:
78 | @(test ! -f ${PROJECT}.pid && \
79 | ./${REDBEAN} -vv -d -L ${PROJECT}.log -P ${PROJECT}.pid && \
80 | printf "started $$(cat ${PROJECT}.pid)") \
81 | || kill -HUP $$(cat ${PROJECT}.pid) && \
82 | printf "restarted $$(cat ${PROJECT}.pid)\n"
83 |
84 | stop-daemon: ${PROJECT}.pid
85 | @kill -TERM $$(cat ${PROJECT}.pid) && \
86 | printf "stopped $$(cat ${PROJECT}.pid)\n" && \
87 | rm ${PROJECT}.pid \
88 |
89 | clean:
90 | rm -f ${PROJECT}.log ${PROJECT}.pid ${REDBEAN} ${REDBEAN}.template ${SQLITE3} ${ZIP} ${UNZIP} ${DEFINITIONS}
91 | [ "$(ls -A definitions)" ] || rm -rf definitions
92 |
--------------------------------------------------------------------------------