Request handler unable to render view with Vision pluginRender Partial View Using jQuery in ASP.NET MVCRender basic HTML view?Loading Youtube Iframe API with RequireJSUnable to access React instance (this) inside event handlerHow to avoid Hapi.js sending 400 error when Validating Request with JoiHapiJS assert request in handlerpage render dependent on async callAngular code on Hapijs by view engine Handlebar of nodejsWebpack3 import bootstrap and other librariesWebpack css issue, missing bundle.css

Is there a term for the belief that "if it's legal, it's moral"?

Why don't countries like Japan just print more money?

Is "Busen" just the area between the breasts?

Can humans ever directly see a few photons at a time? Can a human see a single photon?

Too early in the morning to have SODA?

Designing a magic-compatible polearm

What is "industrial ethernet"?

What's currently blocking the construction of the wall between Mexico and the US?

Encounter design and XP thresholds

How do I choose a villain in the Waterdeep: Dragon Heist adventure?

How can I bring back a dead main character without cliches?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

Primes and SemiPrimes in Binary

Creating a histogram using custom data

What is the origin of Scooby-Doo's name?

How to parse 「場合でも」

Should the party get XP for a monster they never attacked?

"Correct me if I'm wrong"

career in signal processing

How to maintain a closed environment for one person for a long period of time

How can lift be less than thrust that is less than weight?

Is there a difference between an NFC and RFID chip?

What is the highest voltage from the power supply a Raspberry Pi 3 B can handle without getting damaged?

Why does using different ArrayList constructors cause a different growth rate of the internal array?



Request handler unable to render view with Vision plugin


Render Partial View Using jQuery in ASP.NET MVCRender basic HTML view?Loading Youtube Iframe API with RequireJSUnable to access React instance (this) inside event handlerHow to avoid Hapi.js sending 400 error when Validating Request with JoiHapiJS assert request in handlerpage render dependent on async callAngular code on Hapijs by view engine Handlebar of nodejsWebpack3 import bootstrap and other librariesWebpack css issue, missing bundle.css






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm working on a HapiJS api and I've defined a plugin that registers the Vision plugin and configures a rendering engine (ejs). But when I try and respond to the request by rendering a view I get the error




AssertionError [ERR_ASSERTION]: Missing views manager




If I register the Vision plugin and its config somewhere outside the plugin the tests pass but my expectation is that I should be able to encapsulate this logic in a plugin.



// plugin
const ejs = require('ejs');
const Vision = require('vision');

module.exports =
name: 'views',
version: '0.0.1',
register: async (server, path ) =>
await server.register(Vision);
server.views(
engines: ejs ,
path,
);
,
;


The handler code is



// api
server.route(
path: '/korin/songs',
method: 'GET',
handler: async (request, h) =>
try
const acceptType = getMediaType(request.headers.accept);
const data = await server.methods.getTopTracks(
getTopTracks,
lastfmApi,
);
if (acceptType === 'text/html')
return h.view('index'); // <-- this errors

return data;
catch (error)
console.warn(error);

,
);



The error is generated by a failing test which is



suite('render content', () => 
test.only(`given text/html page should respond with header and footer`, async () =>
const server = await setup();
const payload = await server.inject(
method: 'GET',
url: '/korin/songs',
headers:
accept: 'text/html',
,
);

expect(payload).to.contain(`<header>`);
expect(payload).to.contain(`<footer>`);
);
);


// test setup
const setup = async options =>
const server = new Hapi.Server();

// truncated for brevity
await server.register(
plugin: require('../../server/api'),
options:
...defaults,
...options,
,
);

await server.register(
plugin: require('../../server/views'),
options: path: path.join(__dirname, '../views/templates') ,
);

return
server
;
;



Is there something I'm missing? I've tried running a console.log and the code seems to be running in the right order but failing anyway.










share|improve this question




























    0















    I'm working on a HapiJS api and I've defined a plugin that registers the Vision plugin and configures a rendering engine (ejs). But when I try and respond to the request by rendering a view I get the error




    AssertionError [ERR_ASSERTION]: Missing views manager




    If I register the Vision plugin and its config somewhere outside the plugin the tests pass but my expectation is that I should be able to encapsulate this logic in a plugin.



    // plugin
    const ejs = require('ejs');
    const Vision = require('vision');

    module.exports =
    name: 'views',
    version: '0.0.1',
    register: async (server, path ) =>
    await server.register(Vision);
    server.views(
    engines: ejs ,
    path,
    );
    ,
    ;


    The handler code is



    // api
    server.route(
    path: '/korin/songs',
    method: 'GET',
    handler: async (request, h) =>
    try
    const acceptType = getMediaType(request.headers.accept);
    const data = await server.methods.getTopTracks(
    getTopTracks,
    lastfmApi,
    );
    if (acceptType === 'text/html')
    return h.view('index'); // <-- this errors

    return data;
    catch (error)
    console.warn(error);

    ,
    );



    The error is generated by a failing test which is



    suite('render content', () => 
    test.only(`given text/html page should respond with header and footer`, async () =>
    const server = await setup();
    const payload = await server.inject(
    method: 'GET',
    url: '/korin/songs',
    headers:
    accept: 'text/html',
    ,
    );

    expect(payload).to.contain(`<header>`);
    expect(payload).to.contain(`<footer>`);
    );
    );


    // test setup
    const setup = async options =>
    const server = new Hapi.Server();

    // truncated for brevity
    await server.register(
    plugin: require('../../server/api'),
    options:
    ...defaults,
    ...options,
    ,
    );

    await server.register(
    plugin: require('../../server/views'),
    options: path: path.join(__dirname, '../views/templates') ,
    );

    return
    server
    ;
    ;



    Is there something I'm missing? I've tried running a console.log and the code seems to be running in the right order but failing anyway.










    share|improve this question
























      0












      0








      0








      I'm working on a HapiJS api and I've defined a plugin that registers the Vision plugin and configures a rendering engine (ejs). But when I try and respond to the request by rendering a view I get the error




      AssertionError [ERR_ASSERTION]: Missing views manager




      If I register the Vision plugin and its config somewhere outside the plugin the tests pass but my expectation is that I should be able to encapsulate this logic in a plugin.



      // plugin
      const ejs = require('ejs');
      const Vision = require('vision');

      module.exports =
      name: 'views',
      version: '0.0.1',
      register: async (server, path ) =>
      await server.register(Vision);
      server.views(
      engines: ejs ,
      path,
      );
      ,
      ;


      The handler code is



      // api
      server.route(
      path: '/korin/songs',
      method: 'GET',
      handler: async (request, h) =>
      try
      const acceptType = getMediaType(request.headers.accept);
      const data = await server.methods.getTopTracks(
      getTopTracks,
      lastfmApi,
      );
      if (acceptType === 'text/html')
      return h.view('index'); // <-- this errors

      return data;
      catch (error)
      console.warn(error);

      ,
      );



      The error is generated by a failing test which is



      suite('render content', () => 
      test.only(`given text/html page should respond with header and footer`, async () =>
      const server = await setup();
      const payload = await server.inject(
      method: 'GET',
      url: '/korin/songs',
      headers:
      accept: 'text/html',
      ,
      );

      expect(payload).to.contain(`<header>`);
      expect(payload).to.contain(`<footer>`);
      );
      );


      // test setup
      const setup = async options =>
      const server = new Hapi.Server();

      // truncated for brevity
      await server.register(
      plugin: require('../../server/api'),
      options:
      ...defaults,
      ...options,
      ,
      );

      await server.register(
      plugin: require('../../server/views'),
      options: path: path.join(__dirname, '../views/templates') ,
      );

      return
      server
      ;
      ;



      Is there something I'm missing? I've tried running a console.log and the code seems to be running in the right order but failing anyway.










      share|improve this question














      I'm working on a HapiJS api and I've defined a plugin that registers the Vision plugin and configures a rendering engine (ejs). But when I try and respond to the request by rendering a view I get the error




      AssertionError [ERR_ASSERTION]: Missing views manager




      If I register the Vision plugin and its config somewhere outside the plugin the tests pass but my expectation is that I should be able to encapsulate this logic in a plugin.



      // plugin
      const ejs = require('ejs');
      const Vision = require('vision');

      module.exports =
      name: 'views',
      version: '0.0.1',
      register: async (server, path ) =>
      await server.register(Vision);
      server.views(
      engines: ejs ,
      path,
      );
      ,
      ;


      The handler code is



      // api
      server.route(
      path: '/korin/songs',
      method: 'GET',
      handler: async (request, h) =>
      try
      const acceptType = getMediaType(request.headers.accept);
      const data = await server.methods.getTopTracks(
      getTopTracks,
      lastfmApi,
      );
      if (acceptType === 'text/html')
      return h.view('index'); // <-- this errors

      return data;
      catch (error)
      console.warn(error);

      ,
      );



      The error is generated by a failing test which is



      suite('render content', () => 
      test.only(`given text/html page should respond with header and footer`, async () =>
      const server = await setup();
      const payload = await server.inject(
      method: 'GET',
      url: '/korin/songs',
      headers:
      accept: 'text/html',
      ,
      );

      expect(payload).to.contain(`<header>`);
      expect(payload).to.contain(`<footer>`);
      );
      );


      // test setup
      const setup = async options =>
      const server = new Hapi.Server();

      // truncated for brevity
      await server.register(
      plugin: require('../../server/api'),
      options:
      ...defaults,
      ...options,
      ,
      );

      await server.register(
      plugin: require('../../server/views'),
      options: path: path.join(__dirname, '../views/templates') ,
      );

      return
      server
      ;
      ;



      Is there something I'm missing? I've tried running a console.log and the code seems to be running in the right order but failing anyway.







      javascript hapijs hapijs-vision






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 7:37









      PeterPeter

      2,26442950




      2,26442950






















          1 Answer
          1






          active

          oldest

          votes


















          1














          There is an old thread on GitHub about this. TL;DR: the reference to server passed to the plugin when registering is slightly not the same as the "root" server. Some difference about realms, apparently still an issue.



          Indeed: in the plugin, server.getViewsManager() (decorated by vision) after registration of vision and server.views will show something, whereas the same call in your route (so, after plugin registration) will show null. So much for "references".



          I just tried a similar structure to you, got the same error, and this thread pointed me to a workaround: when registering your views plugin, just pass along a reference to the "real" server in the options.



          // plugin
          const ejs = require('ejs');
          const Vision = require('vision');

          module.exports =
          name: 'views',
          version: '0.0.1',
          register: async (server, path, realServer ) => // <= added option
          await realServer.register(Vision); // <= replaced server w/ realServer
          realServer.views( // <= replaced server w/ realServer
          engines: ejs ,
          path,
          );
          ,
          ;


          // test setup
          // ...
          const server = new Hapi.Server();
          // ...
          await server.register(
          plugin: require('../../server/views'),
          options:
          path: path.join(__dirname, '../views/templates'),
          realServer: server // <= added option

          );


          And, obviously, have the same options everywhere you register this plugin.






          share|improve this answer























          • thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

            – Peter
            Apr 10 at 14:04











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333122%2frequest-handler-unable-to-render-view-with-vision-plugin%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          There is an old thread on GitHub about this. TL;DR: the reference to server passed to the plugin when registering is slightly not the same as the "root" server. Some difference about realms, apparently still an issue.



          Indeed: in the plugin, server.getViewsManager() (decorated by vision) after registration of vision and server.views will show something, whereas the same call in your route (so, after plugin registration) will show null. So much for "references".



          I just tried a similar structure to you, got the same error, and this thread pointed me to a workaround: when registering your views plugin, just pass along a reference to the "real" server in the options.



          // plugin
          const ejs = require('ejs');
          const Vision = require('vision');

          module.exports =
          name: 'views',
          version: '0.0.1',
          register: async (server, path, realServer ) => // <= added option
          await realServer.register(Vision); // <= replaced server w/ realServer
          realServer.views( // <= replaced server w/ realServer
          engines: ejs ,
          path,
          );
          ,
          ;


          // test setup
          // ...
          const server = new Hapi.Server();
          // ...
          await server.register(
          plugin: require('../../server/views'),
          options:
          path: path.join(__dirname, '../views/templates'),
          realServer: server // <= added option

          );


          And, obviously, have the same options everywhere you register this plugin.






          share|improve this answer























          • thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

            – Peter
            Apr 10 at 14:04















          1














          There is an old thread on GitHub about this. TL;DR: the reference to server passed to the plugin when registering is slightly not the same as the "root" server. Some difference about realms, apparently still an issue.



          Indeed: in the plugin, server.getViewsManager() (decorated by vision) after registration of vision and server.views will show something, whereas the same call in your route (so, after plugin registration) will show null. So much for "references".



          I just tried a similar structure to you, got the same error, and this thread pointed me to a workaround: when registering your views plugin, just pass along a reference to the "real" server in the options.



          // plugin
          const ejs = require('ejs');
          const Vision = require('vision');

          module.exports =
          name: 'views',
          version: '0.0.1',
          register: async (server, path, realServer ) => // <= added option
          await realServer.register(Vision); // <= replaced server w/ realServer
          realServer.views( // <= replaced server w/ realServer
          engines: ejs ,
          path,
          );
          ,
          ;


          // test setup
          // ...
          const server = new Hapi.Server();
          // ...
          await server.register(
          plugin: require('../../server/views'),
          options:
          path: path.join(__dirname, '../views/templates'),
          realServer: server // <= added option

          );


          And, obviously, have the same options everywhere you register this plugin.






          share|improve this answer























          • thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

            – Peter
            Apr 10 at 14:04













          1












          1








          1







          There is an old thread on GitHub about this. TL;DR: the reference to server passed to the plugin when registering is slightly not the same as the "root" server. Some difference about realms, apparently still an issue.



          Indeed: in the plugin, server.getViewsManager() (decorated by vision) after registration of vision and server.views will show something, whereas the same call in your route (so, after plugin registration) will show null. So much for "references".



          I just tried a similar structure to you, got the same error, and this thread pointed me to a workaround: when registering your views plugin, just pass along a reference to the "real" server in the options.



          // plugin
          const ejs = require('ejs');
          const Vision = require('vision');

          module.exports =
          name: 'views',
          version: '0.0.1',
          register: async (server, path, realServer ) => // <= added option
          await realServer.register(Vision); // <= replaced server w/ realServer
          realServer.views( // <= replaced server w/ realServer
          engines: ejs ,
          path,
          );
          ,
          ;


          // test setup
          // ...
          const server = new Hapi.Server();
          // ...
          await server.register(
          plugin: require('../../server/views'),
          options:
          path: path.join(__dirname, '../views/templates'),
          realServer: server // <= added option

          );


          And, obviously, have the same options everywhere you register this plugin.






          share|improve this answer













          There is an old thread on GitHub about this. TL;DR: the reference to server passed to the plugin when registering is slightly not the same as the "root" server. Some difference about realms, apparently still an issue.



          Indeed: in the plugin, server.getViewsManager() (decorated by vision) after registration of vision and server.views will show something, whereas the same call in your route (so, after plugin registration) will show null. So much for "references".



          I just tried a similar structure to you, got the same error, and this thread pointed me to a workaround: when registering your views plugin, just pass along a reference to the "real" server in the options.



          // plugin
          const ejs = require('ejs');
          const Vision = require('vision');

          module.exports =
          name: 'views',
          version: '0.0.1',
          register: async (server, path, realServer ) => // <= added option
          await realServer.register(Vision); // <= replaced server w/ realServer
          realServer.views( // <= replaced server w/ realServer
          engines: ejs ,
          path,
          );
          ,
          ;


          // test setup
          // ...
          const server = new Hapi.Server();
          // ...
          await server.register(
          plugin: require('../../server/views'),
          options:
          path: path.join(__dirname, '../views/templates'),
          realServer: server // <= added option

          );


          And, obviously, have the same options everywhere you register this plugin.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 9 at 22:29









          Stock OverflawStock Overflaw

          2,000189




          2,000189












          • thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

            – Peter
            Apr 10 at 14:04

















          • thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

            – Peter
            Apr 10 at 14:04
















          thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

          – Peter
          Apr 10 at 14:04





          thanks that makes sense. I've noticed this doesn't work either sinon.spy(server, "register"). when I looked at the source I think I remember seeing the server getting cloned or something.

          – Peter
          Apr 10 at 14:04



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333122%2frequest-handler-unable-to-render-view-with-vision-plugin%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?