How to use the daruk.util 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}`;
      });
github darukjs / daruk / example / 03-weather / services / weather.ts View on Github external
import { BaseService, Context, Daruk, util } from 'daruk';
import request = require('request-promise');

export default class Weather extends BaseService {
  @util('fixIP')
  public fixIP: Daruk['util']['fixIP'];
  public constructor(ctx: Context) {
    super(ctx);
  }
  public async getLatLong(ip: string) {
    return await request(`https://ipapi.co/${ip}/latlong/`);
  }
  public async getIP() {
    let json = await request('http://pv.sohu.com/cityjson', { encoding: null });
    return this.fixIP(json);
  }
  public async getWeather() {
    const API_KEY = 'f4019f67f66c97d24751ac71c72f936f';
    const ip = await this.getIP();
    let latlong = await this.getLatLong(ip);
    latlong = latlong.replace(/"/g, '');

daruk

a node.js web framework

MIT
Latest version published 3 months ago

Package Health Score

70 / 100
Full package analysis