-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-scripting.html
223 lines (187 loc) · 5.99 KB
/
server-scripting.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Best Website</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<nav>
<ul role="none">
<li>
<a href="index.html">Markup and web languages</a>
</li>
<li>
<a href="implications.html">Implications</a>
</li>
<li>
<a href="client-scripting.html">Client-side scripting</a>
</li>
<li>
<a href="server-scripting.html">Server-side scripting</a>
</li>
</ul>
</nav>
<article>
<h1>Server-side scripting</h1>
<p>
Server-side scripting refers to the use of a server to process data sent
by a client and to prepare data to send back to a client, specificaly
relating to dynamically modifying web traffic.
</p>
<p>
For example, most services which offer a log-in feature do so via
backend scripting. The client will send its login credentials to the
server, who will then check them. If they are valid, the server returns
a session token to the client, which can then be used to access
pivileged resources via the web server.
</p>
<p>
While a "scripting language" is a very specific type of language, which
is always parsed and compiled as it is needed or used, many people
incorrectly use this term to refer to any language (such as Java or C#)
used on a web server for dynamic content.
</p>
<aside>
<h2>Server-side scripting languages</h2>
<p>
In order of popularity, according to the StackOverflow Developer
Survey of 2021:
</p>
<ul>
<li>Python</li>
<li>Node.js (JavaScript)</li>
<li>PHP</li>
</ul>
<p>
Note: popularity does not specifically refer to their popularity as
web server scripting languages, just their overall popularity.
</p>
</aside>
<figure>
<img
src="https://static.independent.co.uk/s3fs-public/thumbnails/image/2014/05/21/11/v3-miliband-selwynv2.jpg?width=1200"
/>
<figcaption>
Ed Miliband enjoying some JAM stack (JavaScript, APIs, Markup)
development.
</figcaption>
</figure>
</article>
<div class="Comments">
<h2>Comments</h2>
<div class="Comments-newComment">
<div class="Comments-newCommentNames">
<label>
First name
<input type="text" id="firstName" required />
</label>
<label>
Last name
<input type="text" id="lastName" required />
</label>
</div>
<label>
Email
<input type="email" id="email" required />
</label>
<label>
Date
<input type="date" id="date" required />
</label>
<label>
Comment content
<textarea
minlength="10"
placeholder="Type a comment..."
required
></textarea>
</label>
<button id="submit-comment">Submit comment</button>
</div>
<div class="Comments-list"></div>
</div>
<script>
const LS_KEY = "btec--server-scripts_comments";
/**
* @type {HTMLTextAreaElement}
*/
const textarea = document.querySelector(".Comments-newComment textarea");
const firstName = document.getElementById("firstName");
const lastName = document.getElementById("lastName");
const email = document.getElementById("email");
const date = document.getElementById("date");
function getComments() {
return JSON.parse(localStorage.getItem(LS_KEY)) || [];
}
function addComment(message) {
const comments = getComments();
comments.push(message);
localStorage.setItem(LS_KEY, JSON.stringify(comments));
updateCommentsInDom();
}
function validateNewComment() {
if (textarea.value.trim().length < 10) {
return false;
}
if (
Math.min(
firstName.value.trim().length,
lastName.value.trim().length,
email.value.trim().length,
date.value.length
) === 0
) {
return false;
}
if (!email.checkValidity()) {
return false;
}
return {
comment: textarea.value.trim(),
name: `${firstName.value.trim()} ${lastName.value.trim()}`,
email: email.value.trim(),
date: date.value,
};
}
function submitCommentHandler(e) {
const result = validateNewComment();
if (result === false) {
return;
}
addComment(result);
firstName.value = "";
lastName.value = "";
email.value = "";
date.value = "";
textarea.value = "";
}
function updateCommentsInDom() {
/**
* @type {{ comment: string, name: string, email: string, date: string }[]}
*/
const comments = getComments();
const commentsContainer = document.querySelector(
".Comments .Comments-list"
);
commentsContainer.innerHTML = "";
comments.forEach((comment) => {
const commentElement = document.createElement("div");
commentElement.classList.add("Comment");
commentElement.innerText = comment.comment;
commentElement.setAttribute(
"data-header",
`${comment.name} <${comment.email}> (${comment.date})`
);
commentsContainer.appendChild(commentElement);
});
}
document
.getElementById("submit-comment")
.addEventListener("click", submitCommentHandler);
updateCommentsInDom();
</script>
</body>
</html>