# spa-dev-server

> Single page front-end application development server with API proxy and live reload

Latest version **0.0.8** (published 2022-07-16) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install spa-dev-server
pnpm add spa-dev-server
yarn add spa-dev-server
bun add spa-dev-server
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2022-07-16 |
| First published | 2022-07-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Evgeniy Kuvshinov |
| Maintainers | kib357 |

## Links

- npm: https://www.npmjs.com/package/spa-dev-server
- Repository: https://github.com/kib357/spa-dev-server
- Homepage: https://github.com/kib357/spa-dev-server#readme
- Issues: https://github.com/kib357/spa-dev-server/issues
- npm.io page: https://npm.io/package/spa-dev-server

## Recent versions

- 0.0.8 (latest) — 2022-07-16
- 0.0.6 — 2022-07-15
- 0.0.5 — 2022-07-15
- 0.0.4 — 2022-07-15
- 0.0.3 — 2022-07-15
- 0.0.2 — 2022-07-15
- 0.0.1 — 2022-07-15

## README

# spa-dev-server

Front-end application development server with API proxy and live reload, suitable for ESBuild and other bundlers.

[WARNING] It's NOT a production server for static files!

## Features

- Static files serving from passed `dir`.
- Serve index.html from main dir or given `indexPath`, supports HTML5 history API fallback.
- Proxy API requests to prevent CORS errors.
- Live reload opened tabs with `server.livereload.sendReload()`.
- ESBuild plugin
- Zero dependencies and small size. Server uses `http` module directly without large production HTTP libraries, like "express".

## Installation

```
npm i spa-dev-server
```

## Usage

### Basic

```typescript
const path = require('path')
const DevSever = require('spa-dev-server')

DevServer.create({
  dir: path.resolve(__dirname, './dist'),
  port: 3000,
  indexPath: path.resolve(__dirname, './http/dev.html'),
});
```

### Custom HTTP server

```typescript
const http = require('http')
const path = require('path')
const DevSever = require('spa-dev-server')

const server = http.createServer()

DevServer.create({
  server,
  dir: path.resolve(__dirname, './dist')
});

server.listen(3000)
```

### Proxy API requests

```typescript
const path = require('path')
const DevSever = require('spa-dev-server')

DevServer.create({
  dir: path.resolve(__dirname, './dist'),
  proxy: [
    { filter: /^\/api/, host: "localhost", port: 4000 },
    {
      filter: (req) => req.headers["content-type"] === "application/json",
      host: "localhost",
      port: 8080,
    },
  ],
});
```

### ESBuild

```typescript
import path from "path";
import DevServer from "spa-dev-server";
import esbuild from "esbuild";

const start = async () => {
  const dir = path.resolve(__dirname, "./dist")
  const server = await DevServer.create({ dir });

  esbuild.build({
    bundle: true,
    entryPoints: ["./src/index.tsx"],
    outdir: dir,
    plugins: [server.getEsbuildPlugin()],
    watch: true,
  });
};

start();
```

## Options

### Server Options
```typescript
type ServerOptions = {
  dir: string; // Build output directory to serve files from
  indexPath?: string; // Custom path to index HTML file
  port?: number // Dev server port. Default: 3000
  proxy?: ProxyOptions[]; // Array of proxy configurations, see ProxyOptions below
  server?: http.Server; // Custom HTTP server
  verbose?: boolean; // Print request logs. Default: true
};
```

### Proxy Options
```typescript
type ProxyOptions = {
  filter: RegExp | { (req: http.IncomingMessage): boolean }; // Requests should match this filter
  host: string; // Destination server host
  https?: boolean; // Use https. Default: false
  port?: number; // Destination server port
};
```

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