# @skazka/server-index

> Server index

Latest version **0.0.9** (published 2020-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @skazka/server-index
pnpm add @skazka/server-index
yarn add @skazka/server-index
bun add @skazka/server-index
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2020-03-29 |
| First published | 2019-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | skazkajs |
| Maintainers | evheniy.bystrov, skazkajs |
| Keywords | skazka, node.js, promise, body, http, server, rest, fast, async, await, https, ssl, easy, static |

## Links

- npm: https://www.npmjs.com/package/@skazka/server-index
- Repository: https://github.com/skazkajs/skazka/tree/master/packages/server/index
- Homepage: https://skazkajs.org/
- Issues: https://github.com/skazkajs/skazka/issues
- npm.io page: https://npm.io/package/@skazka/server-index

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2020-03-29
- 0.0.6 — 2020-03-29
- 0.0.1 — 2019-01-16
- 0.0.0 — 2019-01-09

## README

# Server index

Skazka Server Index is serving "index.html" file without caching.

There are 3 Skazka Server modules for working with static files:
- **Skazka Server Index** should be the first module for checking url and returning index.html file without cache.
- **Skazka Server Static** should be the second module for serving any static files with a cache system.
- **Skazka Server SPA** module should be the last module in the app chain (after router, graphQL...).
It returns index.html file for any request - the main idea of any SPA server.

[![NPM](https://nodei.co/npm/@skazka/server-index.png)](https://npmjs.org/package/@skazka/server-index)

## How to install

    npm i @skazka/server @skazka/server-index
    
With yarn:

    yarn add @skazka/server @skazka/server-index
    
##### Skazka Server static and spa:

    npm i @skazka/server @skazka/server-static @skazka/server-spa
    
With yarn:

    yarn add @skazka/server @skazka/server-static @skazka/server-spa
    
Optionally you can add http server, error handler, logger, router, request and response:

    npm i @skazka/server-http @skazka/server-router @skazka/server-error @skazka/server-logger @skazka/server-request @skazka/server-response
      
With yarn:

    yarn add @skazka/server-http @skazka/server-router @skazka/server-error @skazka/server-logger @skazka/server-request @skazka/server-response

## How to use

```javascript
const { resolve } = require('path');

const App = require('@skazka/server');
const Router = require('@skazka/server-router');

const index = require('@skazka/server-index');
const serve = require('@skazka/server-static');
const spa = require('@skazka/server-spa');
        
const error = require('@skazka/server-error');
const logger = require('@skazka/server-logger');

const request = require('@skazka/server-request');
const response = require('@skazka/server-response');
        
const server = require('@skazka/server-http');
        
const app = new App();
const router = new Router();

const root = resolve(__dirname, 'dist');

app.all([
  error(),
  logger(),
  request(),
  response(),
  index({ root }),
]).then(serve({ root, index: false }));
    
app.then(async (ctx) => {
  // it works for any request
});
    
router.get('/data').then(async (ctx) => {
  return ctx.response('data'); 
});
        
app.then(router.resolve());

app.then(spa({ root }));

server.createHttpServer(app);
```

### Options

- **root** - directory with index file, by default: __dirname.
- **index** - file name, by default: index.html (you can use for example index.htm...).
- **url** - it works only for this url, by default: "/".

Example with all options:

```javascript
app.all([
  ...
  index({
    root: resolve(__dirname, 'dist'),
    index: 'index.html',
    url: '/',
  }),
]);
```

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