Skip to content

Commit

Permalink
Merge pull request #481 from Zack921/master
Browse files Browse the repository at this point in the history
feat: hack https.createServer
  • Loading branch information
Zack921 authored Jun 22, 2021
2 parents eac93b5 + 38636cb commit 0b7735b
Show file tree
Hide file tree
Showing 8 changed files with 1,133 additions and 182 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dist
.nyc_output
coverage
*.log
benchmark/metricsResult
benchmark/metricsResult
*.pem
12 changes: 12 additions & 0 deletions examples/https/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## How to run demo

### 1. Install Npm
```bash
yarn
// npm i
```

### 2. Start the server
```
npm run serve
```
18 changes: 18 additions & 0 deletions examples/https/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const https = require('https');
const fs = require('fs');
const path = require('path');

const options = {
key: fs.readFileSync(path.resolve(__dirname, 'key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem'))
};

https.createServer(options, function (req, res) {
console.log("hello world");

res.writeHead(200);
res.end("hello world\n");
}).listen(8000);

console.log("origin node server is listening on 8000");

16 changes: 16 additions & 0 deletions examples/https/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "koa-example",
"scripts": {
"serve": "tsw ./index.js",
"serve:inspect": "NODE_OPTIONS='--inspect=localhost:4442' tsw ./index.js"
},
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@tswjs/open-platform-plugin": "^1.3.1",
"@tswjs/tsw": "^2.5.3",
"winston": "^3.2.1",
"winston-transport": "^4.3.0"
}
}
30 changes: 30 additions & 0 deletions examples/https/tswconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const winston = require("winston");
const OpenPlatformPlugin = require("@tswjs/open-platform-plugin");

module.exports = {
plugins: [
new OpenPlatformPlugin({
appid: "tsw1844",
appkey: "fTctzeCnBHKJZyBYmBAB3H5R",
reportStrategy: "proxied",
// 只支持同步写法
getUid: (request) => "xxx",
getProxyInfo: () => {
return {
"port": 80,
"name": "2.0demo",
"group": "TSW",
"groupName": "TSW团队",
"desc": "2.0demo测试环境",
"order": 30,
"owner": "demoUser",
"alphaList": ["xxx"]
};
}
})
],
winstonTransports: [
new winston.transports.File({ filename: 'error.log', level: 'error'}),
new winston.transports.File({ filename: 'debug.log', level: 'debug'})
]
};
Loading

0 comments on commit 0b7735b

Please sign in to comment.