sptc 0.0.34 → 0.0.35

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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const {executeSptcFile}=require('../engine')
3
+ const {NodeCGI}=require('../dist/httpServer')
4
4
  const {Command}=require('commander')
5
5
  const version=require('../package.json').version
6
6
  const program=new Command()
@@ -9,16 +9,7 @@ const program=new Command()
9
9
  .version(version)
10
10
  .arguments('<filename>', 'Sptc filename.')
11
11
  .option('-d, --defines <string>', 'Macro definition switches. Separate multiple switches with a comma.', '')
12
- .action((filename, {
13
- defines,
14
- })=>{
15
- executeSptcFile(filename, {}, {
16
- write: x=>process.stdout.write(x),
17
- onError: e=>console.log(e),
18
- __DEV__: true,
19
- macroOption: {
20
- defs: defines.split(',').map(x=>x.trim()).filter(x=>x),
21
- },
22
- })
12
+ .action((filename, {defines})=>{
13
+ NodeCGI(filename, defines)
23
14
  })
24
15
  .parse()
@@ -92,6 +92,28 @@ function CGI(req, res, option) {
92
92
 
93
93
  }
94
94
 
95
+ function NodeCGI(filename, defines) {
96
+ const [reqCtx]=buildRequestContext({
97
+ url: filename,
98
+ headers: {},
99
+ }, null, {
100
+ srvDir: __dirname,
101
+ debug: true,
102
+ env: {
103
+ RUNTIME: 'NodeCGI',
104
+ },
105
+ isRouterMode: true,
106
+ })
107
+ executeSptcFile(reqCtx.$_REQUEST_FILE.pathname, reqCtx, {
108
+ write: x=>process.stdout.write(x),
109
+ onError: e=>console.log(e),
110
+ __DEV__: true,
111
+ macroOption: {
112
+ defs: defines.split(',').map(x=>x.trim()).filter(x=>x),
113
+ },
114
+ })
115
+ }
116
+
95
117
  function buildRequestContext(req, res, {srvDir, debug, env, isRouterMode}) {
96
118
  const {fullname, pathname, query}=getRequestFile(req, srvDir)
97
119
  const reqCtx={
@@ -246,4 +268,5 @@ function traverseDirectory(ref, dir, exts, debug) {
246
268
  module.exports={
247
269
  FastCGI,
248
270
  FastCGI_FPM,
271
+ NodeCGI,
249
272
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sptc",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "Simple Pretreat Toolkit CLI",
5
5
  "main": "engine/index.js",
6
6
  "engines": {