CS 351 Spring 2020 Homework 7

Static Site Generation and Networking

Dr. Greg M. Bernstein

Due Monday, March 22nd, 2021 by 11:59PM, 50 points.

General Instructions

In this homework: We will create our own static site generator and get hands on with Networking via Node.js. Put any code you write for this homework into a high level directory with the name Practice. Clear out any old files that you may have in this directory.

Create and Use a new Branch hw7

We will create a new git branch called hw7 (starting from your ‘hw6’ branch) for use in this assignment. The branch you create must exactly match the one I’ve given you for you to receive any credit for this homework.

Prior to creating this new branch make sure your working directory is “clean”, i.e., consistent with the last commit you did when you turned in homework 6. Follow the procedures in GitHub for Classroom Use to create the new branch, i.e., git checkout -b hw7. Review the section on submission for using push with a new branch.

Use README.md for Answers

You will modify the README.md file to contain the answers to this homework.

# Homework #7 Solution

**Your name**
**NetID: yourNetID**

Questions

Question 1. (30 pts) Static Site

We are going to automate the maintenance and updating of the club website using our own static site generator program and not another external library such as Metalsmith or Eleventy. This builds on the processing we learned to do in Homework #6. This will be our last work on our static website. After this we will be working on web servers and web apps.

(a) Create directory structure

Create a new top level directory clubSSG in your repo. Within this directory create the following directories: src, build and views.

Nothing to show here

(b) Copy clubProject site files

Copy your clubProject CSS and image files into the clubSSG/build directory. These are the files that won’t be processed by our program.

Copy your clubProject HTML files into the clubSSG/src directory. These will become the files that we will process and update.

Nothing to show here

(c) Update .gitignore

We are will be writing a Node.js program that will take the files of the src directory converting them to HTML files and placing them in the build directory. Add the appropriate line to your .gitignore file to ignore all the HTML files in the build directory. Show that line here.

(d) Convert src HTML to Markdown

Convert your HTML files into Markdown files that just contain content and metadata front matter. This can take some time. Also for HTML that doesn’t have Markdown equivalents you can mix in HTML, this can require some extra line breaks around HTML elements per the commonmark specification. Remember to add front matter for title and author.

Nothing to show here

(e) Templates

Add templates to the views directory for processing your content. Incorporate your navigation menu into your template via the <% include %> mechanism.

Show your base template here.

(f) Extend Program/Process Files

Now update your processIt.js program from homework #6 to process all the markdown files in the src directory to “generate” your static site. This program should list each of the files in the src directory to the terminal as it is processed.

Here is some code you can use for your dealing with files.

const fs = require('fs');
let srcPrefix = __dirname + "/src";
let bldPrefix = __dirname + "/build";
let allFiles = fs.readdirSync(srcPrefix);

console.log("Processing the src directory: ");
allFiles.forEach(function(srcName) {
    console.log('Reading ' + srcName);
    let fname = srcPrefix + '/' + srcName; // full name of the file to be read
    let fdata = fs.readFileSync(fname, 'utf8');
    //
    // Your file processing here
    //
    // create the full name of the file to be written change extension to .html
    let outName = (bldPrefix + '/' + srcName).replace(".md", ".html");
    fs.writeFileSync(outName, outString);
});

Show your code here.

(g) Deploy Your Site

Deploy your site to the department server. This is your last deployment of your static site. Put the link to the site here. All links and functionality from previous versions must work to receive credit.

Question 2. (10 pts) Networking Concepts

(a) Get your Ethernet and IP addresses with Node.js

Using the program (netIf.js) given in the course slides Node/NPM Network Access obtain the IPv4 and Ethernet addresses for the computer you using to do this homework. If more than one network interface is listed make sure you choose the actual “external” interface that you are using. List these addresses here.

(b) Difference between Ethernet and IP

When we look at the diagrams of the Ethernet and IP packets in the course slides we see a number of similarities. Both contain source and destination addresses, a data payload, and a field to indicate what higher layer protocol the data payload is carrying. Why do we use IP for the worldwide Internet and only use Ethernet in limited networks? Answer here

(c) Packet size limits

Packets have size limits. These usually stem from physical layer considerations. Most Ethernet packets have a “maximum transmission unit” (MTU) of around 1500 bytes. How can we transmit an image on our website with a size of 200KB with this limitation. How would you solve this problem from a high level perspective? What network layer would you think should have this functionality? Answer here

(d) Difference between UDP and TCP

UDP and TCP both provide source and destination port numbers for “multiplexing” purposes. From an end user perspective what extra functionality does TCP provide over UDP and why do we use TCP to carry web traffic? Answer Here

Question 3. (10 pts) DNS

We are going to use Node.js to query the Domain Name System directly for us. The base library is imported and used as follows:

const { Resolver } = require('dns').promises;
const resolver = new Resolver();
// Make various method calls with the resolver object
// as shown below.

(a) Who are your DNS servers?

Find out the default DNS servers your machine is using with the code below.

let servers = resolver.getServers();
console.log("DNS Servers:");
console.log(servers);

List these here, for the IPv4 addresses are any of these local to your network?

I get something like:

$ node dnsTest.js
DNS Servers:
[ 'fd56:a35c:a91::1', '192.168.1.1' ]

(b) Lookup the address of a domain name

Use Node.js and DNS to directly look up the IPv4 address of a domain. Please pick something interesting and unusual (not google or facebook).

// Use a different domain name here
resolver.resolve4('DrBsClasses.org').then((addresses) => {
    console.log('Address for DrBsClasses.org')
    console.log(addresses);
});

Show your results here I get something like:

Address for DrBsClasses.org
[ '73.158.236.89' ]