How to use the daruk.middleware function in daruk

To help you get started, we’ve selected a few daruk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darukjs / daruk / example / 03-weather / controllers / index.ts View on Github external
import { BaseController, config, Context, Daruk, get, middleware, util } from 'daruk';

export default class Index extends BaseController {
  @util('getToday')
  public getToday: Daruk['util']['getToday'];
  @config('author')
  public author: Daruk['config']['author'];
  @config('version')
  public version: Daruk['config']['version'];
  @middleware('cors')
  @get('/')
  public async index(ctx: Context, next: Function) {
    await ctx.service.weather.getWeather()
      .then((weather: string) => {
        ctx.body = `Hi, ${this.author}, project version is ${this.version},
                Today is ${this.getToday()}, weather is ${weather}`;
      })
      .catch((err: string) => {
        ctx.body = `Get weather information error, message: ${err}`;
      });
  }
}

daruk

a node.js web framework

MIT
Latest version published 11 months ago

Package Health Score

62 / 100
Full package analysis