Serving static files
Static files such as the CSS stylesheet use a catch-all route in the note application:
router.get("*", serveStaticFiles("public/"));
All GET requests that are not previously handled are routed to the serveStaticFiles()
function. This function sends the file to the client if it exists in the local public/
folder. If the file is not found, then the function returns without writing a response. This is done for every request so the number of files and the content of the files may change during the lifetime of your application. You will only need to set up a route for GET requests as the browsers issues only HTTP GET requests for these files, in accordance with the semantic of the HTTP method explained earlier.
The serveStaticFiles()
function itself checks whether the path in the request matches a configured prefix. The default value of the prefix is the root folder /
. The prefix is removed from the request path. This relative path is appended to the local folder (which is the...