How to use daruk - 10 common examples

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 / 04-timers / index.ts View on Github external
import { Daruk } from 'daruk';

const myApp = new Daruk('myapp', { rootPath: __dirname, debug: process.env.NODE_ENV === 'dev' });
const port = 1318;

myApp.run(port);
github darukjs / daruk / example / 01-helloWorld / index.ts View on Github external
import { Daruk } from 'daruk';

const myApp = new Daruk('myapp', { rootPath: __dirname, debug: process.env.NODE_ENV === 'dev' });
const port = 3000;

myApp.run(port);
github darukjs / daruk / example / 02-comments / index.ts View on Github external
import { Daruk } from 'daruk';

const port = 3000;
const myApp = new Daruk('my-comments-app', {
  rootPath: __dirname,
  debug: process.env.NODE_ENV === 'dev'
});

myApp.run(port);
github darukjs / daruk / example / 03-weather / index.ts View on Github external
import { Daruk } from 'daruk';

const myApp = new Daruk('myapp', { rootPath: __dirname, debug: process.env.NODE_ENV === 'dev' });

myApp.run(myApp.config.port);
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 / 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 / 01-helloWorld / controllers / index.ts View on Github external
import { BaseController, Context, get, post } from 'daruk';

export default class Index extends BaseController {
  @get('/')
  @post('/')
  public index(ctx: Context, next: Function) {
    ctx.body = 'hello world';
  }
}
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 / 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 12 months ago

Package Health Score

62 / 100
Full package analysis