WebFund 2015W: Tutorial 3

From Soma-notes
Revision as of 12:29, 26 January 2015 by Soma (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In this tutorial you'll be playing with tinywebserver.js, a static file webserver in node.js that has no dependencies outside of the core node.js modules. It is based on a tiny node.js web server written by Rod Waldhoff. (Note that the original is written in CoffeeScript.)

To run it, just type "node tinywebserver.js". It will begin serving on the web the pages in the same directory as the script. You'll want to have some files files to serve; to start off, try saving pages from the web and serving those. (Note: they probably will be broken in some way by tinywebserver.)

You can run tinywebserver under the debugger by typing "node debug tinywebserver.js". (Unclear why this did not work in lecture, but it should work now!)

Questions

  1. What port is the web server listening on?
  2. What file is returned when you access a directory? Why?
  3. What sort of URL do you give to get the insecure URL warning (403 Forbidden response code)?
  4. What URL do you need to get a 500 error?

Tasks

  1. Change the port the server listens on to be 3000.
  2. Change the server to serve files from /home/student/public_html rather than the current directory. Be sure to put some files in it! (Hint: you can grab HTML files from any webserver using wget or curl.)
  3. Write a minimal node express app that provides the same basic functionality as tinywebserver.js. How big is this program? Start with [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/code/myapp.zip myapp or any other basic node app. You'll want to combine the existing files into one file to reduce the number of lines required (e.g., eliminating some requires lines). Note that while your app will contain require lines and the corresponding modules, it shouldn't need files outside of those in node_modules (and the static files that are served) and should fit into one file.
  4. Change tinywebserver.js so it returns a simple HTML error page in response to 404 errors (page not found).