This is an automated email from the ASF dual-hosted git repository.
hufeng pushed a commit to branch v3.0.0
in repository https://gitbox.apache.org/repos/asf/dubbo-js.git
The following commit(s) were added to refs/heads/v3.0.0 by this push:
new afc8402 refactor hello-midway
afc8402 is described below
commit afc8402942653dc8e14f745b84c43b57ef80d021
Author: hufeng <[email protected]>
AuthorDate: Wed Sep 9 23:05:50 2020 +0800
refactor hello-midway
---
.gitignore | 3 +-
examples/hello-midway/.travis.yml | 16 --------
examples/hello-midway/README.md | 1 +
examples/hello-midway/appveyor.yml | 16 --------
examples/hello-midway/package.json | 2 -
examples/hello-midway/src/app.ts | 5 ++-
examples/hello-midway/src/app/controller/home.ts | 45 ++++++++++++++++++++--
examples/hello-midway/src/app/dubbo/index.ts | 12 +++++-
examples/hello-midway/src/typings/app/index.d.ts | 25 ------------
.../hello-midway/src/typings/globals/index.d.ts | 37 ------------------
10 files changed, 59 insertions(+), 103 deletions(-)
diff --git a/.gitignore b/.gitignore
index 84915e7..dc90226 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,4 +56,5 @@ temp
es6
es7
-examples/hello-egg/typings
\ No newline at end of file
+examples/hello-egg/typings
+examples/hello-midway/src/typings
\ No newline at end of file
diff --git a/examples/hello-midway/.travis.yml
b/examples/hello-midway/.travis.yml
index be98816..97a70fc 100644
--- a/examples/hello-midway/.travis.yml
+++ b/examples/hello-midway/.travis.yml
@@ -1,19 +1,3 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
language: node_js
node_js:
- '10'
diff --git a/examples/hello-midway/README.md b/examples/hello-midway/README.md
index c33f09d..0464566 100644
--- a/examples/hello-midway/README.md
+++ b/examples/hello-midway/README.md
@@ -4,6 +4,7 @@
```bash
$ cd ../../
+$ make
$ sh start_dubbo_service.sh
$ cd examples/hello-midway
$ yarn
diff --git a/examples/hello-midway/appveyor.yml
b/examples/hello-midway/appveyor.yml
index 8329ad0..5830a38 100644
--- a/examples/hello-midway/appveyor.yml
+++ b/examples/hello-midway/appveyor.yml
@@ -1,19 +1,3 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
environment:
matrix:
- nodejs_version: '10'
diff --git a/examples/hello-midway/package.json
b/examples/hello-midway/package.json
index 95f88bf..3405fc7 100755
--- a/examples/hello-midway/package.json
+++ b/examples/hello-midway/package.json
@@ -4,9 +4,7 @@
"description": "",
"private": true,
"dependencies": {
- "apache-dubbo-js": "^3.0.0-rc6",
"egg-scripts": "^2.10.0",
- "interpret-util": "^0.0.6",
"midway": "^1.0.0"
},
"devDependencies": {
diff --git a/examples/hello-midway/src/app.ts b/examples/hello-midway/src/app.ts
index fe18b4a..799b0cd 100644
--- a/examples/hello-midway/src/app.ts
+++ b/examples/hello-midway/src/app.ts
@@ -19,10 +19,11 @@ import {Application} from 'midway';
import dubbo from './app/dubbo';
export default async (app: Application) => {
- dubbo(app);
- await app.dubbo.ready();
app.beforeStart(async () => {
console.log('🚀 Your awesome APP is launching...');
+ dubbo(app);
+ await app.dubbo.ready();
+ console.log('dubbo was ready..');
console.log('✅ Your awesome APP launched');
});
};
diff --git a/examples/hello-midway/src/app/controller/home.ts
b/examples/hello-midway/src/app/controller/home.ts
index 2b0ce63..57b1fd2 100755
--- a/examples/hello-midway/src/app/controller/home.ts
+++ b/examples/hello-midway/src/app/controller/home.ts
@@ -16,8 +16,10 @@
*/
import {Context, inject, controller, get, provide} from 'midway';
-import {IDubbo} from '../../typings/app/index';
import {java} from 'apache-dubbo-js';
+import {Sex} from '../dubbo/providers/org/apache/dubbo/demo/Sex';
+import {TypeRequest} from
'../dubbo/providers/org/apache/dubbo/demo/TypeRequest';
+import {UserRequest} from
'../dubbo/providers/org/apache/dubbo/demo/UserRequest';
@provide()
@controller('/')
@@ -31,10 +33,47 @@ export class HomeController {
}
@get('/hello')
- async dubboTest(ctx: Context & IDubbo) {
- const {res, err} = await ctx.app.dubbo.service.DemoProvider.sayHello(
+ async hello() {
+ const {res, err} = await this.ctx.app.dubbo.service.DemoProvider.sayHello(
java.String('hello from node world'),
);
this.ctx.body = err ? err.message : res;
}
+
+ @get('/user-info')
+ async userInfo() {
+ const {
+ res,
+ err,
+ } = await this.ctx.app.dubbo.service.DemoProvider.getUserInfo(
+ new UserRequest({
+ sex: Sex.female,
+ email: '[email protected]',
+ name: 'yangxiaodong',
+ id: 1001,
+ }),
+ );
+
+ this.ctx.body = err ? err.message : res;
+ }
+
+ @get('/echo')
+ async echo() {
+ const {res, err} = await this.ctx.app.dubbo.service.DemoProvider.echo();
+ this.ctx.body = err ? err.message : res;
+ }
+
+ @get('basic-type')
+ async basicType() {
+ const {
+ res,
+ err,
+ } = await this.ctx.app.dubbo.service.BasicTypeProvider.testBasicType(
+ new TypeRequest({
+ bigDecimal: {value: '100.00'},
+ map: {hello: 'hello'},
+ }),
+ );
+ this.ctx.body = err ? err.message : res;
+ }
}
diff --git a/examples/hello-midway/src/app/dubbo/index.ts
b/examples/hello-midway/src/app/dubbo/index.ts
index 84a39a5..48ed113 100644
--- a/examples/hello-midway/src/app/dubbo/index.ts
+++ b/examples/hello-midway/src/app/dubbo/index.ts
@@ -19,8 +19,16 @@ import {Dubbo, setting} from 'apache-dubbo-js';
import {Application, Context} from 'midway';
import service from './service';
+declare module 'egg' {
+ export interface EggApplication {
+ dubbo: Dubbo<typeof service>;
+ }
+}
+
export default async (app: Application) => {
- const {application, register} = app.config.dubbo;
+ /**
+ * invoke dubbo configuration, such as version, group etc.
+ */
const dubboSetting = setting
.match(
[
@@ -32,6 +40,8 @@ export default async (app: Application) => {
},
)
.match('org.apache.dubbo.demo.BasicTypeProvider', {version: '2.0.0'});
+
+ const {application, register} = app.config.dubbo;
const dubbo = new Dubbo<typeof service>({
application,
register,
diff --git a/examples/hello-midway/src/typings/app/index.d.ts
b/examples/hello-midway/src/typings/app/index.d.ts
deleted file mode 100644
index 37ea301..0000000
--- a/examples/hello-midway/src/typings/app/index.d.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import dubbo from '../../app/dubbo';
-declare module 'egg' {}
-
-interface IDubbo {
- app: {
- dubbo: any;
- };
-}
diff --git a/examples/hello-midway/src/typings/globals/index.d.ts
b/examples/hello-midway/src/typings/globals/index.d.ts
deleted file mode 100644
index da29b82..0000000
--- a/examples/hello-midway/src/typings/globals/index.d.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-type ExtendInterface<T> = {[P in keyof T]: T[P]};
-
-interface GlobalMiddlewareNameObject {
- //
-}
-
-interface GlobalControllerRouterOptions {
- sensitive?: boolean;
- middleware: GlobalMiddlewareNames;
-}
-
-type GlobalMiddlewareNames = (keyof GlobalMiddlewareNameObject)[] | undefined;
-
-interface GlobalValidateIdentifierObject {
- //
-}
-
-interface AnyObject {
- [k: string]: any;
-}