0

我按照教程创建 Gun 服务器。但我需要用Hapi来做。

现在,我收到以下错误:

> node server.js

Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!
0.8 WARNING! Breaking changes, test that your app works before upgrading! The adapter interface has been upgraded (non-default storage and transport layers probably won't work). Also, `.path()` and `.not()` are outside core and now in 'lib/'.
WARNING! This `file.js` module for gun is intended for local development testing only!
/home/trex/dev/learn/gun/server/server.js:17
gun.wsp(server);
    ^

TypeError: gun.wsp is not a function
    at Object.<anonymous> (/home/trex/dev/learn/gun/server/server.js:17:5)

服务器源代码:

const Hapi = require('hapi');
const Gun = require('gun');

const gun = new Gun();
const server = new Hapi.Server();

server.connection({ port: 3000, host: 'localhost' });

server.ext('onRequest', () => gun.wsp.server);

gun.wsp(server);

server.start((err) => {

    if (err) {
        throw err;
    }
    console.log(`Server running at: ${server.info.uri}`);
});

这里有什么问题?

4

1 回答 1

0

该错误已在gun 0.8.8 https://github.com/amark/gun/pull/423中解决

const Hapi  = require('hapi');
const Inert = require('inert');
const Gun   = require('../gun/');

const server = new Hapi.Server;
server.connection({ port: 8080 });
server.connections.forEach(c => Gun({ web: c.listener, file: 'data.json' }));

server.register(Inert, () => {});

server.route({
  method: 'GET',
  path: '/{param*}',
  handler: {
    directory: {
      path: __dirname,
      redirectToSlash: true,
      index: true
    }
  }
});

server.start();
于 2017-09-19T15:22:25.163 回答