Practice exercises CHAPTER 8 385
- If you see a pop-up prompt stating that Windows Firewall has blocked some features,
as shown in Figure 8-13, make sure both check boxes are selected and click the Allow
Access button to continue.
FIGURE 8-13 Accepting both options when prompted
- After starting the website, open the web browser and type http://localhost:8080 to
see the Contoso home page.
Be sure to clear the cache for the page by pressing Ctrl+F5. You should see the
Contoso home page and be able to click the link for the ContactUs page to see that
page. - Modify the index.js file so that a POST to /ContactMessage returns a thank you mes-
sage to the customer and logs a small message to the console window as follows.
app.post('/ContactMessage', function (request, response) {
var form = new formidable.IncomingForm();
form.parse(request, function (err, fields) {
var lastName = fields.lastName,
firstName = fields.firstName,
email = fields.email,
message = fields.message;
response.writeHead(200, { 'Content-Type': 'text/html' });
response.write('Thank you, ' + firstName + ' ' + lastName + '<br/>');
response.write('We will contact you at ' + email + '<br/>');
response.end('Your message: ' + message + '<br />');
console.log('Handled request for ' + firstName + ' ' + lastName);
});
});
- In Visual Studio, open the ContactUs.html page and change the