Course Hero Logo

SIT774-8.2C-TaskSheet.pdf - SIT774 Web Technologies and...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 2 out of 5 pages.

8.2C: Writing a Server ApplicationTasksIn this task you are asked to demonstrate how a web server can be coded to servedynamicpages. Specifically, the server application is to provide a page thatdisplays if the visitor is aWinner of a Competitionor not. The selection of awin/no-win can be based on a simple random number selection (i.e., 1 in 3chance). This page is to be served through a defined web address (or route) suchas.Follow the steps below to complete this task:1. Create your own local directory (or you can use the same local directorycreated in Task 8.1).2. Use express module to create aNode.js application(i.e., using theindex.jsfrom your Task 8.1 or creating a newexpressServer.js) that will set a localweb server. The server listens to the port3000.3. Modify yourindex.js(orexpressServer.js) file to:remove the hardcoded response for theGETon the/route (as done inTask 8.1P) and change it to serve pages form thepublic_htmlfolder, asdone in previous weeks (sample of this code is shown in the snippetbelow)add a route handler for aGETrequest on/competition. This would enableaccess tousing a web browser. Thehandler for this route would then choose a random number (say out of 3)and if it equals 3 then display a ‘win’, otherwise display a ‘no winmessage. These messages, along with a statistics (tally) of wins & losses,

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 5 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Three
Professor
N/A
Tags
Web page, World Wide Web

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture