# nestjs-inertia

> Unofficial NestJS (express platform) adapter for InertiaJS.

Latest version **1.0.1** (published 2022-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-inertia
pnpm add nestjs-inertia
yarn add nestjs-inertia
bun add nestjs-inertia
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-08-06 |
| First published | 2022-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 120.7 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 31 |
| Author | harisfi |
| Maintainers | harisfi |
| Keywords | nestjs, nest, inertiajs, inertia, expressjs, express, server-adapter |

## Links

- npm: https://www.npmjs.com/package/nestjs-inertia
- Repository: https://github.com/harisfi/nestjs-inertia
- Homepage: https://github.com/harisfi/nestjs-inertia#readme
- Issues: https://github.com/harisfi/nestjs-inertia/issues
- npm.io page: https://npm.io/package/nestjs-inertia

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ^7.5.6
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^9.0.8
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^9.0.8
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^9.0.8

## Recent versions

- 1.0.1 (latest) — 2022-08-06
- 1.0.0 — 2022-08-06

## README

# nestjs-inertia
`nestjs-inertia` is a simple [NestJS](https://nestjs.com) adapter/middleware with `express-platform` for [Inertia.js](https://inertiajs.com) to create server-driven single page applications.

## Installation
You can run command below to install `nestjs-inertia` to your NestJS project.

```
npm i nestjs-inertia
```

## Applying adapter
Based on official NestJS documentation of their middleware, you can apply `nestjs-inertia` middleware to global or module level like below:

1. Global Level
    ```ts
    import { NestFactory } from '@nestjs/core';
    import { AppModule } from './app.module';
    import { inertiaMiddleware } from 'nestjs-inertia'

    const app = await NestFactory.create(AppModule);
    app.use(inertiaMiddleware);
    await app.listen(3000);
    ```
2. Module Level
    ```ts
    import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
    import { AppController } from './app.controller';
    import { AppService } from './app.service';
    import { InertiaMiddleware } from 'nestjs-inertia'

    @Module({
      imports: [],
      controllers: [AppController],
      providers: [AppService],
    })
    export class AppModule implements NestModule {
      configure(consumer: MiddlewareConsumer) {
        consumer
          .apply(InertiaMiddleware)
          .forRoutes('*');
      }
    }
    ```

## Usage
You can use this adapter from express' `Response` api.

### Basic Usage

- Rendering a component
  ```ts
  res.inertia.render('Users/AllUser', {
    users: [
      {
        id: 1,
        name: 'John Doe'
      }
    ]
  });
  ```
- Share data
  ```ts
  res.inertia.share({
    isLoggedIn: true
  });
  ```
- Redirection
  ```ts
  res.inertia.redirect('/user');
  ```

### Example usage at controller
```ts
import { Controller, Get, Res } from '@nestjs/common';
import { Response } from 'express';

@Controller('users')
export class UserController {
  @Get()
  findAll(@Res() res: Response): Promise<void> {
    return res.inertia.render('Users/AllUser', {
      users: [
        {
          id: 1,
          name: 'John Doe'
        }
      ]
    });
  }
}
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License
[MIT](https://choosealicense.com/licenses/mit/)

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