SE 3316A Web Technologies Lab


SE 3316A Web Technologies Lab #3: Due Sunday,Oct. 27,11:55 pm
Deadlines:
1. Submission deadline: Sunday,Oct 27,11:55 pm
2. Demonstration deadline: Tuesday,Nov. 5,12:30 pm
Objectives:
A. Design and implement a ReST API for basic Create/Read/Update/Delete (CRUD) operations to
maintain a database of key/value pairs on the server-side (back-end).
B. Create a client (front-end) interface for interacting with the above API (pure JavaScript only).
C. Use asynchronous operations for showing a live view of the database.
D. Using a single web-server for both static content as well as ReST API.
E. Apply input sanitization techniques
F. Learn about the basics of using Node.js,Express and MongoDB to create a ReST API
In this lab,you will implement some server-side functionality for the library checkout application in lab 2.
Accessing the application using a public URL is mandatory. You may use Amazon EC2,Cloud9 or your own
server for a public URL. You may use a local installation of Node.js for development purposes.
Workflow:
1. Create a new private Git repository on Github called “se3316-xxx-lab3” (all lowercase) where “xxx”
is your Western email ID.
2. Clone that repository on your workstation/laptop to create a local working directory.
3. Make frequent commits and push your project to Github at the end of your work session.
Submission Instructions:
Please carefully read the instructions and strictly follow them. Your grade depends on it.
1. Use a proper “.gitignore” file so that only the files that you edit are in your repository.
2. Make frequent commits with an appropriate commit message.
3. Ensure that you understand the principles behind your code.
4. Ensure that Github contains the latest version of your code.
5. Copy the output of command “git log” and paste that onto the submission page (Assignments
section) on Owl.
6. Download your repository as a zip file from Github and submit as an attachment. Please do not zip
the folder on your computer as it contains a large amount of extraneous files
7. Ensure that your Github repository is shared with TAs.
8. Demonstrate your lab before the demonstration deadline.
Penalties will apply for not following the naming convention or any of the submission steps.
Schedule:
You may complete it at home. TAs will be available in 3C+ 4435/4440 during lab hours (Mondays
8:30am-10:30am,Tuesdays 8:30am-10:30am and 10:30am-12:30am) to answer any questions that you
may have.
Preparation - Software Stack
On your computer: Install Node.js and follow the “Writing a CRUD app with Node.js and MongoDB” guide
on Owl.
On Amazon AWS: Follow the guides on Owl to set up a AWS EC2 or Cloud9 instance with latest version of
Node.js
1. Create a new workspace
a) Create a new Github repository
b) Initialize the Node package manager with command npm init. Enter ‘lab3‘ for name,
‘server.js‘ for entry point. For other values,you may just press ‘Enter’ key to accept the default

SE 3316A作业代做、代写Web Technologies作业
value or enter anything you like. This creates a file called ‘package.json’. You may inspect this file,
edit it by hand or remove it and re-do this step if you make a mistake.
c) Install dependencies using npm install express mongoose body-parser --save. This will
install the supporting libraries ‘express’,‘mongoose’ and ‘body-parser’ as well as add these to
‘package.json‘ file as dependencies. Feel free to read more about these libraries using your
favorite search engine.
d) Make frequent commits as you progress through the assignment.
2. Install MongoDB
You will be using MongoDB,which is a simple key-value database. You may use a 3rd party provider for this
and use their web API for your application (see “Using 3rd party service for MongoDB” section below).
While this may ease your workload,it offers fewer opportunities to gain experience.
To install,type sudo apt-get install -y mongodb-org on the terminal window. This will download
MongoDB v2.6 and install it on your workspace.
Create the server start script using following three commands (please note the use of spaces,single and
double quotation marks and type them exactly as shown):
1. mkdir data
2. echo ‘mongod --bind_ip=$IP --dbpath=data --nojournal --rest "[email protected]"‘ > rundb
3. chmod a+x rundb
3. Start MongoDB server
In a new terminal,type ./rundb. This will start the database server. Pay attention to the log messages for
any errors or warnings.
Create another new terminal and test the database by running the command mongo. To start the
interactive shell for MongoDB. Type exit to exit the interactive mongo shell.
Problems with MongoDB not starting
To properly shut down the mongodb server,type Ctrl-c in the terminal that started the mongodb server
(e.g. via rundb script). If the database server is not properly shut down (e.g. logging out or closing the
terminal),it may not start the next time and requires repairing the database.
To repair the mongoDb type ./rundb --repair in the terminal and then type ./rundb again to restart
the database.
Preparation - Creating a Basic ReST API with Node.js and Express
Follow the tutorial at scotch.io on getting started with Node.js and Express. Since you have already
performed some if the initial steps in this tutorial,please start from the step: “Setting Up Our Server
server.js”. At the end of this tutorial,you will have created a working ReST API to create,read,update and
delete data records in a MongoDB database.
Important:
1. On C9,mark the application url as public. Otherwise your network endpoints will not be accessible to the
front-end code.
2. Use the correct URL in the ‘mongoose.connect’ method to connect to your own database that was
setup in the preparation step above.
This connect URL follows standard URL notation (scheme://host:port/path). In this case scheme is
‘mongodb’,host is ‘localhost’,port is ‘27017’ (standard port for mongodb) and path is the name of the
database. Let‘s call it ‘bears’. If the database doesn’t exist,mongodb will create it for you. So,the full URL
is: ‘mongodb://localhost:27017/bears’.
Avoid copy+paste since quotation marks are not the ones expected by Node.js (or any programming
language).
Main Activity - Creating a database back-end for the shopping cart
The back-end functionality must provide URLs (nouns) and appropriate HTTP verbs following actions:
1. Create a new item with name (required),type (“book” or “CD”,required) and loan period (optional).
2. Update the quantity of items.
3. Update loan period of an item.
4. Delete an item.
5. Get all available items (name and type),quantity and loan period.
6. Get the quantity,type and loan period of a given item.
You are required to design the proper noun+verb combinations using ReST paradigm. Data may be entered
in any language supported by UTF-8 and the web service must preserve the language encoding.
The front-end functionality must provide:
1. A minimal user interface to test all back-end functions.
2. Use asynchronous functionality (e.g. polling every 2s) to periodically update the available items and
quantities.
1. Sanitize all user input so that the display must not interpret any HTML or JavaScript that might be
typed on to the text area.
2. Allow any language as item name and display items in the language it is entered.
Optional reading: http://xkcd.com/327/
Code will be checked for similarity. Please work independently. Please frequently check the FAQ below for
clarifications,tips and tricks.
FAQ
1. Unable to access the REST endpoints from Postman.
If you could not able to access the REST endpoints from Postman (students report that they get the C9 login
page in the response),follow these steps to solve the problem.
1. Click the ‘Share’ button on top right corner
2. Mark the application URL as Public
2. Using 3rd party service for MongoDB
You may use a 3rd party web service such as mlab.com instead of installing your own server. While this may
ease your workload,it offers fewer opportunities to gain experience.
3. Input sanitization
Main ideas is to prevent any text input field from being used in injection attacks (HTML injection,SQL
injection,JS injection etc). This happens if you store user input and then send that input back to client to be
displayed. E.g. If a user enters malicious JavaScript in to a text box and that gets stored and sent back later
without any filtering,it allows injecting JavaScript to your front-end.
It is very hard to sanitize user input that applies to all situations and requires a layered approach. First layer
is input validation. If a field requires a number,input validation must ensure that only a number is accepted.
Next layer is filtering. You may use a third-party library to strip HTML,CSS and JavaScript from user input.
Third layer is how data is added to the DOM. Always ensure that you use createTextNode() method to
show user entered data.

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:[email protected] 

微信:codehelp

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


HTML代码中要想改变字体颜色,常常需要使用CSS样式表。CSS是一门用来描述网页上样式的语言,通过编写CSS代码可以实现网页中各元素的大小、颜色、字体等各种样式的控制。那么如何在HTML代码中应用CSS样式来改变字体颜色呢?这里为大家介绍一下。 首先,在HTML代码...
HTML代码如何让字体盖住图片呢?需要使用CSS的position属性及z-index属性。 img { position: relative; z-index: -1; } p { position: absolute; to...
HTML代码字体设置 在HTML中,我们可以使用标签来设置网页中的文字字体。常用的字体标签是font和style,下面我们来学习如何使用这些标签。 1. font标签 使用font标签可以改变文字的字体、颜色和大小。它有三个属性font-family、color和...
在网页设计中,HTML代码的字体和字号选择是非常重要的一个环节,因为它们直接关系到页面的可读性和视觉效果。 要指定文本的字体和字号,可以使用HTML中的样式属性。使用样式属性设置字体和字号,如下所示: <p style="font-family: Aria...
HTML(Hypertext Markup Language,超文本标记语言)是一种用于创建网页的标准语言。它由许多标签(一对尖括号包围的关键字)组成,这些标签告诉浏览器如何显示内容。使用HTML代码,我们可以轻松地创建各种类型的图像和图形,如太极图。 在HTM...
外链是指在一个网页中添加一个指向其他网站的链接,用户可以通过这个链接直接跳转到其他网站。在HTML中,实现外链的方法很简单,只需要使用标签就可以了。 <a href="http://www.example.com">这是一个外链,点击跳转到www.ex...
HTML代码是实现网页界面的基础,而网页中的各种表单则是用户和网站进行交互的重要方式之一。下面我们来介绍如何使用HTML代码实现一个简单的报名表格。 <form action="submit.php" method="post"> &lt...
HTML是一种标记语言,用于开发网站和其他互联网内容。字体是网站设计中的关键元素之一,它可以决定网站的整体风格和呈现效果。HTML提供了字体编辑器,使网站设计变得更加容易。 <font face="Arial"> 这里是Arial字体 &...
HTML代码中,字体样式是开发者们必备的一部分。在HTML中,我们可以通过特定的标签和属性设置字体的样式、颜色和大小,以达到更好的排版效果。 <p style="font-size: 14px; color: #333; font-family:...
HTML中的字体可以设为粗体,以强调文本信息。我们可以通过使用一些标签来实现这一功能。其中,常用的标签包括: 1. 标签:该标签会把文本加粗显示,语法如下: 这是一段加粗的文本 2. 标签:与标签作用相同,但语义更强,表示该文本内容的重要性。语法如下:...
HTML代码可以实现文件的上传和下载,在网页开发中相当常见。通过使用<input>标签和<form>标签,我们可以轻松创建一个文件上传表单。 <form action="upload.php" method="post" enct...
HTML代码非常常见于网页设计中。在一些需要处理时间相关数据的场景下,可能需要将时间戳转换为实际时间,这时候就需要使用一些特定的HTML代码。 function timeStamp2Time(time){ var date = new Date(time...
HTML是一种用于创建网页的标记语言。在HTML中,我们可以使用超链接标签实现下载文件到本地的功能。 具体实现步骤如下: <a href="文件的URL" download="文件名">下载文件</a> 其中,href属性是文件...
在HTML代码中,对于字体靠左对齐有各种方法。其中最简单的方式之一是使用pre标签。 使用pre标签可以保留一段文本中的空格和换行符,从而使代码排版更加整齐。下面是一个例子: <p>这是一个段落。</p> &lt...
HTML代码字典是一本解释HTML标记和属性的参考文献。这本字典中包含了最常用的HTML代码以及它们的属性和值的详细描述。 例如,以下是HTML代码字典中的一部分内容: <a href="url">link text</a> 在...
在网页开发过程中,遇到一些需要用户复制的内容,我们通常都会提供复制按钮,让用户更方便地复制所需内容。下面我们来介绍如何使用html代码实现一键复制的功能。 var copyBtn = document.querySelector('#copy-bt...
用户登录 欢迎来到公司登录界面,请输入用户名和密码登录 用户名: 密码: 代码解释: 第1行:定义了一个 HTML 文档 第2行:开始了 HTML 头部 第3行:定义了...
HTML 代码是用来创建网页的语言,它包含了许多不同的元素和属性,让我们可以在网页中添加各种不同的元素和内容,如文字、图片、链接等等。在编写 HTML 代码时,我们可以使用各种不同的样式来美化我们的网页,例如更改字体、颜色、大小等等。 font-family:...
HTML代码中的字体转移 在编写HTML代码时,我们经常会使用各种字体来增强页面的可读性和视觉效果。但是,有些字符或特殊符号可能会在HTML中具有不同的含义,这就需要使用字体转义转换成HTML可以正常显示的字符。 在HTML中,使用"&"符号表示一个特殊字符将要被转...
HTML 编程语言中,你可以使用字体属性来更改文本的字体大小、颜色和样式。其中,字体颜色是最常用的样式更改。在 HTML 中,你可以使用 "color" 属性来更改文本的颜色。下面是一个使用 "pre" 标签的代码示例,演示如何使用 "color" 属性来更改字体颜色...