open-index/open-npm huggingface dataset:
npm package: @itznotabug/appexpress-apicache
Description: A api caching middleware for AppExpress.
Author: @itznotabug
Latest version: 0.0.5

# AppExpress API Cache Middleware

This module allows you to cache API responses for a specified period of time.

The responses are cached in memory after the first request, up until the function container is removed.\
You can check for `X-APPEXPRESS-API-CACHE` in the response header, the values will be any one of the below -

1. `HIT` - response is cached
2. `MISS` - response is not cached, probably this is the first request
3. `EXCLUDED` - the request is excluded for caching response via options or response header
4. `IGNORED` - the request method is either `PUT`, `POST` or `DELETE` which are never cached

## Installation

Add the middleware like this -

```shell
npm install @itznotabug/appexpress-apicache
```

## Usage

```javascript
// import
import AppExpress from '@itznotabug/appexpress';
import * as cache from '@itznotabug/appexpress-apicache';

// setup
const express = new AppExpress();

express.middleware(cache.createApiCache({
    excludes: ['/admin'],
    timeout: 1000 * 60 * 5 // 5 minutes, use 0 for no expiry! 
}));
```

### Excluding a particular request -

```javascript
express.get('/user/paymentMethods', async (req, res) => {
  const user = await sdk.getUser(req);
  const paymentMethods = await sdk.getPaymentMethods(user);

  res.setHeaders({ 'apicache-exclude': true });
  res.json({ paymentMethods })
});
```

### Different cache timeout for a response -

```javascript
express.get('/user/code', async (req, res) => {
  const timedContent = await sdk.timedContent(req);

  const oneMinute = 60 * 1000;
  res.setHeaders({ 'apicache-timeout': oneMinute });
  res.json({ timedContent })
});
```

### Check if cache exists for a URL

```javascript
express.get('/search/results', async (req, res) => {
  if (cache.hasCache(req.url)) {
    res.empty();
    return;
  }

  const thirtySeconds = 30 * 1000;
  const { searchText } = req.params;
  const results = await sdk.search(searchText);

  res.setHeaders({ 'apicache-timeout': thirtySeconds });
  res.json({ results })
});
```

### Clear a cache for url or all cache

```javascript
cache.clearCache(url);

// remove all
cache.clearAllCache();
```
npm package: @itznotabug/appexpress-cors
Description: A cors middleware for AppExpress.
Author: @itznotabug
Latest version: 0.0.2

# AppExpress `CORS` Middleware

This module allows you to specify `cors` policy for your Appwrite Functions with `AppExpress`.

## Installation

Add the middleware like this -

```shell
npm install @itznotabug/appexpress-cors
```

## Usage

```javascript
// import
import cors from '@itznotabug/appexpress-cors';
import AppExpress from '@itznotabug/appexpress';

// setup
const express = new AppExpress();

express.middleware(cors({
    origin: '*', // specify an origin or * for all,
    excludes: ['/styles.css'], // exclude cors on some urls, accepts String & Regex,
    preFlightContinue: false, // if false, empty response is sent on `OPTIONS` method,
    optionsSuccessStatus: 204, // status code to be sent on `OPTIONS`,
    methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'], // allowed methods for cors,
}));
```
npm package: @itznotabug/appexpress-favicon
Description: A favicon middleware for AppExpress.
Author: @itznotabug
Latest version: 0.0.3

# AppExpress Favicon Middleware

This module allows you to use a `favicon.ico` in your Appwrite Functions with `AppExpress`.

The `favicon.ico` is saved in memory after the first request until the function container is removed.

**Here's a [Live Demo for reference](https://appexpress.appwrite.global)!**

## Installation

Add the middleware like this -

```shell
npm install @itznotabug/appexpress-favicon
```

## Usage

```javascript
// import
import AppExpress from '@itznotabug/appexpress';
import favIcon from '@itznotabug/appexpress-favicon';

// setup
const express = new AppExpress();

// if you serve static content & 
// the favicon is in public dir then exclude favicon explicitly.
express.static('public', ['favicon.ico']);

express.middleware(favIcon({ iconPath: 'icons/favicon.ico', maxCacheDays: 30 }));
```
npm package: @itznotabug/appexpress-minifier
Description: A content minifier middleware for AppExpress.
Author: @itznotabug
Latest version: 0.0.5

# AppExpress Minifier Middleware

This module allows basic minification to your outgoing responses.\
Content with `content-type` that contains `text/`, `application/json` and `application/xml` are supported.

For detailed HTML minification options, refer to
the [html-minifier-terser documentation](https://github.com/terser/html-minifier-terser?tab=readme-ov-file#options-quick-reference).

## Installation

Add the middleware like this -

```shell
npm install @itznotabug/appexpress-minifier
```

## Usage

```javascript
// import
import AppExpress from '@itznotabug/appexpress';
import minifier from '@itznotabug/appexpress-minifier';

// setup
const express = new AppExpress();

express.middleware(minifier({
    excludes: [
        '/excludedPath', // direct path
        /\.txt$/, /\.css$/ // or better, use a regex
    ],
    htmlOptions: {
        removeComments: true,
        collapseWhitespace: true
    }
}));
```

Excluding a particular request -

```javascript
express.get('/dashboard', (_, res) => {
  res.setHeaders({ 'exclude-minify': true });
  res.render('dashboard.jsx', { props: buildProps() });
});
```

---

**Suggestion**: Middlewares in `AppExpress` are executed in the order they are added, if you use multiple middlewares,
make sure to add this one at the end so that any content processing (if done by a middleware) is preformed on the full
content.
npm package: @itznotabug/appexpress-nocookies
Description: A cookie remover middleware for AppExpress.
Author: @itznotabug
Latest version: 0.0.4

# AppExpress No-Cookies Middleware

This module allows you to serve resources without any cookies.\
Any `key` in the headers containing the word `cookie` will be stripped from both incoming requests and outgoing
responses.

## Installation

Add the middleware like this -

```shell
npm install @itznotabug/appexpress-nocookies
```

## Usage

```javascript
// import
import AppExpress from '@itznotabug/appexpress';
import noCookies from '@itznotabug/appexpress-nocookies';

// setup
const express = new AppExpress();

express.middleware(noCookies({ excludes: ['/cookie-allowed'] }));
```
npm package: @itznotabug/appexpress-zstd
Description: A zstd web compression module for AppExpress.
Author: @itznotabug
Latest version: 0.0.2

# AppExpress ZSTD Compression

This module allows you to perform `zstd` web compression for compressible resources.

## Installation

Add the middleware like this -

```shell
npm install @itznotabug/appexpress-zstd
```

## Usage

```javascript
// import
import zstd from '@itznotabug/appexpress-zstd';
import AppExpress from '@itznotabug/appexpress';

// setup
const express = new AppExpress();

// set an optional compression level.
express.compression(zstd({ level: 12 }));
```

**Note**: If there was an error while compressing the content, the uncompressed content is returned as is.