@@ -13,8 +13,10 @@ const util = require('util')
13
13
14
14
const PHP_CGI = shell . which ( 'php-cgi' ) ;
15
15
16
- function find_file ( url , php_dir , callback ) {
17
- var file = path . join ( php_dir , url . pathname ) ;
16
+ function find_file ( url , www_root , callback ) {
17
+ var file = "" ;
18
+ file = path . join ( www_root , url . pathname ) ;
19
+ console . log ( "file" , file )
18
20
19
21
fs . stat ( file , function ( err , stat ) {
20
22
// File does not exist
@@ -23,14 +25,14 @@ function find_file(url, php_dir, callback) {
23
25
file = path . join ( file , 'index.php' ) ;
24
26
}
25
27
if ( file . includes ( __dirname ) ) {
26
- fs . exists ( file , function ( exists ) {
27
- console . log ( "File path exists:" , file , exists )
28
- callback ( exists && file ) ;
28
+ fs . stat ( file , function ( error ) {
29
+ console . log ( "File path exists:" , file , error )
30
+ callback ( file ) ;
29
31
} ) ;
30
32
} else {
31
- fs . exists ( path . join ( __dirname , file ) , function ( exists ) {
32
- console . log ( "No file path exists:" , file , exists )
33
- callback ( exists && file ) ;
33
+ fs . stat ( path . join ( __dirname , file ) , function ( error ) {
34
+ console . log ( "No file path exists:" , file , error )
35
+ callback ( file ) ;
34
36
} ) ;
35
37
}
36
38
}
@@ -171,8 +173,9 @@ function run_php(req, response, next, url, file, exe_config) {
171
173
if ( / .* ?\. p h p $ / . test ( path . join ( __dirname , file ) ) ) {
172
174
var res = '' , err = '' ;
173
175
var php ;
174
-
176
+ console . log ( exe_config )
175
177
if ( ! ! exe_config . cgi_path && exe_config . cgi_path !== '' ) {
178
+
176
179
console . log ( ( exe_config . cgi_path . lastIndexOf ( "/" ) == exe_config . cgi_path . length - 1 ? exe_config . cgi_path : exe_config . cgi_path + "/" ) + "php-cgi" + strOptions ( exe_config . options ) ) ;
177
180
178
181
php = child . spawn (
@@ -246,24 +249,26 @@ function run_php(req, response, next, url, file, exe_config) {
246
249
response . end ( ) ;
247
250
} ) ;
248
251
} else {
249
- response . sendFile ( file ) ;
252
+ response . sendFile ( req . url ) ;
250
253
}
251
254
}
252
255
253
- exports . cgi = function ( php_root , exe_config ) {
256
+ exports . cgi = function ( www_root , exe_config ) {
254
257
return function ( req , res , next ) {
255
258
256
259
// stop stream until child-process is opened
257
260
req . pause ( ) ;
261
+ console . log ( "url" , req . url )
258
262
var url = URL . parse ( req . url ) ;
259
263
260
- file = find_file ( url , php_root , function ( file ) {
264
+ file = find_file ( url , www_root , function ( file ) {
265
+ console . log ( exe_config )
261
266
if ( file ) {
262
267
// console.log("find_file call", exe_config.php_cgi_path, file);
263
268
run_php ( req , res , next , url , file , exe_config ) ;
264
269
} else {
265
270
next ( ) ;
266
271
}
267
- } )
268
- } ;
272
+ } . bind ( exe_config ) )
273
+ } . bind ( exe_config ) ;
269
274
} ;
0 commit comments