Skip to content

Commit edabdf2

Browse files
committed
test: demo app update
1 parent 68e3e66 commit edabdf2

File tree

10 files changed

+389
-486
lines changed

10 files changed

+389
-486
lines changed

demo/app/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@import '~nativescript-theme-core/css/core.light.css';
1+


demo/app/app.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import * as application from '@nativescript/core/application';
2-
3-
application.run({moduleName: "main-page"});
2+
import { knownFolders, path } from '@nativescript/core/file-system';
3+
import * as Https from '@nativescript-community/https';
4+
Https.setCache({
5+
diskLocation: path.join(knownFolders.documents().path, 'httpcache'),
6+
diskSize: 10 * 1024 * 1024, // 10 MiB
7+
});
8+
application.run({ moduleName: 'main-page' });

demo/app/main-page.ts

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as Https from "nativescript-https";
2-
import * as Observable from "@nativescript/core/data/observable";
3-
import * as fs from "@nativescript/core/file-system";
4-
import * as dialogs from "@nativescript/core/ui/dialogs";
5-
import * as Page from "@nativescript/core/ui/page";
1+
import * as Https from '@nativescript-community/https';
2+
import * as Observable from '@nativescript/core/data/observable';
3+
import * as fs from '@nativescript/core/file-system';
4+
import * as dialogs from '@nativescript/core/ui/dialogs';
5+
import * as Page from '@nativescript/core/ui/page';
66

77
let page;
88
let viewModel;
@@ -16,21 +16,18 @@ export function pageLoaded(args: Page.NavigatedData) {
1616
page.bindingContext = viewModel;
1717
}
1818

19-
function createRequest(
20-
url: string,
21-
options?: Partial<Https.HttpsRequestOptions>
22-
) {
19+
function createRequest(url: string, options?: Partial<Https.HttpsRequestOptions>) {
2320
return Https.createRequest({
2421
useLegacy: true,
2522
url,
26-
method: "GET",
23+
method: 'GET',
2724
timeout: 1,
2825
...options,
2926
});
3027
}
3128

3229
function onError(error) {
33-
console.error("Https.request error", error, error.stack);
30+
console.error('Https.request error', error, error.stack);
3431
dialogs.alert(error.toString());
3532
page.bindingContext.currentRequest = null;
3633
page.bindingContext.progress = 0;
@@ -40,59 +37,61 @@ function getRequest(url: string, options?: Partial<Https.HttpsRequestOptions>) {
4037
return Https.request({
4138
useLegacy: true,
4239
url,
43-
method: "GET",
40+
method: 'GET',
4441
timeout: 1,
4542
...options,
4643
})
4744
.then((response) => {
4845
page.bindingContext.currentRequest = null;
4946
page.bindingContext.progress = 0;
50-
console.log("Https.request response", response);
47+
console.log('Https.request response', response);
5148
return response;
5249
})
5350
.catch(onError);
5451
}
5552

56-
function postRequest(
57-
url: string,
58-
options?: Partial<Https.HttpsRequestOptions>
59-
) {
53+
function postRequest(url: string, options?: Partial<Https.HttpsRequestOptions>) {
6054
return Https.request({
6155
useLegacy: true,
6256
url,
63-
method: "POST",
57+
method: 'POST',
6458
...options,
6559
})
66-
.then((response) => console.log("Https.request response", response))
60+
.then((response) => console.log('Https.request response', response))
6761
.catch((error) => {
68-
console.error("Https.request error", error);
62+
console.error('Https.request error', error);
6963
dialogs.alert(error);
7064
});
7165
}
7266

7367
export function postHttpbin() {
74-
postRequest("https://httpbin.org/post", {
75-
body: { foo: "bar", baz: undefined, plaz: null },
68+
postRequest('https://httpbin.org/post', {
69+
body: { foo: 'bar', baz: undefined, plaz: null },
7670
});
7771
}
7872

7973
export function postHttpbinWithUTF8() {
8074
Https.request({
81-
url: "https://httpbin.org/post",
82-
method: "POST",
83-
body: { foo: "bar", baz: undefined, plaz: null },
75+
url: 'https://httpbin.org/post',
76+
method: 'POST',
77+
body: { foo: 'bar', baz: undefined, plaz: null },
8478
headers: {
85-
"Content-Type": "application/json; charset=utf-8",
86-
"X-testing": "ok",
79+
'Content-Type': 'application/json; charset=utf-8',
80+
'X-testing': 'ok',
8781
},
8882
}).catch((error) => {
89-
console.error("Https.request error", error);
83+
console.error('Https.request error', error);
9084
dialogs.alert(error);
9185
});
9286
}
9387

9488
export function getHttpbin() {
95-
getRequest("https://httpbin.org/get");
89+
getRequest('https://httpbin.org/get', {
90+
headers: {
91+
// 'Cache-Control': 'public, only-if-cached, max-stale=' +(60 * 60 * 24 * 7),
92+
'Cache-Control': 'max-age=50000',
93+
}
94+
});
9695
}
9796

9897
export function cancelCurrentRequest() {
@@ -101,65 +100,60 @@ export function cancelCurrentRequest() {
101100
}
102101
}
103102
export function getBigFile() {
104-
const request = createRequest(
105-
"http://ipv4.download.thinkbroadband.com/200MB.zip",
106-
{
107-
onProgress: (current, total) => {
108-
page.bindingContext.progress = (current / total) * 100;
109-
},
110-
}
111-
);
103+
const request = createRequest('http://ipv4.download.thinkbroadband.com/200MB.zip', {
104+
onProgress: (current, total) => {
105+
page.bindingContext.progress = (current / total) * 100;
106+
},
107+
});
112108
page.bindingContext.currentRequest = request;
113109

114110
return new Promise<any>((resolve, reject) => {
115111
request.run(resolve, reject);
116112
})
117113
.then((response) => {
118-
console.log("did get response");
119-
let dir = fs.knownFolders.temp().getFile("200MB.zip");
120-
return (response.content as Https.HttpsResponseLegacy).toFile(
121-
dir.path
122-
);
114+
console.log('did get response');
115+
const dir = fs.knownFolders.temp().getFile('200MB.zip');
116+
return (response.content as Https.HttpsResponseLegacy).toFile(dir.path);
123117
// console.log("did get response done");
124118
})
125119
.then(() => {
126120
page.bindingContext.currentPromise = null;
127-
console.log("did get response done");
121+
console.log('did get response done');
128122
})
129123
.catch(onError);
130124
}
131125

132126
export function getHttpbinLargeResponse() {
133-
getRequest("https://httpbin.org/bytes/100000");
127+
getRequest('https://httpbin.org/bytes/100000');
134128
}
135129

136130
export function getMockbin() {
137-
getRequest("https://mockbin.com/request");
131+
getRequest('https://mockbin.com/request');
138132
}
139133

140134
export function get404() {
141-
getRequest("https://mockbin.com/reque2st");
135+
getRequest('https://mockbin.com/reque2st');
142136
}
143137

144138
export function enableSSLPinning(args: Observable.EventData) {
145-
let dir = fs.knownFolders.currentApp().getFolder("assets");
146-
let certificate = dir.getFile("httpbin.org.cer").path;
139+
const dir = fs.knownFolders.currentApp().getFolder('assets');
140+
const certificate = dir.getFile('httpbin.org.cer').path;
147141
Https.enableSSLPinning({
148-
host: "httpbin.org",
149-
commonName: "httpbin.org",
142+
host: 'httpbin.org',
143+
commonName: 'httpbin.org',
150144
certificate,
151145
});
152-
console.log("enabled");
146+
console.log('enabled');
153147
}
154148

155149
export function enableSSLPinningExpired(args: Observable.EventData) {
156-
let dir = fs.knownFolders.currentApp().getFolder("assets");
157-
let certificate = dir.getFile("httpbin.org.expired.cer").path;
158-
Https.enableSSLPinning({ host: "httpbin.org", certificate });
159-
console.log("enabled");
150+
const dir = fs.knownFolders.currentApp().getFolder('assets');
151+
const certificate = dir.getFile('httpbin.org.expired.cer').path;
152+
Https.enableSSLPinning({ host: 'httpbin.org', certificate });
153+
console.log('enabled');
160154
}
161155

162156
export function disableSSLPinning(args: Observable.EventData) {
163157
Https.disableSSLPinning();
164-
console.log("disabled");
158+
console.log('disabled');
165159
}

demo/app/package.json

Lines changed: 0 additions & 112 deletions
This file was deleted.

demo/nativescript.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NativeScriptConfig } from '@nativescript/core';
2+
3+
export default {
4+
id: 'org.nativescript.plugindemo.https',
5+
appResourcesPath: 'app/App_Resources',
6+
android: {
7+
v8Flags: '--expose_gc',
8+
markingMode: 'none',
9+
requireModules: {
10+
0: 'nativescript-https',
11+
},
12+
},
13+
appPath: 'app',
14+
} as NativeScriptConfig;

demo/package.json

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
{
2-
"nativescript": {
3-
"id": "org.nativescript.plugindemo.https",
4-
"tns-android": {
5-
"version": "6.4.1"
6-
},
7-
"tns-ios": {
8-
"version": "7.0.0-beta.3-v8-2020-03-21-010353-01"
9-
}
10-
},
112
"dependencies": {
12-
"nativescript-https": "file:../src",
13-
"nativescript-theme-core": "^1.0.4",
14-
"nativescript-unit-test-runner": "0.7.0",
15-
"@nativescript/core": "~6.4.0"
3+
"@nativescript-community/https": "file:../plugin",
4+
"@nativescript/core": "7.2.0",
5+
"@nativescript/webpack": "4.1.0",
6+
"nativescript-theme-core": "^2.0.24",
7+
"nativescript-unit-test-runner": "0.7.0"
168
},
179
"devDependencies": {
10+
"@nativescript/android": "7.0.1",
11+
"@nativescript/types": "7.0.0",
1812
"nativescript-css-loader": "~0.26.1",
19-
"nativescript-dev-webpack": "~1.5.0",
20-
"tns-platform-declarations": "~6.4.0",
21-
"tslint": "~5.11.0",
22-
"typescript": "3.4.5"
13+
"typescript": "3.9.7"
2314
},
2415
"scripts": {
2516
"build.plugin": "cd ../src && npm run build",
2617
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'"
27-
}
18+
},
19+
"main": "app.js"
2820
}

demo/references.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
/// <reference path="../src/node_modules/tns-platform-declarations/ios.d.ts" />
2-
/// <reference path="../src/node_modules/tns-platform-declarations/android.d.ts" />

0 commit comments

Comments
 (0)