topbit 3.1.7 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/http2.js CHANGED
@@ -5,12 +5,17 @@
5
5
  process.chdir(__dirname)
6
6
 
7
7
  let Topbit = require('../src/topbit.js')
8
- let {Loader} = Topbit
8
+ let {Loader, npargv} = Topbit
9
+
10
+ let {args} = npargv({
11
+ '--httpc': 'httpc'
12
+ })
9
13
 
10
14
  let app = new Topbit({
11
15
  debug: true,
12
16
  globalLog: true,
13
17
  logType: 'stdio',
18
+ allowHTTP1: args.httpc,
14
19
  loadInfoFile: '--mem',
15
20
  cert: './cert/localhost-cert.pem',
16
21
  key: './cert/localhost-privkey.pem',
@@ -25,8 +30,19 @@ if (app.isWorker) {
25
30
  let ld = new Loader()
26
31
 
27
32
  ld.init(app)
33
+
34
+ app.get('/httpc/:id', async ctx => {
35
+ console.log(ctx.headers, ctx.method, ctx.path, ctx.name, ctx.group)
36
+ ctx.to({
37
+ major: ctx.major,
38
+ protocol: ctx.protocol,
39
+ port: ctx.port,
40
+ group: ctx.group
41
+ })
42
+ })
28
43
  }
29
44
 
45
+
30
46
  app.sched('none')
31
47
 
32
48
  app.autoWorker(3)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topbit",
3
- "version": "3.1.7",
3
+ "version": "3.1.8",
4
4
  "description": "A Server-side web framework support http/1.1 and http/2",
5
5
  "main": "src/topbit.js",
6
6
  "directories": {
package/src/httpc.js CHANGED
@@ -6,7 +6,7 @@ const process = require('node:process');
6
6
  const checkHeaderLimit = require('./headerLimit.js')
7
7
  const sendmsg = require('./sendmsg.js');
8
8
 
9
- let Httpc = function () {
9
+ function Httpc() {
10
10
  if ( !(this instanceof Httpc) ) {
11
11
  return new Httpc()
12
12
  }
@@ -1,29 +1,32 @@
1
- const titbit = require('../lib/titbit.js');
1
+ 'use'
2
2
 
3
- var app = new titbit({
3
+ const Topbit = require('../src/topbit.js');
4
+
5
+ let app = new Topbit({
4
6
  debug: true,
5
7
  //http2: true
6
8
  });
7
9
 
8
- var start_time = Date.now();
10
+ let start_time = Date.now()
9
11
 
10
- var ctx = null;
12
+ let ctx = null
11
13
 
12
- let total = 20000;
14
+ let total = 20000
13
15
 
14
- for (let i=0 ;i < total; i++) {
15
- ctx = new app.httpServ.Context();
16
+ for (let i=0; i < total; i++) {
17
+ ctx = new app.httpServ.Context()
16
18
  ctx.path = '/';
17
19
  ctx.ip = '127.0.0.1';
18
- ctx.requestCall = (c) => {
19
- c.send('success');
20
- };
20
+ ctx.requestCall = c => {
21
+ c.to('success')
22
+ }
23
+
21
24
  ctx.box.rand = Math.random()
22
- ctx = null;
25
+ ctx = null
23
26
  }
24
27
 
25
- var end_time = Date.now();
28
+ let end_time = Date.now()
26
29
 
27
30
  let rtm = end_time - start_time;
28
31
 
29
- console.log(rtm, 'ms', `${parseInt(total * 1000 / rtm)}/s`);
32
+ console.log(rtm, 'ms', `${parseInt(total * 1000 / rtm)}/s`)
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const Titbit = require('../lib/titbit.js')
3
+ const Topbit = require('../src/topbit.js')
4
4
 
5
- const app = new Titbit({debug: true})
5
+ const app = new Topbit({debug: true})
6
6
 
7
7
  app.daemon({port:3456, host: '127.0.0.1', worker: 2})