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;
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
add a comment |
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
add a comment |
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
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
javascript hapijs hapijs-vision
asked Mar 25 at 7:37
PeterPeter
2,26442950
2,26442950
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
thanks that makes sense. I've noticed this doesn't work eithersinon.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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
thanks that makes sense. I've noticed this doesn't work eithersinon.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
add a comment |
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.
thanks that makes sense. I've noticed this doesn't work eithersinon.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
add a comment |
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.
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.
answered Apr 9 at 22:29
Stock OverflawStock Overflaw
2,000189
2,000189
thanks that makes sense. I've noticed this doesn't work eithersinon.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
add a comment |
thanks that makes sense. I've noticed this doesn't work eithersinon.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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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