sptc 0.0.35 → 0.0.36

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/bin/sptc.js CHANGED
@@ -1,15 +1,15 @@
1
- #!/usr/bin/env node
2
-
3
- const {NodeCGI}=require('../dist/httpServer')
4
- const {Command}=require('commander')
5
- const version=require('../package.json').version
6
- const program=new Command()
7
- .name(`sptc`)
8
- .description(`sptc`)
9
- .version(version)
10
- .arguments('<filename>', 'Sptc filename.')
11
- .option('-d, --defines <string>', 'Macro definition switches. Separate multiple switches with a comma.', '')
12
- .action((filename, {defines})=>{
13
- NodeCGI(filename, defines)
14
- })
15
- .parse()
1
+ #!/usr/bin/env node
2
+
3
+ const {NodeCGI}=require('../dist/httpServer')
4
+ const {Command}=require('commander')
5
+ const version=require('../package.json').version
6
+ const program=new Command()
7
+ .name(`sptc`)
8
+ .description(`sptc`)
9
+ .version(version)
10
+ .arguments('<filename>', 'Sptc filename.')
11
+ .option('-d, --defines <string>', 'Macro definition switches. Separate multiple switches with a comma.', '')
12
+ .action((filename, {defines})=>{
13
+ NodeCGI(filename, defines)
14
+ })
15
+ .parse()
package/bin/sptcd.js CHANGED
@@ -1,78 +1,78 @@
1
- #!/usr/bin/env node
2
-
3
- const {FastCGI, FastCGI_FPM}=require('../dist/httpServer')
4
- const {Command}=require('commander')
5
- const version=require('../package.json').version
6
- const program=new Command()
7
- .name(`sptc http server`)
8
- .description(`A simple HTTP server`)
9
- .version(version)
10
- .requiredOption('-p, --port <number>', 'The port to serve on.', 9090)
11
- .option('-l, --locally', 'Only accepts local connections.')
12
- .option('-w, --workdir <string>', 'Specifies the working directory.', '.')
13
- .option('-r, --router <string>', 'Specifies a file to use as a router entry. If specified, all requests will be routed to this file.')
14
- .option('-e, --exts <string>', 'Specifies the valid extensions for executable SPTC files.', '.s, .sjs, .sptc')
15
- .option('-n, --workers <number>', 'The number of worker processes.', 1)
16
- .option('-s, --silent', 'Enables silent mode.')
17
- .option('-t, --traverse', 'If the pathname is a directory, executes the index file under the pathname directory if one exists. If no index file is found, traverses the directory. This option is ignored if a router file is specified.')
18
- .option('-d, --debug', 'Enables debug mode.')
19
- .action(({
20
- port,
21
- locally,
22
- workdir,
23
- router,
24
- exts,
25
- workers,
26
- slient,
27
- traverse,
28
- debug,
29
- })=>{
30
- const disableLog=slient || require('cluster').isWorker
31
-
32
- if(router && traverse) {
33
- traverse=false
34
- if(!disableLog) {
35
- console.log('`--traverse` option has been ignored due to the router file has been specified.')
36
- }
37
- }
38
-
39
- const argv=[port, locally, {
40
- serverDir: workdir,
41
- routerEntry: router,
42
- exts: exts.split(',').map(x=>{
43
- const r=x.trim()
44
- return r.indexOf('.')===0? r: '.'+r
45
- }).filter(x=>x),
46
- debug,
47
- traverse,
48
- }]
49
-
50
- if(workers>1) {
51
- FastCGI_FPM(workers, ...argv)
52
- }else{
53
- FastCGI(...argv)
54
- }
55
-
56
- if(disableLog) return;
57
- const {getLocalIpv4Addresses}=require('../utils')
58
- console.log('`sptc-http-server` has been launched with the following option:')
59
- const o={
60
- debug,
61
- workdir,
62
- routerEntry: router || null,
63
- }
64
- o.traverse=traverse? true: false
65
- if(locally) {
66
- o.serve='127.0.0.1:'+port
67
- }else{
68
- o.serves=getLocalIpv4Addresses().map(x=>x+':'+port)
69
- }
70
- o.runtime=workers>1? 'FastCGI_FPM': 'FastCGI'
71
- if(workers>1) {
72
- o.workers=workers
73
- }
74
- console.log(o)
75
-
76
-
77
- })
78
- .parse()
1
+ #!/usr/bin/env node
2
+
3
+ const {FastCGI, FastCGI_FPM}=require('../dist/httpServer')
4
+ const {Command}=require('commander')
5
+ const version=require('../package.json').version
6
+ const program=new Command()
7
+ .name(`sptc http server`)
8
+ .description(`A simple HTTP server`)
9
+ .version(version)
10
+ .requiredOption('-p, --port <number>', 'The port to serve on.', 9090)
11
+ .option('-l, --locally', 'Only accepts local connections.')
12
+ .option('-w, --workdir <string>', 'Specifies the working directory.', '.')
13
+ .option('-r, --router <string>', 'Specifies a file to use as a router entry. If specified, all requests will be routed to this file.')
14
+ .option('-e, --exts <string>', 'Specifies the valid extensions for executable SPTC files.', '.s, .sjs, .sptc')
15
+ .option('-n, --workers <number>', 'The number of worker processes.', 1)
16
+ .option('-s, --silent', 'Enables silent mode.')
17
+ .option('-t, --traverse', 'If the pathname is a directory, executes the index file under the pathname directory if one exists. If no index file is found, traverses the directory. This option is ignored if a router file is specified.')
18
+ .option('-d, --debug', 'Enables debug mode.')
19
+ .action(({
20
+ port,
21
+ locally,
22
+ workdir,
23
+ router,
24
+ exts,
25
+ workers,
26
+ slient,
27
+ traverse,
28
+ debug,
29
+ })=>{
30
+ const disableLog=slient || require('cluster').isWorker
31
+
32
+ if(router && traverse) {
33
+ traverse=false
34
+ if(!disableLog) {
35
+ console.log('`--traverse` option has been ignored due to the router file has been specified.')
36
+ }
37
+ }
38
+
39
+ const argv=[port, locally, {
40
+ serverDir: workdir,
41
+ routerEntry: router,
42
+ exts: exts.split(',').map(x=>{
43
+ const r=x.trim()
44
+ return r.indexOf('.')===0? r: '.'+r
45
+ }).filter(x=>x),
46
+ debug,
47
+ traverse,
48
+ }]
49
+
50
+ if(workers>1) {
51
+ FastCGI_FPM(workers, ...argv)
52
+ }else{
53
+ FastCGI(...argv)
54
+ }
55
+
56
+ if(disableLog) return;
57
+ const {getLocalIpv4Addresses}=require('../utils')
58
+ console.log('`sptc-http-server` has been launched with the following option:')
59
+ const o={
60
+ debug,
61
+ workdir,
62
+ routerEntry: router || null,
63
+ }
64
+ o.traverse=traverse? true: false
65
+ if(locally) {
66
+ o.serve='127.0.0.1:'+port
67
+ }else{
68
+ o.serves=getLocalIpv4Addresses().map(x=>x+':'+port)
69
+ }
70
+ o.runtime=workers>1? 'FastCGI_FPM': 'FastCGI'
71
+ if(workers>1) {
72
+ o.workers=workers
73
+ }
74
+ console.log(o)
75
+
76
+
77
+ })
78
+ .parse()
@@ -80,16 +80,6 @@ function buildGlobal() {
80
80
  return ctx
81
81
  }
82
82
 
83
- let _patched=false
84
- function securityPatch() {
85
- if(_patched) return;
86
- _patched=true
87
- const sfunc=(new vm.Script(`(_=>null).constructor`)).runInNewContext({})
88
- parseInt.constructor.prototype.constructor=sfunc
89
- global.Function=sfunc
90
- global.global=buildGlobal()
91
- }
92
-
93
83
  const NOOP=_=>null
94
84
  const Application={}
95
85
  function buildContext(ctx0, option) {
@@ -273,12 +263,13 @@ function buildContext(ctx0, option) {
273
263
  return priv.__autoload_vars[prop]=ctx.include(inc_fn)[prop]
274
264
  }
275
265
  }
266
+ if(global[prop]) return global[prop]
276
267
  }
277
268
  return Reflect.get(target, prop, receiver)
278
269
  },
279
270
  })
280
271
 
281
- return [{...pctx}, priv]
272
+ return [pctx, priv]
282
273
  }
283
274
 
284
275
  function toWritable(x) {
@@ -332,5 +323,4 @@ function executeVm(vm, ctx, priv) {
332
323
  module.exports={
333
324
  buildContext,
334
325
  executeVm,
335
- securityPatch,
336
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sptc",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Simple Pretreat Toolkit CLI",
5
5
  "main": "engine/index.js",
6
6
  "engines": {