This repository has been archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (55 loc) · 1.93 KB
/
index.js
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
const http = require('http')
const dodaj = require('./dodaj')
const server = http.createServer(function(request, response) {
if (request.method == 'POST') {
const result = dodaj.add100();
var resultPage = `
<html>
<head>
<meta charset="UTF-8">
<title>Wynik</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center">Result: ${result}</h1>
<div class="row justify-content-center">
<div class="col-md-4 text-center">
<a href="/" class="btn btn-primary">Back to main page</a>
</div>
</div>
</div>
</body>
</html>`;
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
response.end(resultPage);
} else {
var html = `
<html>
<head>
<meta charset="UTF-8">
<title>Node.js Number Adder</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center">Node.js Number Adder</h1>
<p class="text-center">Click the button below to add numbers from 1 to 100.</p>
<div class="row justify-content-center">
<div class="col-md-4 text-center">
<form method="post">
<input type="submit" class="btn btn-primary btn-lg" value="Add numbers from 1 to 100" />
</form>
</div>
</div>
</div>
</body>
</html>`
response.writeHead(200, {'Content-Type': 'text/html'})
response.end(html)
}
})
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
console.log(`Server is running on port localhost:${PORT}`);
});