How to retrieve a remote partial in the view in Express? - node.js

I'd like to have a partial come from a service via a url like so (using ejs):
<div>
<%- remotePartial('http://google.com/?q=hi') %>
</div>
Is this possible?

You would need to define a dynamicHelper, that fetches the remote template and passes it to the templating engine.
However, this would require asynchronous dynamicHelpers, which are currently not provided. See this thread on the express user group.

Related

Accessing logged in user roles and include in page source

We are intergrating an external JavaScript application into Acumatica and we have a need to be able to access the logged in users authorization / user access roles. Our thought is that if we can write the logged in users access roles to the page source as global scope variables our JavaScript app can handle the rest, but we are a bit challenged in figuring out how to do that. We know we can write the roles to the trace screen, but that doesn't help as we need it literally in the page source for this to work (ideally the page source and not the DOM - but we can look into if the DOM could work too).
Any help would be much appreciated.
The page source in ASP.Net is a ASPX.CS file that resides on the server, I doubt your JavaScript can hook into that. The communication from the server to the UI layer is a template engine.
You define the fields in the ASPX file and these template fields are populated with the DataViews current record. The minified JavaScript that is in the page runs that templating engine.
You can't simply generate dynamic HTML or access the JavaScript side of things from the server. So having fields values in the DOM is probably your best bet. You can make the controls invisible if required.
Example to read UI control values using JavaScript:
<%# MasterType VirtualPath="~/MasterPages/FormDetail.master" %>
<asp:content id="cont1" contentplaceholderid="phDS" runat="Server">
<script language="javascript" type="text/javascript">
window.addEventListener('load', function () {
// Fetch a value from UI control
var control = px_alls["edControlID"];
var value = control.getValue();
});
</script>
[...]
</asp:content>

JMeter Office360 online : JavaScript required to sign in error while authorization

When I try to login on sharepoint360 online site using JMeter, it gives JavaScript required to sign in error in response. I got below code in response.
<html>
<head>
<noscript>JavaScript required to sign in</noscript>
<title>Continue</title>
<script type="text/javascript">
function OnBack() {}
function DoSubmit() {
var subt = false;
if (!subt) {
subt = true;
document.fmHF.submit();
}
}
</script>
</head>
<body onload="javascript:DoSubmit();">
<form name="fmHF" id="fmHF" action="https://ApplicationURL.sharepoint.com/_forms/default.aspx?apr=1&wa=wsignin1.0" method="post" target="_self">
<input type="hidden" name="t" id="t" value="EgBZAgMAAAAEgAAAAwABJaEZDRmSdbQKqL6rJyYKAN1Z0valM74LOhnXMHkbILiqeyEyWkHmbZ3hVG8XvpXOVLvlnylOzhJx8KQgSsuO0d6P2quRRU168QMumuqH/qvLVkpZ5mPiBDDyI8l1z+E4++pxZ3H37uIevfjckj40rTlGYJ85aT0/nxcqDxlL6pxKStDm9GKNI81ypsDKv7dMEqg9lRDjJO5qmNEDiCP8jPB3WWke5pVqcn6c1MbnbHzKU2uHzekZqjxAflfvWu5LS9R+N6jciFZvicn8P0EV0LZHqmjXgUsoVMdn9gGemJYnQCoIbkk7Oo9DPaqXRsxApY5sqCwotEJvZ45AaBNAQkgBYABIAQAAAxBYNSeVFbxuVhW8blZOoQcACgAgAAAhAGtrQHNmd3Byb2R1Y3RkZXYub25taWNyb3NvZnQuY29tAGMAAC1rayVzZndwcm9kdWN0ZGV2Lm9ubWljcm9zb2Z0LmNvbUBwYXNzcG9ydC5jb20AAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAB0t1bGRlZXAABUt1bWFyAAAAACAAAAAAAAAAAAD//////////wAAFbxuVpUsb1YAAAAAAAAAAAAAAAANADEyMy42My42NS42NgAAAAAAAAAAAAAAAAAAAQAAAQAAAQAAAQAAAADU1N9WAQAAAQAAAAAAAAAAAAAAAAAANwBodHRwczovL3BvcnRhbC5taWNyb3NvZnRvbmxpbmUuY29tL0NoYW5nZVBhc3N3b3JkLmFzcHgA/////wAAAAAAAA==">
</form>
</body>
Thanks in advance.
Sunil
As per Apache JMeter Homepage
JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does
You need to extract the "value" attribute of that "t" hidden input and pass it along with other request parameters. I would recommend using CSS/JQuery Extractor or XPath Extractor for this.
Relevant configurations:
CSS/JQuery Extractor
Reference Name: anything meaningful, i.e. t
CSS/JQuery Expression: input[id=t]
Attribute: value
XPath Extractor
Use Tidy - check. If response is XHTML compliant it is not required however.
Reference Name: again, any JMeter Variable name, i.e. t
XPath Expression: //input[#id='t']/#value
Refer the extracted value as ${t} where required
Handle any other dynamic parameters similarly and you should be good to go. JMeter doesn't execute JavaScript but it can capture and execute JavaScript-driven HTTP requests. Given you perform load testing you shouldn't worry about what is happened in browser as JavaScript is being executed on client side only. See ASP.NET Login Testing with JMeter article for more detailed explanation and instructions.
Looking at how sharepoint authentication works, I believe you need to implement authentication using HTTP Request, instead of using login page, as explained here. Basically you will need 2 HTTP requests: first to extract the SAML token, and second to receive authentication cookies, which you can then use in the following HTTP requests, as you normally do.

Is it possible to include templates within templates with separate contexts?

I'm developing an application in nodejs and handlebars.
I'd like to be able to create a layout template then add various individual components within that layout.
Each component would be created with a separate handlebars template and context.
e.g. layout.tmpl
<html>
<head>...</head>
<body>
<!-- somehow render a handlebars template here with a separate context -->
<!-- somehow render another handlebars template here with a separate context -->
<body>
</html>
Is this possible? If not, is there another templating engine that can do this?
Yes. It is possible with Handlebars partials.

How to create Angularjs layout templates

I am creating a node.js web application where I am using Yeoman angular scaffolding for client side.
I have an index.html which has all the javascript files included to load.
What i want to do is have a header file that will contain users name using model binding. These need to be included in all pages.
How can i achieve this?
You need to use ng-include directive to include partials.
Your index page would be structure something like
<body>
<div id='header' ng-include='/partials/header'/>
<div ng-view />
</body>

How to submit xml data to a web site?

I am using a third party to process transactions. They have an api that says XML content should submitted via an HTTP POST variable named “XML”.
I know how to create the xml, but not sure how to post it to their site. They have a destination url. Can you tell me how to do the Post to their site?
You need to carefully check. Usually you just post XML to an URL. However in this case (indicated by the variable name) it seems that a (typically only used for html forms) form post is needed.
The easiest way is to create a html form with that one field, something like this:
<form method="post" action="http://their url" name="payload">
<input type="hidden" id="XML" name="XML" />
</form>
Then you can fill the field with your XML and do a payload.submit()
Let us know how it goes

Resources