# set-status

> Set a custom HTTP status code for the client by utilizing proxy and a meta tag.

Latest version **0.0.1** (published 2023-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install set-status
pnpm add set-status
yarn add set-status
bun add set-status
```

Provides the command `proxy-status`.

## 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.1 |
| Published | 2023-12-31 |
| First published | 2023-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jiwon Choi |
| Maintainers | devjiwonchoi |
| Keywords | status, status code, browser, client, proxy, next, next.js |

## Links

- npm: https://www.npmjs.com/package/set-status
- Repository: https://github.com/devjiwonchoi/set-status
- Homepage: https://github.com/devjiwonchoi/set-status#readme
- Issues: https://github.com/devjiwonchoi/set-status/issues
- npm.io page: https://npm.io/package/set-status

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^16.3.1
- [express](https://npm.io/package/express.md) ^4.18.2
- [http-proxy-middleware](https://npm.io/package/http-proxy-middleware.md) ^2.0.6

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2023-12-31
- 0.0.0 — 2023-12-31

## README

# set-status

> Set a custom HTTP status code for the client by utilizing proxy and a meta tag.

**Note: Manipulating HTTP status code is not recommended for production. Use at your own risk.**

## Install

```sh
pnpm add set-status
```

## Configuration

You can configure all settings with the environment variables.

- Set the `TARGET_URL` as your target app URL, `http://localhost:3000` by default.
- Set the `PROXY_SERVER_PORT` for the proxy server port, `3001` by default.
- Set the `TARGET_META_NAME` for the target `meta` tag, `set-status` by default.
- Set the `IGNORE_PATH_REGEX` for the regex to ignore the target path set to Next.js by default.

> See [`.env.example`](./.env.example) for an example.

## Usage

### Basic

Run the proxy server with the following command:

```sh
pnpm proxy-status
```

The proxy server will look for the target meta tag and set the status code to the client.

```html
<meta name="set-status" content="401" />
```

The meta tag above will let the proxy server set the status code to `401`.

### Recommended

Install [`concurrently`](https://www.npmjs.com/package/concurrently) to run the proxy server and your production app concurrently.

```sh
pnpm add concurrently
```

Set your `start` script in `package.json` as follows:

```json
{
  "scripts": {
    "start": "concurrently \"pnpm proxy-status\" \"YOUR PRODUCTION COMMAND\""
  }
}
```

```sh
pnpm start
```

### Next.js

> See examples in [`examples/nextjs`](./examples/nextjs).

In Next.js, you can statically set a custom `meta` tag by using a `Metadata` API.

Through this, we can set the status code read from the target meta tag.

```tsx
// page.tsx

export default function Unauthorized() {
  return (
    <div>
      <h1>401</h1>
      <p>Unauthorized</p>
    </div>
  )
}

export const metadata = {
  other: {
    'set-status': 401,
  },
}
```

Also, you can dynamically set the target meta tag by using `generateMetadata` function.

```tsx
// page.tsx

export async function generateMetadata() {
  const res = await fetch('https://example.com/api')
  
  if (res.status !== 200) {
    return {
      other: {
        'set-status': res.status,
      },
    }
  }
}
```

For more information about the `Metadata` API, see the [Next.js documentation](https://nextjs.org/docs/app/building-your-application/optimizing/metadata).

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