# prisma-proxy-express-server

> Creates an api for your prisma client

Latest version **0.0.9** (published 2022-05-04) · 0 weekly downloads

## Install

```sh
npm install prisma-proxy-express-server
pnpm add prisma-proxy-express-server
yarn add prisma-proxy-express-server
bun add prisma-proxy-express-server
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2022-05-04 |
| First published | 2021-12-19 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jacksloan |

## Links

- npm: https://www.npmjs.com/package/prisma-proxy-express-server
- npm.io page: https://npm.io/package/prisma-proxy-express-server

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) 2.3.1

## Recent versions

- 0.0.9 (latest) — 2022-05-04
- 0.0.8 — 2022-02-12
- 0.0.7 — 2022-02-12
- 0.0.5 — 2021-12-19
- 0.0.4 — 2021-12-19
- 0.0.2 — 2021-12-19
- 0.0.1 — 2021-12-19

## README

# prisma-proxy-express-server

Creates an api for your prisma client

# getting started

TODO

# basic usage

For a complete example see [express.js example app](/apps/api/src/main.ts)

```
// prisma.schema
model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
}
```

```typescript
import { createPrismaExpressProxy } from '@prisma-proxy/prisma-proxy-express-server';
import { PrismaClient } from '@prisma/client';
import * as express from 'express';

const app = express();
const prisma = new PrismaClient();

createPrismaExpressProxy({
  app,
  prisma,
  // default middleware is applied if middleware is not explicitly set for a route
  defaultMiddleware: (_res, _req, next) =>
    next(new Error('internal server error')),

  // typed middleware can be used to allow/restrict access to certain prisma actions
  middleware: {
    post: {
      // un-authenticated routes
      findMany: (req, res, next) => next(),

      // restricted route
      create: (req, res, next) => {
        // typeof req.body is PostCreateArgs
        // typeof req.params is {post: string, create: string}
        const token = req.headers.authorization;
        if (isUserAdmin(token)) {
          next();
        } else {
          const error = new Error('You do not have the required permissions');
          error.status = 403;
          next(error);
        }
      },
    },
  },
});

const server = app.listen(3333);
```

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