quickserv

2025-12-07 0 513

QuickServ

Quick, nosetup web Server

About

QuickServ makes creating web applications dangerously easy, no
matter what programming language you use.

QuickServ is a dependency-free, statically-linked, single-file web server that:

  • Has sensible defaults
  • Prints helpful error messages directly to the console
  • Runs on any modern computer, with no setup or installation
  • Needs no configuration
  • Knows which files to run server-side, and which to serve plain
  • Works with any programming language that can read and write
  • Doesn\’t require understanding the intricacies of HTTP
  • Enables Cross Origin Request Sharing (CORS) by default
  • Works with or without the command line

QuickServ brings the heady fun of the 1990s Internet to the 2020s. It is
inspired by the Common Gateway Interface
(CGI), but is much
easier to set up and use. Unlike CGI, it works out of the box with no searching
for obscure log files, no learning how HTTP headers work, no fiddling with
permission bits, no worrying about CORS, no wondering where to put your scripts,
and no struggling with Apache mod_cgi configurations.

Unlike with CGI, you don\’t have to know what anything from the previous
paragraph means to use QuickServ.

It is perfect for:

  • Building hackathon projects without learning a web framework
  • Creating internal tools
  • Prototyping web applications using any language
  • Attaching web interfaces to scripts
  • Controlling hardware with Raspberry Pis on your local network
  • Trying out web development without being overwhelmed

QuickServ should not be used on the public Internet. It should only be used on
private networks.

Get Started

Using QuickServ is as easy as downloading the program, dragging it to your
project folder, and double clicking to run. It automatically detects which files
to execute, and which to serve directly to the user.

Windows

Click to view details
  1. Download for
    Windows.

  2. Make a project folder and add files to it. For example, if Python is
    installed, create a file called test.py in the project folder containing:

    #!python
    
    # Put your code here. For example:
    import random
    print(random.randint(0, 420))

    Since test.py starts with #!something, where something test.py is the
    command to execute the file, QuickServ will know to run it. If QuickServ is
    not running your file, make sure to add this to the beginning.

    On Windows, QuickServ also knows to automatically run files that end in
    .exe and .bat. Any other file type needs to start with #!something if
    it should be run.

  3. Move the downloaded quickserv_windows_x64.exe file to the project folder.

  4. Double click quickserv_windows_x64.exe in the project folder to start
    QuickServ. Allow access through Windows Defender if prompted.

  5. Go to http://127.***0.0.1:42069 (or the address shown by QuickServ) to connect
    to your web application. In the example, to run test.py, go to
    http://127.***0.0.1:42069/test.py.

Mac

Click to view details
  1. Download the right version for your computer. If necessary, check what type
    of processor your Mac
    has.
    You will have to unzip the files after you download them.

    • Download for
      Intel.
    • Download for Apple
      Silicon.
  2. Make a project folder and add files to it. For example, if Python is
    installed, create a file called test.py in the project folder containing:

    #!python
    
    # Put your code here. For example:
    import random
    print(random.randint(0, 420))

    If you are making the file with TextEdit, you will need to go into Format > Make Plain Text to save the file in the correct format.

    Since test.py starts with #!something, where something test.py is the
    command to execute the file, QuickServ will know to run it. If QuickServ is
    not running your file, make sure to add this to the beginning.

    On Mac, QuickServ also knows to automatically run files that have been
    compiled. Any other file type needs to start with #!something if it should
    be run.

  3. Move the downloaded quickserv_macos_x64 or quickserv_macos_arm64 file to
    the project folder.

  4. Right click quickserv_macos_x64 or quickserv_macos_arm64 in the project
    folder and select \”Open.\” Then, press \”Open\” in the confirmation dialog box.
    After running it this way once, you will be able to start QuickServ by simply
    double-clicking the file.

  5. Go to http://127.***0.0.1:42069 (or the address shown by QuickServ) to connect
    to your web application. In the example, to run test.py, go to
    http://127.***0.0.1:42069/test.py.

Raspberry Pi

Click to view details

It\’s easiest to install and run via the command line. Open the
Terminal.

Enter the following commands. A password may be required for the first commands.

# Download
sudo curl \\
    --location \\
    --output /usr/local/bin/quickserv \\
    https://git*hub.c**om/jstrieb/quickserv/releases/latest/download/quickserv_raspi_arm

# Make executable
sudo chmod +x /usr/local/bin/quickserv

# Make a project folder
mkdir -p my/project/folder

# Go to project folder
cd my/project/folder

# Add a test file 
cat <<EOF > test.py
#!python3

# Put your code here. For example:
import random
print(random.randint(0, 420))
EOF

# Run QuickServ
quickserv

Go to http://127.***0.0.1:42069 (or the address shown by QuickServ) to connect to
your web application. For example, to run test.py, go to
http://127.***0.0.1:42069/test.py.

Other Operating Systems

Click to view details

Clicking to run executables does not have consistent behavior across Linux
distros, so it\’s easiest to install and run via the command line. Depending
on your computer\’s architecture, it may be necessary to change the filename
at the end of the curl HTTP request URL below.

See all download options on the releases
page.

# Download
sudo curl \\
    --location \\
    --output /usr/local/bin/quickserv \\
    https://**gi*thub.com/jstrieb/quickserv/releases/latest/download/quickserv_linux_x64

# Make executable
sudo chmod +x /usr/local/bin/quickserv

# Make a project folder
mkdir -p /my/project/folder

# Go to project folder
cd /my/project/folder

# Add a test file 
cat <<EOF > test.py
#!python3

# Put your code here. For example:
import random
print(random.randint(0, 420))
EOF

# Run QuickServ
quickserv

Go to http://127.***0.0.1:42069 (or the address shown by QuickServ) to connect to
your web application. For example, to run test.py, go to
http://127.***0.0.1:42069/test.py.

Alternatively, use the instructions below to compile from source.

Compile From Source

Click to view details

Compile and install from source using the following command. A version of Go
greater than 1.16 is required because of the dependency on embedded filesystems.

go install github.com/jstrieb/quickserv@latest

Then create your project folder, populate it, and run QuickServ.

# Make a project folder
mkdir -p /my/project/folder

# Go to project folder
cd /my/project/folder

# Add a test file 
cat <<EOF > test.py
#!python3

# Put your code here. For example:
import random
print(random.randint(0, 420))
EOF

# Run QuickServ
quickserv

Tutorial

To demonstrate key features of QuickServ, we will build a simple web
application to perform addition. The code will not follow best practices, but
it will show how little is needed to get started building with QuickServ.

First, we create create a project folder and drag the QuickServ executable into
the folder, as in the getting started steps.

Next, inside the folder, we save the following text as index.html:

<form action=\"/calculate\">
<input name=\"first\" type=\"number\"> + <input name=\"second\" type=\"number\"> = ???
<br>
<button>Calculate</button>
</form>

This code submits two variables to the /calculate page. In the browser, it
looks like this:

Then, we create a folder called calculate inside the project folder. Inside
the calculate folder, we save the following code as index.py. The name
index.whatever tells QuickServ to run this file when a user visits
http://w*ebs*ite/*calculate instead of needing them to visit
http://w*ebs*ite/*calculate/index.py.

Pay special attention to the code comments. They highlight a number of
important QuickServ features.

#!python3

# Each QuickServ script must begin with a line like the one above so that
# QuickServ knows how to run the file. This line tells QuickServ that I would
# type `python3 this_file.py` to run this file at the command prompt. For
# example, if you wanted to do `julia this_file.py` instead, then you would
# make the first line of `this_file.py` be `#!julia`.
#
# Since we just want QuickServ to show the HTML code to the user and not run
# it, index.html does not begin with this. The first line is only required when
# QuickServ has to run the code.

import argparse

# All HTML form values get turned into command line arguments. The names are
# formatted like \"--name\" and the value comes right after the name.
parser = argparse.ArgumentParser()
parser.add_argument(\"--first\", type=int, required=True)
parser.add_argument(\"--second\", type=int, required=True)
args = parser.parse_args()

# Print the result -- anything printed out goes right to the user. In this
# case, the output is text. But you can print anything and QuickServ will guess
# the file type. Even printing the contents of image and video files works.
print(args.first + args.second)

Now double click QuickServ in your project folder and try it out in your
browser. That\’s it!

See the examples linked in the next section for more QuickServ demonstrations.
Read more details in the How it Works section, and in the code
itself. The Advanced section has additional information about the
environment QuickServ sets up for executables it runs.

Examples

All examples are located in the examples folder, which is a Git submodule
connected to the
jstrieb/quickserv-examples
repo. Go to that repo for more information on how to run the examples.

Some highlights:

Summary Language Windows Mac Linux
YouTube to GIF Shell
Create Bloom filters C
Synchronized movie list TypeScript
Brainfuck interpreter x86-64 Assembly
Mandelbrot zoom Shell
Cryptocurrency dashboard Go
PDF tools Python
Typeset Markdown as PDF Standard ML

How It Works

All of the QuickServ code lives in
quickserv.go.
This well-commented file is about 700 lines long, and should take an experienced
programmer with no Golang familiarity at most an hour to read.

Click to view details

QuickServ has two main parts. The first is an initialization procedure, run
exactly once at startup. The second is a handler function, called every time a
user makes an HTTP request to the server.

Initialization Routine

When QuickServ starts up, it checks for command-line configuration flags, opens
a log file if one is passed with --logfile (otherwise it logs to the standard
output), and changes directories if a working directory is passed with --dir.
Note that the log file path is relative to the current working directory, not
relative to the one passed with --dir.

Next, QuickServ scans the working directory for files to run. It prints all of
the files that will be executed. This behavior is useful for determining if
QuickServ recognizes a script as executable. It also prints helpful information
for the user such as the web address to visit to access the server, and what
folder the server is running in, as well as how to stop it.

If any part of the initialization fails, an error is reported. In the event of a
fatal error, QuickServ waits for user input before quitting. This way, a user
who double-clicks the executable (as opposed to starting it from the command
line) does not have a window appear and then immediately disappear, flashing too
quickly for the error to be read.

Error messages are purposefully written with as little technical jargon as
possible, though some is unavoidable. Likely causes for the errors are also
included in error messages, so that they are easier for users to identify and
fix.

As the last step in the initialization procedure, QuickServ starts a web server
with a single handler function for all requests. The server listens on the
default port of 42069, or on a random port if a user specified the
--random-port command-line flag. A random port would be desirable if the user
has to show a project built with QuickServ to someone humorless, for example.

Request Handler

When a user visits a web page, QuickServ handles the request by calling the lone
handler function.

First, this function tries to open the file the user requested. If it cannot
find or open the file, it tries to serve a default version of the file. For
example, there is an embedded, default favicon.ico that gets served. If there
is no default file matching the path, it lets the built-in Go fileserver handle
the error and respond with a 404 error code.

If the file the user requested is present, it checks whether it is a directory.
If it is a directory, QuickServ looks inside for a file named index.xxx where
xxx is any file extension. If an index file is found, the index is served (and
possibly executed) as if it were the original page requested. Otherwise, the
user must have requested a directory without a default index, so QuickServ
responds with a listing of the other files in the directory.

If the file the user requested is present and not a directory (i.e., it is a
regular file), QuickServ checks whether or not it is executable. If so, it
executes the file it found. If not, it returns the raw file contents to the
user. In both cases, QuickServ will guess what filetype (and therefore which
mimetype) to use for the response.

The technique for determining if a file is executable depends on the runtime
operating system. On Windows, any file with a .bat or .exe extension is
considered executable. On non-Windows systems, any file with the executable
permission bit set is considered executable. On all systems, a file is
executable if it has a valid pseudo-shebang at the beginning. The shebang must
be on the very first line, must begin with #!, and must be a valid command.
For example, both of the following are acceptable, assuming python3 is
installed and on the PATH:

  • #!/usr/bin/python3
  • #!python3

To execute a file, QuickServ either runs the file itself (if it is an .exe or
has the executable bit set), or it passes the file\’s path as the first argument
to the executable listed in its shebang. The request body is passed to the
program on standard input, and everything printed by the program on standard
output is used as the response body. Executed programs are neither responsible
for writing—nor able to write—HTTP response headers.

All parsed HTTP form variables (if the Content-Type is
x-www-form-urlencoded) are also passed as command line arguments when the
program is executed. This way, the user does not need to parse the variables
themselves.

Whatever the executed program prints on standard error is logged by QuickServ,
which means it gets printed in the console window by default. This is handy for
debugging. If the program terminates with a non-zero exit code, QuickServ
responds with a 500 internal server error. Otherwise it returns with a 200.

If the request is a URL-encoded POST request with form data, QuickServ
URL-decodes all of the characters except for three symbols: %, &, and =.
The user is responsible for substituting these. Note that it is important to
always URL-decode % last in the program that processes the form data.

Disclaimer

Do not run QuickServ on the public Internet. Only run it on private networks.

QuickServ is not designed for production use. It was not created to be fast or
secure. Using QuickServ in production puts your users and yourself at risk,
please do not do it.

QuickServ lets people build dangerously insecure things. It does not sanitize
any inputs or outputs. It uses one process per request, and is susceptible to a
denial of service attack. Its security model presumes web users are trustworthy.
These characteristics make prototyping easier, but are not safe on the public
Internet.

To deter using QuickServ in production, it runs on port 42069. Hopefully that
makes everyone think twice before entering it into a reverse proxy or port
forward config. For a more professional demo, the command-line flag
--random-port will instead use a random port, determined at runtime.

QuickServ is similar to the ancient CGI protocol. There are many
well-articulated, well-established reasons that CGI is bad in
production,
and they all apply to QuickServ in production.

Advanced

Command Line Options

QuickServ has advanced options configured via command line flags. These
change how and where QuickServ runs, as well as where it saves its output.

Usage: 
quickserv [options]

Options:
  --dir string
        Folder to serve files from. (default \".\")
  --logfile string
        Log file path. Stdout if unspecified. (default \"-\")
  --no-pause
        Don\'t pause before exiting after fatal error.
  --random-port
        Use a random port instead of 42069.

HTTP Headers & Environment Variables

In imitation of CGI, HTTP headers are passed to the executed program as
environment variables. A header called Header-Name will be set as the
environment variable HTTP_HEADER_NAME.

There is also a REQUEST_TYPE variable that specifies whether the request was
GET, POST, etc.

Read From Standard Input

HTTP requests with a body pass the body to the executed program on standard
input. In most cases, the request body is passed verbatim. This is not the case
for HTML forms.

HTML form data can either be read from command line arguments, as in the
tutorial, or parsed from standard input. Variables take the form

name=value&othername=othervalue

The simple addition example from the tutorial can be rewritten to
parse HTTP form values from the standard input instead of from the command line
arguments.

#!python3

import sys


# In the form input, \"=\" and \"&\" determine where variables start and end. So if
# they are literally included in the variable name or value, they must be
# specially decoded. This code replaces every instance of the text on the left
# with the text on the right to do the decoding:
#     %3D -> =
#     %26 -> &
#     %25 -> %
#
# NOTE: Order matters! \"%\" must be decoded last. If not, it can mess with
# decoding the others, since their encoded version uses \"%\"
def decode_characters(text):
    text = text.replace(\"%3D\", \"=\")
    text = text.replace(\"%26\", \"&\")
    text = text.replace(\"%25\", \"%\")
    return text

first = second = 0

# Read all of the input into a variable. We are expecting the raw data to look
# like:
#       first=123&second=456
data = sys.stdin.read()

# The raw data looks like the above, so split it into pairs at each \"&\"
pairs = data.split(\"&\")
for pair in pairs:
    # Each pair looks like the following, so split at each \"=\":
    #       name=value
    name, value = pair.split(\"=\")

    # Decode any special characters (=, &, %) now that we have split the
    # variables up. This isn\'t necessary here since we\'re expecting numbers and
    # not expecting any of those characters. But it matters a lot when a user
    # could submit text with those characters
    name = decode_characters(name)
    value = decode_characters(value)

    # If the name is what we\'re looking for, store the value for adding
    if name == \"first\":
        first = int(value)
    elif name == \"second\":
        second = int(value)

# Print the result -- anything printed out goes right to the user. In this
# case, the output is text. But you can print anything and QuickServ will try and
# guess the file type.
print(first + second)

Project Status & Contributing

This project is actively developed and maintained. If there are no recent
commits, it means that everything is running smoothly!

Please open an issue with any
bugs, suggestions, or questions. This especially includes discussions about how
to make error messages as clear as possible, and how to make the default
settings applicable to as many users as possible.

Pull requests without prior discussion will be ignored – don\’t waste time
writing code before confirming that it will be merged in. As a busy, lone
developer, it is easier to be responsive when all code contributions have
context.

If you make a blog post, video, tutorial, hackathon project, or anything else
using QuickServ, please open an
issue or message me on my
contact form so that I can link back
to it!

Support the Project

There are a few ways to support the project:

  • Star the repository and follow me on GitHub
  • Share and upvote on sites like Twitter, Reddit, and Hacker News
  • Report any bugs, glitches, or errors that you find
  • Translate into other languages so everyone can use the project
  • Build and share your own projects made with QuickServ

These things motivate me to to keep sharing what I build, and they provide
validation that my work is appreciated! They also help me improve the project.
Thanks in advance!

If you are insistent on spending money to show your support, I encourage you to
instead make a generous donation to one of the following organizations. By
advocating for Internet freedoms, organizations like these help me to feel
comfortable releasing work publicly on the Web.

  • Electronic Frontier Foundation
  • Signal Foundation
  • Mozilla
  • The Internet Archive

Acknowledgments

This project would not be possible without the help of:

  • Logan Snow
  • Amy Liu
  • Hacker News user rchaves, who
    helpfully suggested passing parsed form values as command line
    arguments
  • Everyone who supports the project

下载源码

通过命令行克隆项目:

git clone https://github.com/jstrieb/quickserv.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 quickserv https://www.zuozi.net/31535.html

Fantasy
上一篇: Fantasy
SignalW
下一篇: SignalW
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务