Sale!

ECS 162 Assignment 4

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (1 vote)

In this assignment, we will make a little app that takes an input
word and produces its palindrome; that is, given “bark” it
produces “barkkrab”. The interesting part is that we will computethe palindrome on the server.

Answering a query

Begin with miniServer3.js, which was discussed in detail inMonday’s lecture. Upload it to the server, and put it into a newdirectory /hello with a sub-directory /public. Edit miniServer3.jsto put your port number into the global variable port. Install
express using npm (npm install express). Put a file (a simple html
file, for instance) in the /public directory, and run the server in/hello using node. Make sure the server can serve the static file,
and answers queries about animals.

Now, change the server so that it detects queries of the form:
http://server162.site:port/query?word=anything Here port is your”port” number, and “anything” is any word. Add some code so thatif it gets a query of this form, it shoud return the palindrome asJSON:
{ “palindrome”: “anythinggnihtyna” } If your server gets a request
for a static file in your “public” directory, it should serve that file.

If your server gets any other kind of HTTP request, it should returnan error message, such as “Cannot find /whatever”.

AJAX query

Now we will use our server to serve a page and respond to anAJAX query. In your /public directory, you can put this Web pagepalindrome.html, which has a text input box and a submit button.
Notice the submit button does nothing. Give it an onclick function,
and add some javascript that gets the “value” property of the inputbox when the submit button is pressed.

Now have your code send the word to the server as an AJAXrequest, using the format we programmed the server tounderstand. You can use the XMLHttpRequest object, exactly aswe did in the last project. The one small difference when you arecommuincating with your own server instead of a CORS server isthat the url is just “query?word=…”, that is, you don’t specify thedomain name part of the url since the browser knows it. Thecallback function that is run when the response comes backshould gets the palindrome out of the returned JSON, and displayit on the page.

If you want to, you can make the page prettier by adding somecss; feel free to add to the html.

Turn in Instructions
Hand in the assignment as a zip file, using Canvas. To zip up theentire server directory, including the public directory, go to thedirectory above “hello”, and on the command line, type:
zip -r hello.zip hello