将项目结构调整为前后端分离的清晰目录布局,优化了代码组织和可维护性。主要变更包括: - 将前端代码移至frontend目录 - 将后端代码移至backend目录 - 更新README.md以反映新的目录结构 - 优化.gitignore文件 - 修复部分文件路径问题
38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
var signer = require('./signer');
|
||
var https = require("https");
|
||
var sig = new signer.Signer();
|
||
//Set the AK/SK to sign and authenticate the request.
|
||
// 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;
|
||
// 本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。
|
||
sig.Key = process.env.HUAWEICLOUD_SDK_AK;
|
||
sig.Secret = process.env.HUAWEICLOUD_SDK_SK;
|
||
|
||
//The following example shows how to set the request URL and parameters to query a VPC list.
|
||
//Specify a request method, such as GET, PUT, POST, DELETE, HEAD, and PATCH.
|
||
//Set request host.
|
||
//Set request URI.
|
||
//Set parameters for the request URL.
|
||
var r = new signer.HttpRequest("GET", "endpoint.example.com/v1/77b6a44cba5143ab91d13ab9a8ff44fd/vpcs?limie=1");
|
||
//Add header parameters, for example, x-domain-id for invoking a global service and x-project-id for invoking a project-level service.
|
||
r.headers = {"Content-Type": "application/json"};
|
||
//Add a body if you have specified the PUT or POST method. Special characters, such as the double quotation mark ("), contained in the body must be escaped.
|
||
r.body = '';
|
||
|
||
var opt = sig.Sign(r);
|
||
console.log(opt.headers["X-Sdk-Date"]);
|
||
console.log(opt.headers["Authorization"]);
|
||
|
||
var req = https.request(opt, function (res) {
|
||
console.log(res.statusCode);
|
||
console.log('headers:', JSON.stringify(res.headers));
|
||
res.on("data", function (chunk) {
|
||
console.log(chunk.toString())
|
||
})
|
||
});
|
||
|
||
req.on("error", function (err) {
|
||
console.log(err.message)
|
||
});
|
||
req.write(r.body);
|
||
req.end();
|