Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
752bbd74b0 | |||
467f8d3254 | |||
9ff7713103 | |||
30de4add37 | |||
434dbd718a | |||
94cb734f9f | |||
e03edc6bbf | |||
03c4340e4c | |||
f048bd407b | |||
93a43d7ff5 |
@ -1,5 +1,5 @@
|
||||
# gitzone ci_default
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@ -38,19 +38,7 @@ snyk:
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
@ -60,6 +48,18 @@ testSTABLE:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
@ -82,7 +82,7 @@ codequality:
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command tslint -c tslint.json ./ts/**/*.ts
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@ -98,7 +98,9 @@ trigger:
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
20
.vscode/settings.json
vendored
Normal file
20
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2179
package-lock.json
generated
2179
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/webrequest",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.6",
|
||||
"private": false,
|
||||
"description": "securely request from browsers",
|
||||
"main": "dist/index.js",
|
||||
@ -13,23 +13,24 @@
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.3",
|
||||
"@gitzone/tstest": "^1.0.17",
|
||||
"@pushrocks/smartexpress": "^2.0.4",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.12",
|
||||
"node-fetch": "^2.3.0",
|
||||
"tslint": "^5.17.0",
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/smartexpress": "^3.0.40",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.7.8",
|
||||
"node-fetch": "^2.6.0",
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.2"
|
||||
"@pushrocks/smartdelay": "^2.0.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
|
@ -21,6 +21,6 @@ securely request from browsers
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
[](https://maintainedby.lossless.com)
|
||||
|
@ -60,11 +60,17 @@ tap.test('first test', async tools => {
|
||||
'http://localhost:2345/apiroute3'
|
||||
]);
|
||||
|
||||
const response2 = await new webrequest.WebRequest().getJson('http://localhost:2345/apiroute3');
|
||||
|
||||
console.log(response);
|
||||
console.log(response2)
|
||||
|
||||
expect(response)
|
||||
.property('hithere')
|
||||
.to.equal('hi');
|
||||
expect(response2)
|
||||
.property('hithere')
|
||||
.to.equal('hi');
|
||||
});
|
||||
|
||||
tap.test('tear down server', async () => {
|
||||
|
22
ts/index.ts
22
ts/index.ts
@ -4,9 +4,8 @@ import * as plugins from './webrequest.plugins';
|
||||
* web request
|
||||
*/
|
||||
export class WebRequest {
|
||||
public async getJson(urlArg: string | string[], requestBody?: any) {
|
||||
public async getJson(urlArg: string | string[]) {
|
||||
const response: Response = await this.request(urlArg, {
|
||||
body: requestBody,
|
||||
method: 'GET'
|
||||
});
|
||||
return response.json();
|
||||
@ -17,8 +16,8 @@ export class WebRequest {
|
||||
*/
|
||||
public async postJson(urlArg: string, requestBody?: any) {
|
||||
const response: Response = await this.request(urlArg, {
|
||||
body: requestBody,
|
||||
method: 'GET'
|
||||
body: JSON.stringify(requestBody),
|
||||
method: 'POST'
|
||||
});
|
||||
return response.json();
|
||||
}
|
||||
@ -28,8 +27,8 @@ export class WebRequest {
|
||||
*/
|
||||
public async putJson(urlArg: string, requestBody?: any) {
|
||||
const response: Response = await this.request(urlArg, {
|
||||
body: requestBody,
|
||||
method: 'GET'
|
||||
body: JSON.stringify(requestBody),
|
||||
method: 'PUT'
|
||||
});
|
||||
return response.json();
|
||||
}
|
||||
@ -37,18 +36,17 @@ export class WebRequest {
|
||||
/**
|
||||
* put js
|
||||
*/
|
||||
public async deleteJson(urlArg: string, requestBody?: any) {
|
||||
public async deleteJson(urlArg: string) {
|
||||
const response: Response = await this.request(urlArg, {
|
||||
body: requestBody,
|
||||
method: 'GET'
|
||||
});
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* a fault tolerant request
|
||||
*/
|
||||
async request(
|
||||
public async request(
|
||||
urlArg: string | string[],
|
||||
optionsArg: {
|
||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||
@ -91,7 +89,7 @@ export class WebRequest {
|
||||
if (!urlToUse) {
|
||||
throw new Error('request failed permanently');
|
||||
}
|
||||
|
||||
console.log(`Getting ${urlToUse} with method ${optionsArg.method}`);
|
||||
const response = await fetch(urlToUse, {
|
||||
method: optionsArg.method,
|
||||
headers: {
|
||||
@ -110,7 +108,7 @@ export class WebRequest {
|
||||
}
|
||||
};
|
||||
|
||||
const finalResponse: Response = await doRequest(urlArg[usedUrlIndex]);
|
||||
const finalResponse: Response = await doRequest(allUrls[usedUrlIndex]);
|
||||
console.log(finalResponse);
|
||||
return finalResponse;
|
||||
}
|
||||
|
Reference in New Issue
Block a user