1.0.0 • Published 7 years ago

magnet-algolia v1.0.0

Weekly downloads
11
License
MIT
Repository
github
Last release
7 years ago

Usage

All Algolia api should refer algoliasearch

Basic

import magnet from 'magnet-core';
import Config from 'magnet-config';
import Logger from 'magnet-bunyan';
import Server from 'magnet-spdy';
import Session from 'magnet-session';
import Router from 'magnet-router';
import Algolia from 'magnet-algolia';

let app = await magnet([Config, Logger, Server, Session, Router, algolia]);

server/controllers/user.js

export default function user({ router, algolia }) {
  router

  .get('/users', async function (ctx) {
    var index = algolia.initIndex('users');

    index.search('Atlenta', function(err, results) {
      if (err) {
        throw err;
      }

      console.log('We got `' + results.nbHits + '` results');
      console.log('Here is the first one: ', results.hits[0]);

      // call client.destroy() this when you need to stop the node.js client
      // it will release any keepalived connection
      algolia.destroy();
    });
    ctx.body = [];
  })

  .post('/user', async function (ctx) {
    ctx.body = ctx.request.body;
  })

  .put('/user/:userId', async function (ctx) {
    ctx.body = ctx.params;
  })

  .get('/user/:userId', async function (ctx) {
    ctx.body = ctx.query;
  });
}
1.0.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago