Skip to content

Commit 9a72a75

Browse files
committed
2 parents 0243134 + aa21b0f commit 9a72a75

File tree

21 files changed

+102
-36
lines changed

21 files changed

+102
-36
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ docs
6969

7070
test-result
7171

72-
cli/http-adapter*.js
72+
cli/http-adapter*.js
73+
74+
junit.xml

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"env": {
1212
"NODE_ENV": "development",
1313
"DEBUG": "server:*",
14-
"CONF_PATH": "./conf-dev"
14+
"CONF_PATH": "./conf"
1515
},
1616
"runtimeArgs": [
1717
"-r",

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"kubectl",
1010
"protobuf",
1111
"quotemark",
12+
"stringify",
1213
"tmpl",
1314
"webhook",
1415
"woff"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<a href="https://circleci.com/gh/code2life/http-adapter/tree/master"><img src="https://circleci.com/gh/Code2Life/http-adapter.svg?style=svg" alt="Build Status"></a>
55
<a href="https://codecov.io/gh/code2life/http-adapter/"><img src="https://img.shields.io/codecov/c/github/code2life/http-adapter/master.svg" alt="Coverage Status"></a>
66
<a href="https://www.codacy.com/app/Code2Life/http-adapter?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Code2Life/http-adapter&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/e93d8415d1074997abc36c2918f079e3" alt="Codacy Badge"></a>
7-
<a href="https://codebeat.co/projects/github-com-code2life-http-adapter-master"><img alt="codebeat badge" src="https://codebeat.co/badges/a2025aec-3af4-484e-8b2a-a0a597f69867" /></a>
7+
<a href="https://codebeat.co/projects/github-com-code2life-http-adapter-master"><img alt="codebeat badge" src="https://codebeat.co/badges/190e8cb0-520f-46b1-8129-68197cf17248" /></a>
88
<a href="https://www.npmjs.com/package/node-adapter"><img src="https://img.shields.io/npm/v/node-adapter.svg" alt="Version"></a>
9+
<a href="https://hub.docker.com/r/code2life/http-adapter"><img src="https://img.shields.io/docker/cloud/build/code2life/http-adapter.svg" alt="Version"></a>
910
<a href="https://www.npmjs.com/package/node-adapter"><img src="https://img.shields.io/github/license/Code2Life/http-adapter.svg" alt="License"></a>
1011
</p>
1112

conf/_demo/context.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ mixin:
99
initContext:
1010
libraries:
1111
lodash: _
12+
os: os
1213
constants:
1314
token: 'global token from application context'
14-
webhookSiteURL: https://webhook.site/8bd70130-f663-4c2f-ada4-42a65f6abbf6
15+
httpPostTestURL: http://httpbin.org/post
1516
initFunctions:
1617
init: functions/init.ts
1718
functions:

conf/_demo/functions/init.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type OSEnv = {
2+
home: string;
3+
host: string;
4+
};
5+
6+
function initializeApp () {
7+
let osEnv = {} as OSEnv;
8+
osEnv.home = this.os.homedir();
9+
osEnv.host = this.os.hostname();
10+
console.log(`initialized: ${JSON.stringify(osEnv)}`);
11+
}
12+
13+
export default initializeApp;

conf/_demo/functions/log.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(msg) => {
2+
console.log(msg);
3+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Context } from 'koa';
2+
import { AxiosRequestConfig } from 'axios';
3+
import { DynamicRuntime } from '../types';
4+
5+
/**
6+
*
7+
* @param {AxiosConfig} axiosConf
8+
* @param {KoaContext} context
9+
*/
10+
async function relayInterceptor(this: DynamicRuntime, axiosConf: AxiosRequestConfig, ctx: Context) {
11+
this.log(`relay interceptor from config: ${ctx.hostname}, ${JSON.stringify(axiosConf)}`);
12+
}
13+
14+
export default relayInterceptor;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import { ResponseObj } from '../types' ;
2+
// import { Context} from 'koa';
3+
4+
/**
5+
* @param respObj, statusCode, headers, body
6+
* @param ctx, Koa2 request context
7+
*/
8+
async (respObj, ctx) => {
9+
this.log(`response interceptor from config: ${ctx.reqId}`);
10+
}

conf/_demo/routes/get-user.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ extract:
77
validate: val => val && val.indexOf('gzip') !== -1
88
# bodyHandlers
99
relay:
10-
- name: webhook.site
11-
location: ${this.webhookSiteURL}
10+
- name: demoPost
11+
location: ${this.httpPostTestURL}
1212
method: post
1313
headers:
14-
original-acceipt-encoding: ${this.accept}
14+
original-accept-encoding: ${this.accept}
1515
token-from-context: ${this.token}
1616
body: |-
17-
{ id: "${ctx.request.params.userId}" }
17+
{ id: "${ctx.params.userId}", data: "demo" }
1818
interceptors:
19-
relay-interceptor: function/relay-interceptor.ts
19+
relay-interceptor: functions/relay-interceptor.ts
2020
response:
2121
policy: 'afterRelay'
2222
headers:
2323
request-id: ${ctx.reqId}
2424
body: templates/response-body.tmpl
2525
interceptors:
26-
response-interceptor: function/response-interceptor.js
26+
response-interceptor: functions/response-interceptor.js

0 commit comments

Comments
 (0)