Before that, our project was running on Windows, and today we're going to run our program on the Linxu machine. Before looking at Linux deployment, let's look at node. js like an ASP. NET MVC filter or call an interceptor. In App.js we add the following code
var beforerequest = function (Req, res, next) { if (req.originalurl == '/' | | req.originalUrl == '/login ' | | req.originalUrl == '/config ' | | req.originalUrl == '/user ' | | req.originalUrl == '/loginout ') { next (); } else if (session.user == null | | session.user == undefined | | !session.user.userid) { res.redirect ('/login '); } else { Next (); &nbsP; }}app.use (beforerequest);
At this point when a request arrives, it will first determine whether the user is logged in, if not logged in, then jump to the login interface. But make sure that the code is before you register the route.
App.use ('/', routes);
OK, next we are looking at the use of Log4js on the node. JS platform.
var log4js = require (' Log4js '), var log4jsconfig = require ('./framework/config/log4js_config.js '); Log4js.configure ( Log4jsconfig.config);
OK, let's take a look at the configuration of Log4js
exports.config = { appenders: [ { type: ' Console ', category: "Console" }, { type: ' file ', filename : ' Logs/info.log ', Maxlogsize: 1024, backups: 1, category: ' Log_info ' }, { type: "Datefile", filename: "Logs/error", alwaysIncludePattern: true, pattern: "-yyyy-mm-dd-hh.log", category: "Log_error" }, { category: "Log_ Trace ", type: " Datefile ", alwaysincludepattern: true, pattern: "-yyyy-mm-dd-hh.log", filename: "Logs/trace" } ], replaceConsole: true, levels: { console: "All", log_error: " All ", log_info: " all ", log_trace: "All"     }}
OK, after this configuration, let's look at the log of the log.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/ED/wKioL1fO2dKxokvTAAAvNV-X9f8131.png "title=" Qq20160906225912.png "alt=" Wkiol1fo2dkxokvtaaavnv-x9f8131.png "/>
OK, in fact we set the record in App.js.
var loggerinfo = Log4js.getlogger (' log_info '); var loggererror = Log4js.getlogger (' log_error '); var loggertrace = Log4js.getlogger (' Log_trace '); App.use (Log4js.connectlogger (loggerinfo, {format: ': Method:url '});
Three kinds of log,error are defined, 404 and 500 are recorded respectively.
App.use (function (req, res, next) {Loggererror.error (Req.url); var err = new Error (' not Found '); Err.status = 404; Err.message = "The resource" is a look for was not found! "; Next (err);}); App.use (function (err, req, res, next) {Res.status (Err.status | | 500); Loggererror.error (Err.message); Res.render (' error ', {message:err.message, error: {}});
and info is used to record Console.log, set
Replaceconsole:true
The
Allows the contents of the console to be output in the window, instead of just writing the log file.
[2016-08-01 14:17:01.074] [info] log_info - get /user/file?pageindex=0& pagesize=10&isshared=false&filename=[2016-08-01 14:17:02.408] [info] log_info - get /page?q=s[2016-08-01 14:17:02.841] [info] log_info - get / Docshare[2016-08-01 14:17:04.674] [info] log_info - get /user/sharedfile?userid= &pageIndex=0&pageSize=10&fileName=&startDate=&endDate=[2016-08-01 14:17:08.921] [Info] log_info - get /page?q=u[2016-08-01 14:17:11.713] [info] log_info - get /page?q=r[2016-08-01 14:17:11.919] [info] log_info - get / File/auth[2016-08-01 14:17:13.628] [info] log_info - get /user/file?pageindex=0 &pagesize=10&isshared=true&startdate=fri%20jul%2001%202016%2000:00:00%20gmt+0800%20 (й) &endDate =mon%20aug%2001%202016%2014:17:11%20gmt+0800%20 (й) &filename=[2016-08-01 14:17:21.512] [info] log_info - get /page?q=c
And the format is the HTTP Method+url set above
App.use (Log4js.connectlogger (loggerinfo, {format: ': Method:url '));
OK, about Log4js said so much, after all, just a tool, we go down to see the API on the line.
OK, then we'll change the program to Linux my centos5.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/EE/wKiom1fO25bhNU3GAAIUvDHlb3w611.png "title=" Qq20160906230632.png "alt=" Wkiom1fo25bhnu3gaaiuvdhlb3w611.png "/>
Have you noticed that my desktop FTP server 192.168.80.1, yes, I built the FTP server in WIN10. OK, we'll put the node. JS program in FTP and we'll copy it to CentOS.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/EE/wKiom1fO3C-xbP80AAA8uXumXWY200.png "title=" Qq20160906230914.png "alt=" Wkiom1fo3c-xbp80aaa8uxumxwy200.png "/>
OK, we copy all the things we need to use in this way to CentOS.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/EE/wKiom1fO3I-TE9q7AABVsnJ6Ihs116.png "title=" Qq20160906231018.png "alt=" Wkiom1fo3i-te9q7aabvsnj6ihs116.png "/>
What we need is a deployment program, Mongodb,node.js for Linux. Well, when we're done, we'll start MongoDB.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/86/ED/wKioL1fO3U3CpusDAAIDZRbBrpo290.png "title=" Qq20160906231346.png "alt=" Wkiol1fo3u3cpusdaaidzrbbrpo290.png "/>
Then we start the program with the node command.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/ED/wKioL1fO3uzBFP1JAABTqjI1HGA528.png "title=" Qq20160906232044.png "alt=" Wkiol1fo3uzbfp1jaabtqji1hga528.png "/>
Started successfully, we asked in window to ask
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/EE/wKiom1fO3zfzzsVxAACRTj8mmx4498.png "title=" Qq20160906232201.png "alt=" Wkiom1fo3zfzzsvxaacrtj8mmx4498.png "/>
Some people say, you this figure how I know is not the Linux IP. I'll show you two pictures now, one is IP,
One is the CentOS Firefox browser.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/ED/wKioL1fO36yQNvvAAADFX9XmQ3s692.png "title=" Qq20160906232353.png "alt=" Wkiol1fo36yqnvvaaadfx9xmq3s692.png "/>
Let's look at the effects of Firefox under Linux.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/ED/wKioL1fO4QzCbySEAACQerMyrZw780.png "title=" Qq20160906232942.png "alt=" Wkiol1fo4qzcbyseaacqermyrzw780.png "/>
This browser is estimated to be somewhat old and does not support HTML5. Ok finally we log in to see if the system is normal.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/EE/wKiom1fO4V3iebSkAADFO9uDTwI402.png "title=" Qq20160906233117.png "alt=" Wkiom1fo4v3iebskaadfo9udtwi402.png "/>
What's wrong with the wood, OK, it's here today. There will be a lot of playing Linux, what's the. NET core what's the thing we also play.
This article is from the "Technology Creation value" blog, please be sure to keep this source http://leelei.blog.51cto.com/856755/1847040
The Linux deployment of node. JS closest Combat (12)