1.0.4 • Published 4 months ago

nuxt-nust v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Nust Module for Nuxt

🚧 Development in progress, not ready for production

npm version npm downloads License Nuxt

A Nuxt module that allows NestJS like backend structure in nuxt, powering nuxt backend with features like:

  • 🎮  Controllers
  • 🖌️  Decorators
  • 🛎️  Injectable providers/services
  • 🪄️  Parameter extraction
  • ✅️  Body/DTO Validation (using class-validator)
  • 🔄️  Transformers (using class-transformer)
  • 🔒️  Guards

Usage

  1. Install the module to your Nuxt application:
npm i nuxt-nust
  1. Add nuxt-nust to list of modules in your nuxt.config.ts file, along with nust configuration:
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-nust'],
  nust: {
    controllersFile: 'server/nust/index.ts', // Path to controllers export file in your project relative to root folder
    debug: false, // Enable to show the routes added by your controllers in the logs
  }
})
  1. Create a file in your project to export all controllers that sits under the path specified in the previous step, for example: server/nust/index.ts
// server/nust/index.ts
import { type NustControllers } from 'nuxt-nust'

export default {
  // Here you'll be adding your controller classes
  // Example:
  // post: PostController
} satisfies NustControllers
  1. That's it! You can now use Nust Module in your Nuxt app ✨

Example of adding a controller, lets call this one CatController

1.Create a controller file under the nust directory, server/nust/cat/Cat.controller.ts

import { Controller, type H3Event } from 'nuxt-nust'

@Controller('cat')
export class CatController {

  @Get('')
  findAll(event: H3Event) {
    return `this action returns all cats`
  }
  
}
  1. Add controller to server/nust/index.ts file
// server/nust/index.ts
import {type NustControllers} from 'nuxt-nust'
import { CatController } from "./cat/Cat.controller";

export default {
  cat: CatController
} satisfies NustControllers
  1. Restart nuxt service
  2. Now the endpoint /api/cat is available

🚧 Further Documentation in progress

1.0.4

4 months ago

1.0.3

4 months ago