forked from hoodiehq/ember-hoodie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
85 lines (68 loc) · 2.12 KB
/
index.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
/* jshint node:true */
'use strict';
var url = require('url');
var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
function hoodieMiddleware(config) {
/* jshint -W040 */
var appConfig = this.project.config(config.options.environment);
/* jshint +W040 */
if (!appConfig.hoodie) {
return;
}
var Hapi = require('hapi');
var hoodie = require('hoodie').register;
var proxy = require('http-proxy-middleware');
var PouchDB = require('pouchdb');
config.app.use('/hoodie', proxy({target: 'http://localhost:' + appConfig.hoodie.server.port}));
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: appConfig.hoodie.server.port
});
server.register({
register: hoodie,
options: appConfig.hoodie.server
}, function (error) {
if (error) {
throw error;
}
console.log('app', 'Starting');
server.start(function (error) {
if (error) {
throw error;
}
console.log('Your Hoodie server has started on ' + url.format(server.info.uri));
});
});
}
module.exports = {
name: 'ember-hoodie',
// ember-browserify has the drawback that apps using ember-hoodie would be
// required to install ember-browserify as well.
// https://github.com/ef4/ember-browserify#using-ember-browserify-in-addons
treeForVendor(tree) {
var hoodiePackage = path.dirname(require.resolve('@hoodie/client'));
var hoodieTree = new Funnel(this.treeGenerator(hoodiePackage), {
srcDir: 'dist',
destDir: '/'
});
var pouchdbPackage = path.join(path.dirname(require.resolve('pouchdb')), '..', 'dist');
var pouchdbTree = new Funnel(pouchdbPackage, {
files: ['pouchdb.js'],
destDir: 'pouchdb'
});
if (tree) {
return mergeTrees([tree, hoodieTree, pouchdbTree], {overwrite: true});
} else {
return mergeTrees([hoodieTree, pouchdbTree], {overwrite: true});
}
},
included(app) {
this._super.apply(this, arguments);
app.import('vendor/hoodie.js');
app.import('vendor/pouchdb/pouchdb.js');
},
serverMiddleware: hoodieMiddleware
};