Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Daruk } from 'daruk';
const myApp = new Daruk('myapp', { rootPath: __dirname, debug: process.env.NODE_ENV === 'dev' });
const port = 1318;
myApp.run(port);
import { Daruk } from 'daruk';
const myApp = new Daruk('myapp', { rootPath: __dirname, debug: process.env.NODE_ENV === 'dev' });
const port = 3000;
myApp.run(port);
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);
import { Daruk } from 'daruk';
const myApp = new Daruk('myapp', { rootPath: __dirname, debug: process.env.NODE_ENV === 'dev' });
myApp.run(myApp.config.port);
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}`;
});
}
}
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}`;
});
}
}
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';
}
}
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}`;
});
}
}
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}`;
});
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, '');