Aiursoft.Static 8.0.10

dotnet tool install --global Aiursoft.Static --version 8.0.10                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local Aiursoft.Static --version 8.0.10                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Aiursoft.Static&version=8.0.10                
nuke :add-package Aiursoft.Static --version 8.0.10                

Aiursoft.Static

MIT licensed Pipeline stat Test Coverage NuGet version (Aiursoft.Static) ManHours Docker

Static is a simple static files HTTP server, as a global tool.

Install

Requirements:

  1. .NET 8 SDK

Run the following command to install this tool:

dotnet tool install --global Aiursoft.Static

Usage

After getting the binary, run it directly in the terminal.

$ static.exe  --help
Description:
  Start a static file server.

Usage:
  static [options]

Options:
  -p, --port <port>           The port to listen for the server. [default: 8080]
  --path <path>               The folder to start the server. [default: .]
  --allow-directory-browsing  Allow directory browsing the server files under the path. This options if conflict with --mirror. [default: False]
  --mirror <mirror>           The website to mirror. Automatically proxy the file if the file is not found in the server. This option if conflict with --allow-directory-browsing.
  --cache-mirror              Cache the mirrored files. This will save the mirrored files to the servers disk. [default: True]
  --enable-webdav             Enable WebDAV for the server. This is a read-only WebDAV server. [default: False]
  --version                   Show version information
  -?, -h, --help              Show help and usage information

It will start an HTTP server on http://localhost:8080.

Install for all users

You can install this tool for all users by running the following command:

sudo apt install -y dotnet8
sudo dotnet tool install Aiursoft.Static --tool-path /opt/static || sudo dotnet tool update Aiursoft.Static --tool-path /opt/static
sudo chmod +x /opt/static/static

Then you can run the tool by /opt/static/static.

Install for systemd

You can make it a systemd service by creating a file /etc/systemd/system/static.service with the following content:

[Unit]
Description=Serves static files for '/mnt/data' on port 48466
After=network.target
Wants=network.target

# Before starting, run:
# find /mnt/data -type d -print0 | sudo xargs -0 chmod 0755
# find /mnt/data -type f -print0 | sudo xargs -0 chmod 0644
# So www-data user can read the files
# Also owner user can write to the files
[Service]
User=www-data
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/opt/static/static --path /mnt/data -p 48466 --allow-directory-browsing
WorkingDirectory=/mnt/data
LimitNOFILE=1048576
KillSignal=SIGINT
Environment="ASPNETCORE_ENVIRONMENT=Production"
Environment="DOTNET_PRINT_TELEMETRY_MESSAGE=false"
Environment="DOTNET_CLI_TELEMETRY_OPTOUT=1"
Environment="ASPNETCORE_FORWARDEDHEADERS_ENABLED=true"

[Install]
WantedBy=multi-user.target

Then you can start the service by running:

sudo systemctl enable static
sudo systemctl start static
sudo systemctl status static

Run in Docker

First, install Docker here.

Then run the following commands in a Linux shell:

image=hub.aiursoft.cn/aiursoft/static
appName=static
sudo docker pull $image
sudo docker run -d --name $appName --restart unless-stopped -p 5000:5000 -v /var/www/$appName:/data $image

That will start a web server at http://localhost:5000 and you can test the app.

The docker image has the following context:

Properties Value
Image hub.aiursoft.cn/aiursoft/static
Ports 5000
Binary path /app
Data path /data

Use Aiursoft.Static to build your own Docker image

You can use Aiursoft.Static to build your own Docker image. Here is an example of a Dockerfile:

Assuming that you have a React project in the current directory that can be built with yarn build and the output is in the build directory.

# ============================
# Prepare Build Environment
FROM hub.aiursoft.cn/node:21-alpine as npm-env
WORKDIR /src
COPY . .
RUN yarn
RUN yarn build

# ============================
# Prepare Runtime Environment
FROM hub.aiursoft.cn/aiursoft/static
COPY --from=npm-env /src/build /data

If you want to override the default behavior, simply add the entrypoint key to the service.

FROM hub.aiursoft.cn/aiursoft/static
COPY --from=npm-env /app/public /data

ENTRYPOINT [ "/app/static", "--port", "5000", "--path", "/data", "--not-found-page", "/404.html" ]

Use Aiursoft.Static in docker-compose

You can use Aiursoft.Static in docker-compose. Here is an example of a docker-compose.yml:

version: '3.7'

services:
  static:
    image: hub.aiursoft.cn/aiursoft/static
    volumes:
      - your-volume:/data

If you want to override the default behavior, simply add the entrypoint key to the service.

version: '3.7'

services:
  static:
    image: hub.aiursoft.cn/aiursoft/static
    volumes:
      - your-volume:/data
    entrypoint: ["sh", "-c", "/app/static --port 5000 --path /data/mirror/archive.ubuntu.com --allow-directory-browsing"]

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.

We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
8.0.10 117 10/15/2024
8.0.9 99 10/10/2024
8.0.8 91 10/7/2024
8.0.7 139 8/12/2024
8.0.6 115 7/10/2024
8.0.5 163 6/29/2024
8.0.4 115 6/28/2024
8.0.3 166 4/23/2024
8.0.2 196 3/13/2024
8.0.1 192 2/19/2024
8.0.0 179 2/19/2024
7.0.21 130 2/18/2024
7.0.19 155 2/18/2024
7.0.18 177 2/18/2024
7.0.17 163 2/18/2024
7.0.16 175 2/18/2024
7.0.15 155 2/18/2024
7.0.14 209 2/8/2024
7.0.13 191 2/8/2024
7.0.12 182 2/8/2024
7.0.11 173 2/8/2024
7.0.10 178 2/2/2024
7.0.9 188 1/30/2024
7.0.8 269 12/12/2023
7.0.7 175 12/12/2023
7.0.6 170 12/12/2023
7.0.5 200 12/6/2023
7.0.4 136 12/6/2023
7.0.3 168 12/6/2023
7.0.2 181 12/6/2023
7.0.1 241 11/2/2023
7.0.0 273 9/5/2023
1.0.1 263 8/20/2023