Skip to content

Commit

Permalink
feat: webpack-plugin-demo add network example
Browse files Browse the repository at this point in the history
  • Loading branch information
flyfishzy committed Mar 2, 2022
1 parent 30cb78c commit 7b51f42
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Network {
.fontWeight(FontWeight.Bold)
Button('Use Axios').onClick(() => {
this.response = 'request...'
axios.get('https://developer.harmonyos.com/cn/develop/')
axios.get('https://www.openharmony.cn/sig')
.then((res) => {
console.log('---------')
console.log(res.data)
Expand All @@ -26,7 +26,7 @@ struct Network {

Button('Use fetch').onClick(() => {
this.response = 'request...'
fetch('https://developer.harmonyos.com/cn/develop/')
fetch('https://www.openharmony.cn/sig')
.then(res => {
console.log('-----------')
console.log(res.data)
Expand Down
13 changes: 13 additions & 0 deletions examples/webpack-plugin-demo/entry/src/main/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
"tablet",
"car"
],
"reqPermissions": [
{
"name": "ohos.permission.INTERNET",
"reason": "http",
"usedScene": {
"ability": [
"org.originjs.openharmony.polyfilldemo.MainAbility"
],
"when": "always"
}
}
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
Expand Down Expand Up @@ -53,6 +65,7 @@
"pages": [
"pages/index",
"pages/checksum",
"pages/network",
"pages/xmlparser"
],
"name": "default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PageData {
struct Index {
private pageItems: PageData[] = [
{ name: 'Checksum', page: 'pages/checksum' },
{ name: 'Network', page: 'pages/network' },
{ name: 'fast-xml-parser', page: 'pages/xmlparser' },
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import axios from 'axios'
import {LambdaClient, InvokeCommand} from "@aws-sdk/client-lambda";
import {CognitoIdentityClient} from "@aws-sdk/client-cognito-identity";
import {fromCognitoIdentityPool} from "@aws-sdk/credential-provider-cognito-identity";

@Entry
@Component
struct Network {
@State response: string = ''

build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center,
justifyContent: FlexAlign.Center }) {
Text('OpenHarmony Network Demo')
.fontSize(20)
.fontWeight(FontWeight.Bold)
Button('Use Axios').onClick(() => {
this.response = 'request...'
axios.get('https://www.openharmony.cn/sig')
.then((res) => {
console.log('---------')
console.log(res.data)
this.response = res.statusText
});
})

Button('Use fetch').onClick(() => {
this.response = 'request...'
fetch('https://www.openharmony.cn/sig')
.then(res => {
console.log('-----------')
console.log(res.data)
this.response = res.statusText;
});
})

Button('Use aws-sdk').onClick(() => {
this.response = 'request aws...'
const REGION = "us-west-2"
const client = new LambdaClient({
region: REGION,
credentials: fromCognitoIdentityPool({
client: new CognitoIdentityClient({ region: REGION }),
identityPoolId: 'us-west-2:e88b2309-dcc2-4ea6-a5a9-1cd4b453e7b7' })
});
const params={
FunctionName: "hello",
InvocationType: "RequestResponse",
LogType: "None"
}
client.send(new InvokeCommand(params)).then(
(data) => {
this.response = new TextDecoder('utf-8').decode(data.Payload)
},
(error) => {
this.response = JSON.stringify(error)
}
);
})

Text(this.response)
.fontSize(16)
}
.width('100%')
.height('100%')
}
}
4 changes: 4 additions & 0 deletions examples/webpack-plugin-demo/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"dependencies": {
"@aws-sdk/client-cognito-identity": "^3.53.0",
"@aws-sdk/client-lambda": "^3.53.0",
"@aws-sdk/credential-provider-cognito-identity": "^3.53.0",
"axios": "^0.26.0",
"checksum": "^1.0.0",
"fast-xml-parser": "^4.0.3"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"typescript": "^4.5.5"
},
"simple-git-hooks": {
"pre-commit": "lint-staged --concurrent false",
"pre-commit": "pnpm exec lint-staged --concurrent false",
"commit-msg": "node scripts/verifyCommit.mjs $1"
},
"lint-staged": {
Expand Down

0 comments on commit 7b51f42

Please sign in to comment.