@@ -13,8 +13,10 @@ const util = require('util')
1313
1414const PHP_CGI = shell . which ( 'php-cgi' ) ;
1515
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 )
1820
1921 fs . stat ( file , function ( err , stat ) {
2022 // File does not exist
@@ -23,14 +25,14 @@ function find_file(url, php_dir, callback) {
2325 file = path . join ( file , 'index.php' ) ;
2426 }
2527 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 ) ;
2931 } ) ;
3032 } 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 ) ;
3436 } ) ;
3537 }
3638 }
@@ -171,8 +173,9 @@ function run_php(req, response, next, url, file, exe_config) {
171173 if ( / .* ?\. p h p $ / . test ( path . join ( __dirname , file ) ) ) {
172174 var res = '' , err = '' ;
173175 var php ;
174-
176+ console . log ( exe_config )
175177 if ( ! ! exe_config . cgi_path && exe_config . cgi_path !== '' ) {
178+
176179 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 ) ) ;
177180
178181 php = child . spawn (
@@ -246,24 +249,26 @@ function run_php(req, response, next, url, file, exe_config) {
246249 response . end ( ) ;
247250 } ) ;
248251 } else {
249- response . sendFile ( file ) ;
252+ response . sendFile ( req . url ) ;
250253 }
251254}
252255
253- exports . cgi = function ( php_root , exe_config ) {
256+ exports . cgi = function ( www_root , exe_config ) {
254257 return function ( req , res , next ) {
255258
256259 // stop stream until child-process is opened
257260 req . pause ( ) ;
261+ console . log ( "url" , req . url )
258262 var url = URL . parse ( req . url ) ;
259263
260- file = find_file ( url , php_root , function ( file ) {
264+ file = find_file ( url , www_root , function ( file ) {
265+ console . log ( exe_config )
261266 if ( file ) {
262267 // console.log("find_file call", exe_config.php_cgi_path, file);
263268 run_php ( req , res , next , url , file , exe_config ) ;
264269 } else {
265270 next ( ) ;
266271 }
267- } )
268- } ;
272+ } . bind ( exe_config ) )
273+ } . bind ( exe_config ) ;
269274} ;
0 commit comments