33/**
44 * Copyright (c) 2016 Fabio Massaioli and other contributors
55 *
6- * Code from Node http module:
7- * Copyright Joyent, Inc. and other Node contributors
8- *
96 * Permission is hereby granted, free of charge, to any person obtaining a copy of
107 * this software and associated documentation files (the "Software"), to deal in
118 * the Software without restriction, including without limitation the rights to
@@ -30,55 +27,51 @@ var fcgi = require('../index.js'),
3027 fs = require ( 'fs' ) ,
3128 util = require ( 'util' ) ;
3229
33- var count = 0 ;
34-
35- function s ( obj ) {
36- return util . inspect ( obj ) ;
30+ function log ( msg ) {
31+ fs . appendFileSync ( 'fileServer.log' , msg ) ;
3732}
3833
3934fcgi . createServer ( function ( req , res ) {
40- count += 1 ;
41-
42- req . on ( 'complete' , function ( ) {
43- var path = req . url . slice ( 1 ) ;
44- fs . stat ( path , function ( err , stat ) {
45- if ( err ) {
46- res . writeHead ( 500 , {
47- 'Content-Type' : 'text/plain; charset=utf-8' ,
48- 'Content-Length' : err . stack . length
49- } ) ;
50- res . end ( err . stack + '\n' ) ;
51- } else {
52- var stream = fs . createReadStream ( path ) ;
53- res . writeHead ( 200 , {
54- 'Content-Type' : 'application/octet-stream' ,
55- 'Content-Length' : stat . size
56- } ) ;
57- stream . pipe ( res ) ;
58- }
59- } ) ;
35+ var path = req . url . slice ( 1 ) ;
36+ fs . stat ( path , function ( err , stat ) {
37+ if ( err ) {
38+ res . writeHead ( 500 , {
39+ 'Content-Type' : 'text/plain; charset=utf-8' ,
40+ 'Content-Length' : err . stack . length
41+ } ) ;
42+ res . end ( err . stack + '\n' ) ;
43+ } else {
44+ var stream = fs . createReadStream ( path ) ;
45+ res . writeHead ( 200 , {
46+ 'Content-Type' : 'application/octet-stream' ,
47+ 'Content-Length' : stat . size
48+ } ) ;
49+ stream . pipe ( res ) ;
50+ }
6051 } ) ;
61- } ) . listen ( ) ;
52+ } ) . listen ( function ( ) {
53+ log ( 'Listening\n' ) ;
54+ } ) ;
6255
6356process . on ( 'uncaughtException' , function ( err ) {
64- fs . appendFileSync ( 'test. log' , err . stack + '\n\n' ) ;
57+ log ( err . stack + '\n\n' ) ;
6558 process . exit ( 1 ) ;
6659} ) ;
6760
6861process . on ( 'exit' , function ( ) {
69- fs . appendFileSync ( 'test. log' , 'Exit - Uptime:' + process . uptime ( ) + '\n\n' ) ;
62+ log ( 'Exit - Uptime:' + process . uptime ( ) + '\n\n' ) ;
7063} ) ;
7164
7265process . on ( 'SIGTERM' , function ( ) {
73- fs . appendFileSync ( 'test. log' , 'SIGTERM\n' ) ;
66+ log ( 'SIGTERM\n' ) ;
7467 process . exit ( 0 ) ;
7568} ) ;
7669
7770process . on ( 'SIGINT' , function ( ) {
78- fs . appendFileSync ( 'test. log' , 'SIGINT\n' ) ;
71+ log ( 'SIGINT\n' ) ;
7972 process . exit ( 0 ) ;
8073} ) ;
8174
8275process . on ( 'SIGUSR1' , function ( ) {
83- fs . appendFileSync ( 'test. log' , 'SIGUSR1\n' ) ;
76+ log ( 'SIGUSR1\n' ) ;
8477} ) ;
0 commit comments