# orator-static-server

> Static file serving for Orator API servers.

Latest version **2.1.4** (published 2026-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install orator-static-server
pnpm add orator-static-server
yarn add orator-static-server
bun add orator-static-server
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.1.4 |
| Published | 2026-05-08 |
| First published | 2024-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 86.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | steven velozo |
| Maintainers | stevenvelozo |

## Links

- npm: https://www.npmjs.com/package/orator-static-server
- Repository: https://github.com/stevenvelozo/orator-static-server
- Homepage: https://github.com/stevenvelozo/orator-static-server#readme
- Issues: https://github.com/stevenvelozo/orator-static-server/issues
- npm.io page: https://npm.io/package/orator-static-server

## Dependencies (4)

- [mime](https://npm.io/package/mime.md) ^4.1.0
- [finalhandler](https://npm.io/package/finalhandler.md) ^2.1.1
- [serve-static](https://npm.io/package/serve-static.md) ^2.2.1
- [fable-serviceproviderbase](https://npm.io/package/fable-serviceproviderbase.md) ^3.0.19

## Recent versions

- 2.1.4 (latest) — 2026-05-08
- 2.1.3 — 2026-04-24
- 2.1.2 — 2026-04-24
- 2.1.1 — 2026-04-24
- 2.0.4 — 2026-02-27
- 2.0.3 — 2026-02-19
- 2.0.1 — 2026-02-18
- 2.0.0 — 2026-02-16
- 1.0.2 — 2026-02-16
- 1.0.1 — 2024-11-26
- 1.0.0 — 2024-11-23

## README

# Orator Static Server

> Static file serving for Orator API servers

Orator Static Server provides static file serving capabilities for Orator. The core static file serving functionality is built directly into the main [orator](https://github.com/stevenvelozo/orator) module via the `addStaticRoute` method, which serves files from disk with MIME type detection and subdomain-based folder routing.

## Features

- **File Serving** - Serve static files from any directory on disk
- **MIME Detection** - Automatic Content-Type headers based on file extension
- **Default Files** - Configurable default file (e.g., `index.html`) for directory requests
- **Route Stripping** - Strip URL prefixes before mapping to the filesystem
- **Subdomain Routing** - Serve different folders based on request subdomain

## Usage

Static file serving is available through the main Orator module's `addStaticRoute` method:

```javascript
const libFable = require('fable');
const libOrator = require('orator');
const libOratorServiceServerRestify = require('orator-serviceserver-restify');

const _Fable = new libFable({
	Product: 'MyStaticServer',
	ServicePort: 8080
});

_Fable.serviceManager.addServiceType('Orator', libOrator);
_Fable.serviceManager.addServiceType('OratorServiceServer', libOratorServiceServerRestify);
_Fable.serviceManager.instantiateServiceProvider('Orator');
_Fable.serviceManager.instantiateServiceProvider('OratorServiceServer');

// Serve static files from ./public
_Fable.Orator.addStaticRoute('./public/');

_Fable.Orator.startService();
```

## API

### addStaticRoute(pFilePath, pDefaultFile, pRoute, pRouteStrip, pParams)

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `pFilePath` | string | *required* | Path to the directory to serve files from |
| `pDefaultFile` | string | `"index.html"` | Default file for directory requests |
| `pRoute` | string | `"/*"` | Route pattern to match |
| `pRouteStrip` | string | `"/"` | URL prefix to strip before filesystem lookup |
| `pParams` | object | `{}` | Options passed to `serve-static` |

## Examples

### Single Page Application

```javascript
// All routes fall back to index.html
_Fable.Orator.addStaticRoute('./dist/', 'index.html', '/*');
```

### Serving Under a Subpath

```javascript
// /app/styles.css serves ./dist/styles.css
_Fable.Orator.addStaticRoute('./dist/', 'index.html', '/app/*', '/app/');
```

### API Server with Static Frontend

```javascript
// API routes first
_Fable.Orator.serviceServer.get('/api/data',
	(pRequest, pResponse, fNext) =>
	{
		pResponse.send({ value: 42 });
		return fNext();
	});

// Static files for everything else
_Fable.Orator.addStaticRoute('./public/', 'index.html', '/*');
```

## Subdomain Folder Routing

When a request arrives with a subdomain, Orator checks if a matching subfolder exists in the serve directory. If it does, files are served from that subfolder.

For a serve path of `./sites/`:
- `http://clienta.example.com/page.html` checks for `./sites/clienta/page.html`
- If `./sites/clienta/` exists, it serves from there
- Otherwise, falls back to `./sites/page.html`

## Documentation

Full documentation is available in the [`docs`](./docs) folder, or served locally:

```bash
npx docsify-cli serve docs
```

## Related Packages

- [orator](https://github.com/stevenvelozo/orator) - API server abstraction
- [orator-serviceserver-restify](https://github.com/stevenvelozo/orator-serviceserver-restify) - Restify service server implementation
- [fable](https://github.com/stevenvelozo/fable) - Application services framework

## License

MIT

## Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the [Retold Contributing Guide](https://github.com/stevenvelozo/retold/blob/main/docs/contributing.md).

---
_Source: https://npm.io/package/orator-static-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
