Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** app.js This is a simple web site that hosts a fake Wake Tech Credit Union web site. It uses the third-party module: connect version

/** app.js This is a simple web site that hosts a fake Wake Tech Credit Union web site. It uses the third-party module: connect version 3.4.1. and serve-static version 1.11.1 For detailed information on connect module visit its official NPM web site at: https://www.npmjs.com/package/connect */ var connect = require('connect'); var http = require('http'); var serveStatic = require('serve-static'); var util = require('util'); // Create an app var app = connect(); // Create a middleware that serves static web pages using third-party module: static-serve var staticMiddleware = serveStatic('public', {index:['index.html', 'index.htm']}); // Create a custom access log middleware to the console function logit(req, res, next) { util.log(util.format('Request received: %s, %s', req.method, req.url)); next(); } // Mount all the middlewares app.use(logit).use(staticMiddleware).listen(3333); console.log('static web server started on port 3333'); Your job is to modify app.js file in this project so that your Node.js web server will log all client access requests to a text file called access.log. The format of the log file is: datetime | user-agent | browser language | original url requested Here are some sample log entries from access.log file: Mon Jul 18 2016 15:46:24 GMT-0400 (Eastern Daylight Time)|Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36|en-US,en;q=0.8,es;q=0.6|/ Mon Jul 18 2016 15:47:12 GMT-0400 (Eastern Daylight Time)|Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko|en-US,es;q=0.8,zh-CN;q=0.5,en;q=0.3|/images/career.jpg Mon Jul 18 2016 15:46:47 GMT-0400 (Eastern Daylight Time)|Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0|en-US,en;q=0.5|/css/interface.css The above entries show three access attempts to our web site. The first one is from a Chrome browser which accepts only en-US and en languages. The requested URL is /. The second one is from an IE browser which accepts en-US, es, and zh-CN languages. The requested URL is /images/career.jps. The last one is from a FireFox browser which accepts en-US and en languages. The requested URL is /css/interface.css. We can write a small program to analyze this log file and show the daily hits of each page of our web site. We can also tally the most popular browsers used to access our web site. You need to submit only the modified app.js file. Hint: You need to require the fs module and create a file write stream to write the log to access.log. Example: var ws = fs.createWriteStream(access.log, {flags: a}); //append You can re-use the existing custom middleware called logit or create a new one. You can get user agent, browser language and requested URL by doing this: var reqHeader = req.headers; var userAgent = reqHeader[user-agent]; var browserLanguage = reqHeader[accept-language]; var requestedUrl = req.originalUrl; Note: It will be beneficial for you to study the official documentation of connect and serve-static module: https://www.npmjs.com/package/connect https://www.npmjs.com/package/serve-static Pls send me answer as soon as possible. if you have any question, pls late me know. don't put any kind of answer because i post same question three times.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

5. Have you any experience with agile software development?

Answered: 1 week ago