UNPKG

2.13 kBJavaScriptView Raw
1function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=e(require("@36node/whisper")),o=e(require("only")),t=e(require("pino")),r=e(require("dotenv")),i=function(e){var n=e.body;this.header=e.header,this.body=n};i.prototype.toJSON=function(){return o(this,["header","body"])};var s=function(e){var n=e.month,o=e.date,t=e.hour,r=e.minute,i=e.second;this.month=0,this.date=1,this.hour=0,this.minute=0,this.second=0,this.month=n,this.date=o,this.hour=t,this.minute=r,this.second=i};s.prototype.toJSON=function(){return o(this,["month","date","hour","minute","second"])};var u=function(){};function h(e,n){var o=process.env[e.toUpperCase()]||process.env[e]||n;if(void 0===o)throw new Error("environment "+e+" is missing");return o}u.prototype.parse=function(e){if(10!==e.length)throw new Error("package length wrong");if(35!==e[0]&&35!==e[1])throw new Error("pcakge should start with ##");if(35!==e[8]&&35!==e[9])throw new Error("pcakge should end with ##");return{header:{command:e[2]},body:{month:e[3],date:e[4],hour:e[5],minute:e[6],second:e[7]}}},u.prototype.build=function(e){return"time: "+e.month+"-"+e.date+"-"+e.hour+"-"+e.minute+"-"+e.second},r.config();var d=h("NODE_ENV","development"),c=h("PORT",9527),a=h("LOG_LEVEL","info"),f={env:h,NODE_ENV:d,PORT:c,LOG_LEVEL:a},p=t({level:a,base:null}),m=new n,v=new u;m.use(function(e,n){try{var o=Date.now();return Promise.resolve(n()).then(function(){var n=Date.now();p.info(e.data),p.info("request: "),p.info(e.req),p.info("response: "),p.info(e.res),p.info("session "+e.session.id+": seq "+e.no+" success "+(n-o)+" ms")})}catch(e){return Promise.reject(e)}}),m.use(function(e,n){try{var o=v.parse(e.data);return e.req=new i(o),Promise.resolve(n()).then(function(){e.res=new s(o.body),e.send(v.build(e.res))})}catch(e){return Promise.reject(e)}}),m.on("close",function(e){p.info("session "+e.id+": closed")}),m.on("timeout",function(e){p.info("session "+e.id+": timeout")}),m.on("end",function(e){p.info("session "+e.id+": end")}),m.on("error",function(e){p.info("session "+e.id+": error")}),exports.app=m,exports.config=f;
2//# sourceMappingURL=index.js.map