topbit 3.0.0 → 3.0.2

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/README.cn.md CHANGED
@@ -131,7 +131,7 @@ GET POST PUT PATCH DELETE OPTIONS TRACE HEAD
131
131
 
132
132
  'use strict'
133
133
 
134
- const Topbit = require('titibit')
134
+ const Topbit = require('topibit')
135
135
 
136
136
  const app = new Topbit({
137
137
  debug: true
@@ -705,14 +705,12 @@ app.use(async (c, next) => {
705
705
  })
706
706
 
707
707
  //use可以级联: app.use(m1).use(m2)
708
- //在21.5.4版本以后,不过这个功能其实根本不重要
709
- //因为有topbit-loader扩展,实现的功能要强大的多。
710
708
 
711
709
  ```
712
710
 
713
711
  ## topbit完整的流程图示
714
712
 
715
- ![](images/topbit-middleware.png)
713
+ ![](images/topbit-middleware.webp)
716
714
 
717
715
 
718
716
  > **需要知道的是,其实在内部,body数据接收和解析也都是中间件,只是刻意安排了顺序,分出了pre和use接口。**
package/README.md CHANGED
@@ -113,7 +113,7 @@ The first 6 are the most commonly used. For each request type, the router has a
113
113
 
114
114
  'use strict'
115
115
 
116
- const Topbit = require('titibit')
116
+ const Topbit = require('topibit')
117
117
 
118
118
  const app = new Topbit({
119
119
  debug: true
@@ -678,13 +678,11 @@ app.use(async (c, next) => {
678
678
  })
679
679
 
680
680
  // use can be cascaded: app.use(m1).use(m2)
681
- // Available after v21.5.4, but this feature is not critical
682
- // because the topbit-loader extension offers much more powerful functionality.
683
681
  ```
684
682
 
685
683
  ## Topbit Complete Flow Chart
686
684
 
687
- ![](images/topbit-middleware.png)
685
+ ![](images/topbit-middleware.webp)
688
686
 
689
687
  > **It is important to know that internally, body data reception and parsing are also middleware. The order is deliberately arranged, separating `pre` and `use` interfaces.**
690
688
 
@@ -0,0 +1,13 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIB4DCCAYWgAwIBAgIUP4XKCZ4CiwGAQDcWvyJknRmVAOcwCgYIKoZIzj0EAw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koxDjAMBgNV
4
+ BAoMBUJyYXZlMQ0wCwYDVQQLDARDb3JlMQ0wCwYDVQQDDARXYW5nMB4XDTI1MTIw
5
+ NTAwNDcyNloXDTM1MTIwMzAwNDcyNlowVjELMAkGA1UEBhMCQ04xCzAJBgNVBAgM
6
+ AkhiMQwwCgYDVQQHDANTWkoxDjAMBgNVBAoMBUJyYXZlMQ0wCwYDVQQLDARDb3Jl
7
+ MQ0wCwYDVQQDDARXYW5nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBgZDvrQE
8
+ NCxqkxlAugcozIZUGN2okUCZ0Ff8i3O2IKjhT2I4EhYO6V+OqjorUw6rba8NUPuz
9
+ gaazoj7QJH2lcKMhMB8wHQYDVR0OBBYEFLm3o3RWP/LNQIRNLrxIV2sWyo+9MAoG
10
+ CCqGSM49BAMCA0gAMEUCIQDtequ0KVuO0jGUIipEnob39qRrvbN2ivnJngPl7Phn
11
+ ngIgKKc7BiPvfVGszW364NoAX+dfvP7vgv4LkVb5oZpbw7A=
12
+ -----END CERTIFICATE-----
@@ -0,0 +1,5 @@
1
+ -----BEGIN EC PRIVATE KEY-----
2
+ MHcCAQEEICWpohhKOazU0ISyQVB8NRfdIVrIJQSiuojuXoqH3ZuYoAoGCCqGSM49
3
+ AwEHoUQDQgAEBgZDvrQENCxqkxlAugcozIZUGN2okUCZ0Ff8i3O2IKjhT2I4EhYO
4
+ 6V+OqjorUw6rba8NUPuzgaazoj7QJH2lcA==
5
+ -----END EC PRIVATE KEY-----
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+
3
+ NAME='localhost'
4
+
5
+ if [ $# -gt 0 ] ; then
6
+ NAME=$1
7
+ fi
8
+
9
+ # 当前openssl无法生成基于SM2的ECC证书,会提示无法读取私钥错误
10
+
11
+ #生成私钥
12
+ #openssl ecparam -genkey -name prime256v1 -out "$NAME.key"
13
+
14
+ #若要基于私钥生成公钥请执行
15
+ #openssl ec -in "$NAME.key" -pubout -out "$NAME.pub"
16
+
17
+ openssl ecparam -genkey -name prime256v1 | openssl ec -out "$NAME.key"
18
+
19
+ #生成证书请求文件
20
+ #openssl req -new -sha256 -out "$NAME.req" -key "$NAME.key"
21
+ openssl req -new -out "$NAME.req" -key "$NAME.key"
22
+
23
+ openssl x509 -req -in "$NAME.req" -out "$NAME.cert" -signkey "$NAME.key" -days 3650
24
+
package/demo/sni.js ADDED
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ const topbit = require('../src/topbit.js');
4
+ const fs = require('fs');
5
+ const tls = require('tls');
6
+
7
+ let certs = {
8
+ 'x.com' : {
9
+ cert : fs.readFileSync('./cert/x.com.cert'),
10
+ key : fs.readFileSync('./cert/x.com.key')
11
+ },
12
+
13
+ 'api.x.com' : {
14
+ cert : fs.readFileSync('./cert/api.x.com.cert'),
15
+ key : fs.readFileSync('./cert/api.x.com.key')
16
+ }
17
+ }
18
+
19
+ let app = new topbit({
20
+ debug: true,
21
+ loadMonitor: false,
22
+ http2: true,
23
+ https: true,
24
+ server : {
25
+ SNICallback : (servername, cb) => {
26
+ return cb(null, tls.createSecureContext(certs[servername]));
27
+ }
28
+ },
29
+ pidFile: '/tmp/mymaster.pid'
30
+ });
31
+
32
+
33
+ app.use(async (c, next) => {
34
+ if (!c.getFile('image')) {
35
+ return c.status().oo('image not found');
36
+ }
37
+ await next(c);
38
+ }, {method:'POST', group: 'upload'});
39
+
40
+ app.get('/', async c => {
41
+ c.oo('ok');
42
+ })
43
+
44
+ app.post('/p', async c => {
45
+ c.ok(c.body);
46
+ });
47
+
48
+ app.post('/upload', async c => {
49
+ try {
50
+ c.res.body = await c.moveFile(c.getFile('image'), {
51
+ path: process.env.HOME + '/tmp/buffer'
52
+ });
53
+ } catch (err) {
54
+ c.res.body = err.message;
55
+ }
56
+ }, '@upload');
57
+
58
+ app.daemon(1990, 2);
59
+
package/demo/static.js ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ process.chdir(__dirname)
4
+
5
+ let Topbit = require('../src/topbit.js')
6
+ let {Resource} = Topbit.extensions
7
+
8
+ let app = new Topbit({
9
+ debug: true,
10
+ loadInfoFile: '--mem',
11
+ globalLog: true,
12
+ logType: 'stdio'
13
+ })
14
+
15
+ if (app.isWorker) {
16
+ app.get('/', async ctx => {
17
+ ctx.ok('ok')
18
+ })
19
+
20
+ let rse = new Resource({
21
+ staticPath: './',
22
+ routePath: '/static/*'
23
+ })
24
+
25
+ rse.init(app)
26
+ }
27
+
28
+ app.sched('none')
29
+
30
+ app.autoWorker(3)
31
+
32
+ app.daemon(1234, 1)
Binary file
package/images/topbit.png CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topbit",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A Server-side web framework support http/1.1 and http/2",
5
5
  "main": "src/topbit.js",
6
6
  "directories": {
@@ -289,6 +289,10 @@ class Resource {
289
289
  }
290
290
  }
291
291
 
292
+ if (real_path.indexOf('/../') >= 0) {
293
+ return c.status(404).to('file not found')
294
+ }
295
+
292
296
  let pathfile = `${self.staticPath}${self.prepath}${real_path}`
293
297
 
294
298
  if (self.cache.has(real_path)) {
package/src/sendmsg.js CHANGED
@@ -13,15 +13,15 @@ module.exports = (type, msg, options = {autoExit: false}) => {
13
13
  process.send({
14
14
  type: type,
15
15
  message: msg
16
- });
16
+ })
17
17
  }
18
18
 
19
19
  if (options.autoExit) {
20
- process.exit(options.exitCode || 0);
20
+ process.exit(options.exitCode || 0)
21
21
  }
22
22
 
23
23
  } catch (err) {
24
24
 
25
25
  }
26
26
 
27
- };
27
+ }
Binary file