-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
109 lines (90 loc) · 3.88 KB
/
server.js
File metadata and controls
109 lines (90 loc) · 3.88 KB
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
const express = require('express');
const app = express();
const port = process.env.PORT || 4000;
const dataGenerators = require('./dataGenerators');
app.use(express.static('public'));
app.get('/generate/name', (req, res) => {
const gender = req.query.gender || 'all';
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateName(gender, quantity));
});
app.get('/generate/surname', (req, res) => {
const gender = req.query.gender || 'all';
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateSurname(gender, quantity));
});
app.get('/generate/date', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
const format = req.query.format || 'DD-MM-YYYY';
const separator = req.query.separator || '-';
res.json(dataGenerators.generateDate(quantity, format, separator));
});
app.get('/generate/pesel', (req, res) => {
const gender = req.query.gender || 'all';
const year = parseInt(req.query.year) || undefined;
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generatePESEL(gender, quantity, year));
});
app.get('/generate/id', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateID(quantity));
});
app.get('/generate/swift', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateSwift(quantity));
});
app.get('/generate/nip', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateNIP(quantity));
});
app.get('/generate/regon', (req, res) => {
const type = parseInt(req.query.type) || 9;
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateREGON(quantity, type));
});
app.get('/generate/landRegistry', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateLandRegistryNumber(quantity));
});
app.get('/generate/bankAccount', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateBankAccountNumber(quantity));
});
app.get('/generate/iban', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateIBAN(quantity));
});
app.get('/generate/companyName', (req, res) => {
const wordCount = parseInt(req.query.wordCount) || 1;
const funny = req.query.funny === 'true';
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateCompanyName(quantity, wordCount, funny));
});
app.get('/generate/street', (req, res) => {
const wordCount = parseInt(req.query.wordCount) || 1;
const funny = req.query.funny === 'true';
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateStreet(quantity, wordCount, funny));
});
app.get('/generate/city', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateCity(quantity));
});
app.get('/generate/postalCode', (req, res) => {
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generatePostalCode(quantity));
});
app.get('/generate/comment', (req, res) => {
const wordCount = parseInt(req.query.words) || 10;
const characterCount = parseInt(req.query.characters);
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateComment(quantity, wordCount, characterCount));
});
app.get('/generate/specialComment', (req, res) => {
const type = req.query.type;
const quantity = parseInt(req.query.quantity) || 1;
res.json(dataGenerators.generateSpecialComment(quantity, type));
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});