WebFund 2015W: Tutorial 3: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
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.) | 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" | 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=== | ===Questions=== |
Latest revision as of 16:29, 26 January 2015
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
- What port is the web server listening on?
- What file is returned when you access a directory? Why?
- What sort of URL do you give to get the insecure URL warning (403 Forbidden response code)?
- What URL do you need to get a 500 error?
Tasks
- Change the port the server listens on to be 3000.
- 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.)
- 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.
- Change tinywebserver.js so it returns a simple HTML error page in response to 404 errors (page not found).