sptc 0.0.35 → 0.0.37
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 +15 -15
- package/bin/sptcd.js +78 -78
- package/engine/interpreter.js +14 -13
- package/package.json +1 -1
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()
|
package/engine/interpreter.js
CHANGED
|
@@ -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) {
|
|
@@ -246,9 +236,20 @@ function buildContext(ctx0, option) {
|
|
|
246
236
|
const jsvm=Utils.compileFile(inc, {
|
|
247
237
|
compileFunc: code=>new vm.Script(code+'; Symbol()[0]=_=>0', inc)
|
|
248
238
|
})
|
|
239
|
+
|
|
240
|
+
/*
|
|
249
241
|
const jsctx={
|
|
250
242
|
...inc_payload,
|
|
251
|
-
}
|
|
243
|
+
}*/
|
|
244
|
+
|
|
245
|
+
const [jsctx]=buildContext({
|
|
246
|
+
...ctx0,
|
|
247
|
+
...inc_payload,
|
|
248
|
+
}, {
|
|
249
|
+
isEntry: false,
|
|
250
|
+
masterPriv: priv,
|
|
251
|
+
})
|
|
252
|
+
|
|
252
253
|
jsvm.runInNewContext(jsctx)
|
|
253
254
|
return jsctx
|
|
254
255
|
}
|
|
@@ -273,12 +274,13 @@ function buildContext(ctx0, option) {
|
|
|
273
274
|
return priv.__autoload_vars[prop]=ctx.include(inc_fn)[prop]
|
|
274
275
|
}
|
|
275
276
|
}
|
|
277
|
+
if(global[prop]) return global[prop]
|
|
276
278
|
}
|
|
277
279
|
return Reflect.get(target, prop, receiver)
|
|
278
280
|
},
|
|
279
281
|
})
|
|
280
282
|
|
|
281
|
-
return [
|
|
283
|
+
return [pctx, priv]
|
|
282
284
|
}
|
|
283
285
|
|
|
284
286
|
function toWritable(x) {
|
|
@@ -332,5 +334,4 @@ function executeVm(vm, ctx, priv) {
|
|
|
332
334
|
module.exports={
|
|
333
335
|
buildContext,
|
|
334
336
|
executeVm,
|
|
335
|
-
securityPatch,
|
|
336
337
|
}
|