senecajs / seneca-web

Http route mapping for Seneca microservices.
MIT License
76 stars 44 forks source link

Quick example does not work #107

Closed djensen47 closed 8 years ago

djensen47 commented 8 years ago

I cloned the repository. Did an npm install. Went into the examples directory. Ran node using-hapi.js and received the following error:

Seneca Fatal Error
==================

Message: seneca: Action init:web failed: Provide a function as adapter.

Code: act_execute

Details: { message: 'Provide a function as adapter',
  pattern: 'init:web',
  fn: [Function: init],
  cb: [Function],
  instance: 'Seneca/dqyso9fl8492/1477530181592/8864/3.2.1/-',
  'orig$':
   Error: Provide a function as adapter
       at Seneca.setServer (C:\Users\david\src\open-source\seneca-web\web.js:81:17)
       at Seneca.init (C:\Users\david\src\open-source\seneca-web\web.js:117:13)
       at execute_action (C:\Users\david\src\open-source\seneca-web\node_modules\seneca\seneca.js:1015:20)
       at Object.act_fn [as fn] (C:\Users\david\src\open-source\seneca-web\node_modules\seneca\seneca.js:911:11)
       at processor (C:\Users\david\src\open-source\seneca-web\node_modules\gate-executor\gate-executor.js:131:14)
       at Immediate._onImmediate (C:\Users\david\src\open-source\seneca-web\node_modules\gate-executor\gate-executor.js:240:7)
       at tryOnImmediate (timers.js:543:15)
       at processImmediate [as _immediateCallback] (timers.js:523:5),
  'message$': 'Provide a function as adapter',
  plugin: {} }

Stack:
    at Seneca.setServer (C:\Users\david\src\open-source\seneca-web\web.js:81:17)
    at Seneca.init (C:\Users\david\src\open-source\seneca-web\web.js:117:13)
    at execute_action (C:\Users\david\src\open-source\seneca-web\node_modules\seneca\seneca.js:1015:20)
    at Object.act_fn [as fn] (C:\Users\david\src\open-source\seneca-web\node_modules\seneca\seneca.js:911:11)
    at processor (C:\Users\david\src\open-source\seneca-web\node_modules\gate-executor\gate-executor.js:131:14)
    at Immediate._onImmediate (C:\Users\david\src\open-source\seneca-web\node_modules\gate-executor\gate-executor.js:240:7)
    at tryOnImmediate (timers.js:543:15)
    at processImmediate [as _immediateCallback] (timers.js:523:5)

Instance: Seneca/dqyso9fl8492/1477530181592/8864/3.2.1/-
  ALL ERRORS FATAL: action called with argument fatal$:true (probably a plugin init error, or using a plugin seneca instance, see senecajs.org/fatal.html)
    at Seneca.act_done (C:\Users\david\src\open-source\seneca-web\node_modules\seneca\seneca.js:1054:29)

When: 2016-10-27T01:03:02.004Z

Log: {kind:null,plugin:seneca,tag:3.2.1,id:dqyso9fl8492/1477530181592/8864/3.2.1/-,code:act_execute,notice:seneca: A

Node:
  { http_parser: '2.7.0', node: '6.2.1', v8: '5.0.71.52', uv: '1.9.1', zlib: '1.2.8', ares: '1.10.1-DEV', icu: '57.1', modules: '48', openssl: '1.0.2h' },
  { debug: false, uv: true, ipv6: true, tls_npn: true, tls_alpn: true, tls_sni: true, tls_ocsp: true, tls: true },
  [ 'Binding contextify', 'Binding natives', 'NativeModule events', 'NativeModule util', 'Binding uv', 'NativeModule buffer', 'Binding buffer', 'NativeModule internal/util', 'Binding util', 'NativeModule timers', 'Binding timer_wrap', 'NativeModule internal/linkedlist', 'NativeModule assert', 'NativeModule internal/process', 'Binding config', 'NativeModule internal/process/warning', 'NativeModule internal/process/next_tick', 'NativeModule internal/process/promises', 'NativeModule internal/process/stdio', 'NativeModule path', 'NativeModule module', 'NativeModule internal/module', 'NativeModule vm', 'NativeModule fs', 'Binding fs', 'NativeModule constants', 'Binding constants', 'NativeModule stream', 'NativeModule _stream_readable', 'NativeModule _stream_writable', 'NativeModule _stream_duplex', 'NativeModule _stream_transform', 'NativeModule _stream_passthrough', 'Binding fs_event_wrap', 'NativeModule crypto', 'Binding crypto', 'NativeModule internal/streams/lazy_transform', 'NativeModule string_decoder', 'NativeModule net', 'NativeModule internal/net', 'Binding cares_wrap', 'Binding tty_wrap', 'Binding tcp_wrap', 'Binding pipe_wrap', 'Binding stream_wrap', 'NativeModule dns', 'NativeModule http', 'NativeModule _http_incoming', 'NativeModule _http_common', 'Binding http_parser', 'NativeModule internal/freelist', 'NativeModule _http_outgoing', 'NativeModule _http_server', 'NativeModule _http_agent', 'NativeModule _http_client', 'NativeModule url', 'NativeModule punycode', 'NativeModule querystring', 'NativeModule https', 'NativeModule tls', 'NativeModule _tls_common', 'NativeModule _tls_wrap', 'NativeModule _stream_wrap', 'Binding js_stream', 'Binding tls_wrap', 'NativeModule _tls_legacy', 'NativeModule os', 'Binding os', 'NativeModule zlib', 'Binding zlib', 'NativeModule console', 'NativeModule tty', 'Binding signal_wrap' ]
djensen47 commented 8 years ago

It looks like the examples in the docs directory were not updated to use a require statement instead of a string. I can submit a pull request to fix this tomorrow-ish.

dgonzalez commented 8 years ago

That would be awesome. If you need any help, please ping me. I might be able to assist you.

djensen47 commented 8 years ago

Also, the getting started guide for Seneca is maybe using an old example of how to integrate seneca with a web server: http://senecajs.org/getting-started/#web-server-integration

There is no reference to seneca-web in this section and I think the example only works on Express? Maybe that's an issue for the seneca repo but I thought I might mention it here too.

imatmati commented 8 years ago

Hi djensen47 ,

Yes, the example is no longer synchronized with current state of plugins. I ran into the same problem with the express example. The issue is that the adapter can no longer be called as stated in the code. You must require a special plugin for Express located here : https://github.com/senecajs/seneca-web-adapter-express

Now after moving some files for my personal arrangement, I was able to make it run :

'use strict'
var Seneca = require('seneca')
var Express = require('express')
var Web = require('seneca-web')
var Routes = require('./routes')
var Plugin = require('./plugin')

var config = {
    routes: Routes,
   adapter: require('seneca-web-adapter-express'),
   context: Express()
 }

var seneca = Seneca() .use(Plugin) .use(Web, config)
 .ready(() => {
    var server = seneca.export('web/context')()

  server.listen('4000', () => {
  console.log('server started on: 4000')
})

})

The point is to require 'seneca-web-adapter-express' and pass it as the adapter. The same seems to go for hapi, have a look at https://github.com/senecajs/seneca-web-adapter-hapi

Hope this can help.

djensen47 commented 8 years ago

Yup, thanks, helpful. I discovered this the other day too.

imatmati commented 8 years ago

Hi Dave,

What do you get exactly and how do you send your request ?

Ivan Matmati

----- Mail original -----

De: "Dave Jensen" notifications@github.com À: "senecajs/seneca-web" seneca-web@noreply.github.com Cc: "ivan matmati" ivan.matmati@laposte.net, "Comment" comment@noreply.github.com Envoyé: Mercredi 2 Novembre 2016 01:16:05 Objet: Re: [senecajs/seneca-web] Quick example does not work (#107)

Also, it appears that the Express example doesn't work at all even when using require for the adapter.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub , or mute the thread .

djensen47 commented 8 years ago

I didn't understand the question but I went ahead and fixed the examples with #112.

imatmati commented 8 years ago

Good, I was thinking about those changes, but you did it. Now, all examples will be ... working examples.