Thanks to visit codestin.com
Credit goes to github.com

Skip to content

leochiu-a/gh-serve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gh-serve

A lightweight, zero-dependency static file server built with Node.js. Perfect for serving static websites locally during development or for GitHub Pages preview.

Installation

npm install -g gh-serve

Or use directly with npx:

npx gh-serve

Usage

Basic Usage

Serve files from the current directory:

gh-serve

Serve files from a specific directory:

gh-serve ./public

With Base URL

Simulate GitHub Pages subpath deployment (e.g., username.github.io/repo-name):

gh-serve ./dist --base /my-repo

or using the short flag:

gh-serve ./dist -b /my-repo

Your site will be available at http://localhost:3000/my-repo

Custom Port

Use the PORT environment variable:

PORT=8080 gh-serve

Command Line Options

  • Directory path: First positional argument (default: ./demos)
  • --base, -b <path>: Set a base URL path for serving files

Examples

# Serve current directory on port 3000
gh-serve .

# Serve dist folder with base URL
gh-serve ./dist --base /my-project

# Serve on custom port
PORT=8080 gh-serve ./public

# Preview GitHub Pages locally
gh-serve ./docs -b /repository-name

Development

Prerequisites

  • Node.js 16 or higher
  • pnpm (recommended) or npm

Setup

# Install dependencies
pnpm install

# Run in development mode
pnpm dev

# Build
pnpm build

Project Structure

gh-serve/
├── src/
│   └── serve.ts      # Main server implementation
├── dist/             # Built output (after running pnpm build)
├── package.json
└── tsconfig.json

Contributing

Contributions are welcome! Please follow the commit conventions when submitting changes.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published