-
Notifications
You must be signed in to change notification settings - Fork 61
/
web.js
104 lines (84 loc) · 2.03 KB
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
var hapi = require('hapi')
var vision = require('vision')
var inert = require('inert')
var handlebars = require('handlebars')
module.exports = function(options) {
var folder = options.folder || __dirname
var server = new hapi.Server()
server.connection({port: options.port || 8000})
server.register( vision )
server.register( inert )
var seneca = options.seneca
server.route({
method: 'GET',
path: '/{path*}',
handler: {
directory: {
path: folder + '/www',
}
}
})
server.views({
engines: { html: handlebars },
path: folder + '/www',
layout: true
})
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply.view('index', {title: 'nodezoo'})
}})
server.route({
method: 'GET', path: '/info/{mod}',
handler: function( request, reply )
{
//server.
seneca.act(
{
role: 'info',
cmd: 'get',
name: request.params.mod
},
function (err, mod) {
if( err ) {
mod = {}
}
mod.no_npm = !mod.npm
mod.no_github = !mod.github
reply.view('info',{
title: 'nodezoo - '+request.params.mod,
mod: mod
})
})
}})
server.route({
method: 'GET',
path: '/api/query',
handler: function (request, reply) {
seneca.act(
{
role: 'search',
cmd: 'search',
query: request.query.q
},
function (err, out) {
if (err) {
out = {items: []}
}
reply(out)
})
}})
server.route({
method: 'GET', path: '/api/suggest',
handler: function( request, reply ){
seneca.act(
'role:suggest,cmd:suggest',{query:request.query.q,default$:[]},
function(err,out){
reply(out||[])
})
}})
server.start()
return server
}