Question: Restrictions: For this exercise you must use an Express - server. You cannot use Express' static middleware or any other third - party middleware. Create

Restrictions: For this exercise you must use an Express-server. You cannot use Express' static
middleware or any other third-party middleware.
Create a server that answers to calls to any url of the form /public/somefile.ext (where somefile.ext is
a filename put in by the user, for example the regularly used "deer.jpg") by either:
If the requested url is for a jpg: Send an image to the browser from a folder "./public"
In all other cases: Triggers a download at the browser so that the requested file from the
"./public"-folder can be saved to the user's system.
You are asked to do this in two different ways. First: Deliberately not use the root option of
res.sendFile and res.download. Second: By using the root option. For both cases try to download the
actual JS-file that contains the code of your server by moving outside of the "./public" folder!
Provide the URL-string that makes this possible (when not using the root-option in your code) as a
comment.
Hint: To trick your server to go outside the "./public" folder you need to lookup how some special
characters are URL-encoded, particularly useful will be the encodings for the dot "." and the slash
"/".
Restrictions: For this exercise you must use an

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!