【发布时间】:2020-10-20 11:32:23
【问题描述】:
我玩过UiPath Orchestrator package。并且使用安装的 node.js 包连接成功。
无论如何,现在我需要在我的网站中以一种可以从简单的html 网站访问它的方式实现它。
在那里我很难让它运行。这就是我想使用它的方式:
index.html:
<html>
...
<button onclick="test()">Do something</button>
...
<script src="scripts.js"></script>
...
</html>
server.js:(我以node server.js开头)
var http = require('http'),
fs = require('fs');
const port = 6543;
const path = require('path');
const server = http.createServer((req, res) => {
let filePath = path.join(
__dirname,
req.url === "/" ? "index.html" : req.url
);
let extName = path.extname(filePath);
let contentType = 'text/html';
switch (extName) {
case '.js':
contentType = 'text/javascript';
break;
}
console.log(`File path: ${filePath}`);
console.log(`Content-Type: ${contentType}`);
res.writeHead(200, {'Content-Type': contentType});
const readStream = fs.createReadStream(filePath);
readStream.pipe(res);
});
server.listen(port, (err) => {
...
});
scripts.js:
function test() {
...
// get the orch object here without defining it here as it contains credentials
var orchestratorInstance = new Orchestrator({
tenancyName: string (optional),
usernameOrEmailAddress: string (required),
password: string (required),
hostname: string (required),
isSecure: boolean (optional, default=true),
port: integer (optional, [1..65535], default={443,80} depending on isSecure),
invalidCertificate: boolean (optional, default=false),
connectionPool: number (optional, 0=unlimited, default=1)
});
}
这行得通。所以测试函数被触发了。
但现在我想获取Orchestrator 对象(如此处所示https://www.npmjs.com/package/uipath-orchestrator)。
如何以最好的方式做到这一点?
也许只是将该对象传递给scripts.js 文件本身?但是如何使用window 或global 来做到这一点,这会是一个合适的解决方案吗?
我需要服务器端生成的对象,因为它包含可能不会传送到客户端的凭据。
【问题讨论】:
-
您可以将节点生成的 javascript 嵌入到 html 的脚本文件中。
-
如何处理对象?一些示例代码?
标签: javascript node.js uipath