refactor hello-midway
diff --git a/.gitignore b/.gitignore
index 84915e7..dc90226 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,4 +56,5 @@
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 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 @@
}
@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: 'coder.yang20100@gmail.com',
+ 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 {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 @@
},
)
.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;
-}