Skip to content

Commit 0b7735b

Browse files
authored
Merge pull request #481 from Zack921/master
feat: hack https.createServer
2 parents eac93b5 + 38636cb commit 0b7735b

File tree

8 files changed

+1133
-182
lines changed

8 files changed

+1133
-182
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ dist
66
.nyc_output
77
coverage
88
*.log
9-
benchmark/metricsResult
9+
benchmark/metricsResult
10+
*.pem

examples/https/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## How to run demo
2+
3+
### 1. Install Npm
4+
```bash
5+
yarn
6+
// npm i
7+
```
8+
9+
### 2. Start the server
10+
```
11+
npm run serve
12+
```

examples/https/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const https = require('https');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const options = {
6+
key: fs.readFileSync(path.resolve(__dirname, 'key.pem')),
7+
cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem'))
8+
};
9+
10+
https.createServer(options, function (req, res) {
11+
console.log("hello world");
12+
13+
res.writeHead(200);
14+
res.end("hello world\n");
15+
}).listen(8000);
16+
17+
console.log("origin node server is listening on 8000");
18+

examples/https/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "koa-example",
3+
"scripts": {
4+
"serve": "tsw ./index.js",
5+
"serve:inspect": "NODE_OPTIONS='--inspect=localhost:4442' tsw ./index.js"
6+
},
7+
"version": "1.0.0",
8+
"main": "index.js",
9+
"license": "MIT",
10+
"dependencies": {
11+
"@tswjs/open-platform-plugin": "^1.3.1",
12+
"@tswjs/tsw": "^2.5.3",
13+
"winston": "^3.2.1",
14+
"winston-transport": "^4.3.0"
15+
}
16+
}

examples/https/tswconfig.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const winston = require("winston");
2+
const OpenPlatformPlugin = require("@tswjs/open-platform-plugin");
3+
4+
module.exports = {
5+
plugins: [
6+
new OpenPlatformPlugin({
7+
appid: "tsw1844",
8+
appkey: "fTctzeCnBHKJZyBYmBAB3H5R",
9+
reportStrategy: "proxied",
10+
// 只支持同步写法
11+
getUid: (request) => "xxx",
12+
getProxyInfo: () => {
13+
return {
14+
"port": 80,
15+
"name": "2.0demo",
16+
"group": "TSW",
17+
"groupName": "TSW团队",
18+
"desc": "2.0demo测试环境",
19+
"order": 30,
20+
"owner": "demoUser",
21+
"alphaList": ["xxx"]
22+
};
23+
}
24+
})
25+
],
26+
winstonTransports: [
27+
new winston.transports.File({ filename: 'error.log', level: 'error'}),
28+
new winston.transports.File({ filename: 'debug.log', level: 'debug'})
29+
]
30+
};

0 commit comments

Comments
 (0)