An open API service indexing awesome lists of open source software.

https://github.com/zopdev/static-server

A server written in golang using gofr framework which can serve static files.
https://github.com/zopdev/static-server

Last synced: about 1 month ago
JSON representation

A server written in golang using gofr framework which can serve static files.

Awesome Lists containing this project

README

          

# Static Server

A simple and efficient solution for serving static files.

## Features

- **Easy to use**: Just place your static files in the `static` directory, and the server takes care of the rest.
- **Dockerized**: Easily deployable as a Docker container.
- **Lightweight**: Minimal dependencies for optimal performance.
- **Configurable**: You can easily configure the server or extend it based on your needs.
- The server serves files from the `static` directory by default, but you can change this by setting the `STATIC_DIR_PATH` environment variable.
- Support all the confgs of the gofr framework - https://gofr.dev

## Usage

### 1. Build a Docker image

To deploy the server, you need to build a Docker image using the provided `Dockerfile`.

#### Example `Dockerfile`

```dockerfile
# Use the official static-server image as the base image
# This will pull the latest prebuilt version of the static-server to run your static website
FROM zopdev/static-server:latest

# Copy static files into the container
# The 'COPY' directive moves your static files (in this case, located at '/app/out') into the '/website' directory
# which is where the static server expects to find the files to serve
COPY /app/out /static

# Expose the port on which the server will run
# By default, the server listens on port 8000, so we expose that port to allow access from outside the container
EXPOSE 8000

# Define the command to run the server
# The static server is started with the '/main' binary included in the image, which will start serving
# the files from the '/website' directory on port 8000
CMD ["/main"]
```

### 2. Build the Docker image

Navigate to your project directory and run the following command to build the Docker image:

```bash
docker build -t static-server .
```

This command:
- Uses the `Dockerfile` in the current directory (`.`) to build an image.
- Tags the image with the name `static-server` (`-t static-server`).

### 3. Run the Docker container

Once the image is built, run the container using the following command:

```bash
docker run -d -p 8000:8000 static-server
```

This command:
- Runs the container in detached mode (`-d`).
- Maps port 8000 on your host machine to port 8000 inside the container (`-p 8000:8000`), so you can access the static files via `http://localhost:8000`.

### 4. Access your static website

Once the container is running, you can visit your website at:

```
http://localhost:8000
```

Your static files will be served, and the root (`/`) will typically display your `index.html` (if present).

## Notes

- The server serves all files in the `website` directory, so make sure to avoid any sensitive files or configuration details in that directory.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.