From e623c45da65b61bd455e356c8bf9692ee4354037 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Tue, 26 May 2015 22:34:51 +0200 Subject: [PATCH] Allow serving of static files through 'static_dir' directive. --- doc/MANUAL.md | 27 +++++++++++++++++ examples/static_serve/job_serve.sh | 5 ++++ examples/static_serve/static/ssh_server.png | Bin 0 -> 3015 bytes examples/static_serve/static_serve.json | 15 ++++++++++ src/scriptform.py | 31 ++++++++++++++++++-- 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 examples/static_serve/job_serve.sh create mode 100644 examples/static_serve/static/ssh_server.png create mode 100644 examples/static_serve/static_serve.json diff --git a/doc/MANUAL.md b/doc/MANUAL.md index b67e4de..295fcc5 100644 --- a/doc/MANUAL.md +++ b/doc/MANUAL.md @@ -115,6 +115,10 @@ Structurally, they are made up of the following elements: - **`title`**: Text to show at the top of each page. **Required**, **String**. +- **`static_dir`**: Path to a directory from which static files should be + served. See also "[Serving static files](#output_static_files)". + **Optional**, **String**. + - **`forms`**: A list of dictionaries of form definitions. **Required**, **List of dictionaries**. @@ -370,6 +374,29 @@ and shown to the user in the browser. If a script's exit code is not 0, it is assumed an error occured. Scriptform will show the script's stderr output (in red) to the user instead of stdin. +### Serving static files + +Scriptform can serve static files. It is disabled by default. To enable it, +provide a `static_dir` option in the top section of the form configuration: + + { + "title": "Static serve", + "static_dir": "static", + "forms": [ + ... + +This tells Scriptform to serve static files from that location. To refer to a +static file, use the `/static` URL: + + https://example.com/static?fname=foobar.png + +Will refer to the `static/foobar.png` file. If `static_dir` is a relative path, +it will be relative to the form configuration (.json) file you're running. + +Scriptform does not provide the browser with a content-type of the file, since +it is impossible to guess. Generally, browsers do a decent job at figuring it +out themselves. + ## Script execution When the user submits the form, scriptform will validate the provided values. diff --git a/examples/static_serve/job_serve.sh b/examples/static_serve/job_serve.sh new file mode 100755 index 0000000..61cbf72 --- /dev/null +++ b/examples/static_serve/job_serve.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cat < +ENDOFTEXT diff --git a/examples/static_serve/static/ssh_server.png b/examples/static_serve/static/ssh_server.png new file mode 100644 index 0000000000000000000000000000000000000000..f79c801a49a9cced361a9c9076fa5126ce547c0b GIT binary patch literal 3015 zcmaJ@dpy(oA70oRQm$bqnx#T!o941LV~lLETvjZ^Y>UM%w#nRzR6?ET;&Mz!64K43 ziw+S&k;_t(Z?|gs?==Kvoc&YXh68tbsw3GkBPxV}VZvw*HJ*}B(^_g76j@Q zQhL~D354RtrrTF;mHvYMaO`cWQ}gB1iq0jLvuYY!RX`gRA@MBw#O2ZDiN51+(!wOt z)~x8yi_12nJC-A1fK;o{{=duEd3DG&r+nqo6c=BK^Nj3OpI6&&+0yJ!?Rkt+@=u^Ab>IDz^n;9GE8>@mp3?|g$a&k6FJX+5V~Qh4<%)m0i(i9 zr^#yWvz@)m6#(l3Hq6NN^oYK z4#1X?tR(vT#&HGbVvQNYbIq2=5vu}Jd#2uKffY=~e%tex*9b4MJ{}%!(CRyj>7`s) zusGr0BcHJgm;ygN2Qv|}Sm@(Z{MgcbxGyu-)(B=EiW_;qj zI_)jB{xPjk@N@C8`&E+gwI=e|MX5{hpn)LcX}F8;Nh7;%c)9ZpaRAW7YwuKnx;r|r zrrQ;?w|GkRUbgBy@g&+H`pi#`0GE0lE0x4m&ohj#wpXO?M#MVVHRkDoLKI&%*VXmj zcMss*4TrH?n7tPyE>;G$4&xg(fC=F{o`=sso@usk(2je!3_0Wz?@>PDZnpRYfIPB( zu13xgS&}a`rQk8zz+r5cmF1FDKIVnSke6lW<-mTl#^(msc>Badjdje|_BG1S?k0gDCL;%~ zoL(L0SJ?Rgmex{`(Z(FrQxcR9=Hu3-PH`*_<6cb}90AQP=GZwKW$7iJ8#NnD+FahI z-Bo(mS|!U^v3o9CSb^9Siv!5rOZI8*d2iiY==KR;{91!TKB8c>O0f-@QP<9arj4%NM!$N=RlM(eU1DP^u~!GZrRbQZZ%EC|hcR(OEdHQwj6j|L_Ns41@Dy#| z%M-a2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