How to use the awilix-koa.createController function in awilix-koa

To help you get started, we’ve selected a few awilix-koa 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 inkubux / MediaSpeed / src / routes / library-api.js View on Github external
try {
            const query = ctx.params.id ? { uid: ctx.params.id } : {};

            const libraries = await this.service.find(query);
            Promise.all(libraries.map(async lib => this.libraryScanner.scan(lib)));
        } catch (err) {
            console.log('Error occurred while scanning', err);
        }
    }
}

// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(LibraryRestApi)
    .prefix('/api/libraries')
    .get('', 'find')
    .get('/:id', 'get')
    .post('', 'create')
    .patch('/:id', 'update')
    .delete('/:id', 'remove')
    .post('/:id/scan', 'scan')
    .post('/scan', 'scan');
github inkubux / MediaSpeed / src / routes / transcode-api.js View on Github external
/* eslint-disable no-useless-constructor */
import { createController } from 'awilix-koa';
import StreamApi from './base-stream-api';

class TranscodeApi extends StreamApi {
    constructor(movieService, episodeService, ffmpegStreamer) {
        super(movieService, episodeService, ffmpegStreamer);
    }

    getRange(ctx) {
        return false;
    }
}

export default createController(TranscodeApi)
    .prefix('/transcode')
    .get('/:type/:id', 'stream');
github inkubux / MediaSpeed / src / routes / season-api.js View on Github external
/* eslint-disable no-useless-constructor */
import { createController } from 'awilix-koa';
import BaseRestApi from './base-api';

class SeasonsRestApi extends BaseRestApi {
    constructor(seasonService) {
        super(seasonService);
    }
}

// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(SeasonsRestApi)
    .prefix('/api/seasons')
    .get('', 'find')
    .get('/:id', 'get')
    .post('', 'create')
    .patch('/:id', 'update')
    .delete('/:id', 'remove');
github inkubux / MediaSpeed / src / routes / episode-api.js View on Github external
/* eslint-disable no-useless-constructor */
import { createController } from 'awilix-koa';
import BaseRestApi from './base-api';

class EpisodeRestApi extends BaseRestApi {
    constructor(episodeService) {
        super(episodeService);
    }
}

// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(EpisodeRestApi)
    .prefix('/api/episodes')
    .get('', 'find')
    .get('/:id', 'get')
    .post('', 'create')
    .patch('/:id', 'update')
    .delete('/:id', 'remove');
github jeffijoe / koa-es7-boilerplate / src / routes / todos-api.js View on Github external
// just over HTTP.
const api = todoService => ({
  findTodos: async ctx => ctx.ok(await todoService.find(ctx.query)),
  getTodo: async ctx => ctx.ok(await todoService.get(ctx.params.id)),
  createTodo: async ctx =>
    ctx.created(await todoService.create(ctx.request.body)),
  updateTodo: async ctx =>
    ctx.ok(await todoService.update(ctx.params.id, ctx.request.body)),
  removeTodo: async ctx =>
    ctx.noContent(await todoService.remove(ctx.params.id))
})

// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
export default createController(api)
  .prefix('/todos')
  .get('', 'findTodos')
  .get('/:id', 'getTodo')
  .post('', 'createTodo')
  .patch('/:id', 'updateTodo')
  .delete('/:id', 'removeTodo')
github inkubux / MediaSpeed / src / routes / show-api.js View on Github external
return ctx.ok(await this.seasonService.find(query));
    }

    async getEpisodes(ctx) {
        let query = { ...{ show_uid: ctx.params.id }, ...ctx.query };

        if (ctx.params.sid) {
            const seasonIdkey = isNaN(ctx.params.sid) ? 'season_uid' : 'season_number';
            query[seasonIdkey] = ctx.params.sid;
        }

        return ctx.ok(await this.episodeService.find(query));
    }
}

export default createController(ShowRestApi)
    .prefix('/api/shows')
    .get('', 'find')
    .get('/:id', 'get')
    .get('/:id/seasons', 'getSeasons')
    .get('/:id/episodes', 'getEpisodes')
    .get('/:id/seasons/:sid', 'getSeasons')
    .get('/:id/seasons/:sid/episodes', 'getEpisodes')
    .post('', 'create')
    .patch('/:id', 'update')
    .delete('/:id', 'remove');
// Maps routes to method calls on the `api` controller.
// See the `awilix-router-core` docs for info:
// https://github.com/jeffijoe/awilix-router-core
github inkubux / MediaSpeed / src / routes / hls-api.js View on Github external
async stream(ctx, res) {
        const session = ctx.query.session;
        const segment = ctx.params.segment;
        ctx.body = await this.streamer.getStream(segment, session);
    }

    async stop(ctx, res) {
        const session = ctx.query.session;
        this.streamer.stopStream(session);

        ctx.body = { message: 'ok' };
    }
}

export default createController(HlsApi)
    .prefix('/hls')
    .get('/:type/:id/index.m3u8', 'masterPlaylist')
    .get('/:type/:id/video.m3u8', 'playlist')
    .get('/:type/:id/index:segment.ts', 'stream')
    .post('/:type/:id/stop', 'stop');
github mollyywang / koa2-mongodb-jwt-server / src / routes / products-api.js View on Github external
* exports a "controller" that `awilix-koa` use for routing. 
 * 返回路由控制器供`awilix-koa` 使用路由
 */

const api = productService => ({
  getProduct: async ctx => ctx.ok(await productService.get(ctx.params.id)),
  getList: async ctx => {
    ctx.ok(await productService.getList(ctx.request.body))
  },
  createProduct: async ctx =>
    ctx.ok(await productService.create(ctx.request.body)),

})


export default createController(api)
  .prefix('/public/products')
  .get('/get/:id', 'getProduct')
  .post('/create', 'createProduct')
  .post('/getlist', 'getList')
github mollyywang / koa2-mongodb-jwt-server / src / routes / users-api.js View on Github external
import { createController } from 'awilix-koa'

/**
 * more info about [`awilix-koa`] (https://github.com/jeffijoe/awilix-koa#awesome-usage) 
 * more info about [`awilix-router`] (https://github.com/jeffijoe/awilix-router-core)
 * exports a "controller" that `awilix-koa` use for routing. 
 * 返回路由控制器供`awilix-koa` 使用路由
 */

const api = userService => ({
  login: async ctx => ctx.ok(await userService.login(ctx.request.body)),
  register: async ctx =>
    ctx.ok(await userService.register(ctx.request.body)),
})

export default createController(api)
  .prefix('/public/user')
  .post('/login', 'login')
  .post('/logout', 'logout')
  .post('/register', 'register')
github mollyywang / koa2-mongodb-jwt-server / src / routes / stars-api.js View on Github external
const api = starService => ({
  findStars: async ctx => {
    const userId = ctx.state.user.data._id
    ctx.ok(await starService.findStars(userId))
  },
  addStar: async ctx => {
    const userId = ctx.state.user.data._id
    ctx.ok(await starService.addStar(userId, ctx.request.body))
  },
  removeStar: async ctx => {
    const userId = ctx.state.user.data._id
    ctx.ok(await starService.removeStar(userId, ctx.params.id))
  }
})

export default createController(api)
  .prefix('/star')
  .get('/starlist', 'findStars')
  .post('/add', 'addStar')
  .get('/remove/:id', 'removeStar')

awilix-koa

Awilix helpers for Koa

MIT
Latest version published 2 months ago

Package Health Score

64 / 100
Full package analysis

Similar packages