Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Create a folder in your repository named static to store the files for this assignment. Inside the static folder create another folder named public

Instructions

Create a folder in your repository named static to store the files for this assignment. Inside the static folder create another folder named public to hold the files that will be made available to browsers on the public Internet.

Use npm to install the st module.

npm install st 

The following code shows one way to use the st module to serve requests for files.

const http = require('http'); const st = require('st'); const port = 8000; var mount = st({ path: 'public/', index: 'index.html' }); const server = http.createServer((req, res) => { mount(req, res); }); server.listen(port, () => { console.log(`Server running at http://localhost:${port}/`); }); 

Place the above code in a file named server.js.

Add content to the public folder and go to http://localhost:8000/ to test that the server is working correctly. In particular, create index.html and see that this file is served for the following 2 different URLs. This is accomplished by including index: 'index.html' in the configuration object.

http://localhost:8000/ http://localhost:8000/index.html 

problem 1

Include an img element in one of your pages that refers to an image file in the public folder.

Use an external style sheet to style the web pages.

Test that browsers load and render the Web page as expected.

problem 2

Intercept requests for the path /hi and return the following html instead of letting st handle the request.

You requested /hi.

The url property of the req object passed into your request handler provides the path requested by the user. You can use this in an if statement as follows.

if (req.url === '/hi') { // ... } 

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

8. What are the costs of collecting the information?

Answered: 1 week ago

Question

Create a decision tree for Problem 12.

Answered: 1 week ago

Question

U11 Informing Industry: Publicizing Contract Actions 317

Answered: 1 week ago