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 Expressserver. You cannot use Express' static
middleware or any other thirdparty middleware.
Create a server that answers to calls to any url of the form publicsomefileext 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
publicfolder 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 JSfile that contains the code of your server by moving outside of the public folder!
Provide the URLstring that makes this possible when not using the rootoption 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 URLencoded, particularly useful will be the encodings for the dot and the slash
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
