Merge branch 'master' of https://github.com/fkereki/modernjs
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
**/flow-typed
|
||||
**/flow-coverage
|
||||
**/out
|
||||
**/*.env
|
||||
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome",
|
||||
"url": "http://localhost:8080",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"program": "${file}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFBjCCAu4CCQCfqa7X5n3VxTANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJB
|
||||
VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0
|
||||
cyBQdHkgTHRkMB4XDTE4MDUxNTAyMzIzOVoXDTE5MDUxNjAyMzIzOVowRTELMAkG
|
||||
A1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0
|
||||
IFdpZGdpdHMgUHR5IEx0ZDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIB
|
||||
ANbcHBybfkSZuPYvrLjOrX9W24YpwQvfRWLGYFXUAbyu3kTjZkuYUI4nWgFcZXHo
|
||||
TGoes92SNL5OnOXPh2MQbyBU/5sVsuZnObtSPt8095UeJrQSyAlSV5J5Q1yHs3qI
|
||||
Etq7MHJ02EgaysupNmiSctzdys+hGCavQ0Yl8StOg4HF+0LD2OKfdxDSsYTWaZ10
|
||||
F6/AyPX4d4/tCm9RqZOJx/XRiDJ8uZjShApiJ+HbQkIybqVGx7NQSlA7kCbrS4s/
|
||||
Zl292l2G+O4/Wa0dxQSg9JjKg7/QwLt/m/MhNWEm3fEWxfRYxABG1Y11OZDyXDNj
|
||||
X55gRHRJTZLMEgW+Dex38gHjKk2L6xuG7xrkBmk7fB8UD42dEa/vToJ7L4hlvsaJ
|
||||
ZyhNinwsNf+ap+STfe34skokKawE5ASqwsK8cyBueX5CMjUYHSKdgR/B59v9HXbp
|
||||
vfh+SKN1j+dt4VrIsIMWLs8jzJ63vUdLyl19/29VK/AKVouWvV/egF4IKAmZcRJ0
|
||||
V6kNqPI4PvlDgIiBmqafX7UArh9gNNf77cfOp6Xd6PmEof1OW/WXtoI5QZMTTcJZ
|
||||
JHZYH1S3WPQJYYsk7OKWy9LHKiieBAV7X0y+25yfwZeWl/PJTWJiqkxjwoee3FF5
|
||||
Y0OpGGkZBUK/RTuVryHelMRucuS+oTsqk4HKiWp8Ds8tAgMBAAEwDQYJKoZIhvcN
|
||||
AQELBQADggIBAGwVGW9/j6ImzQSXzPwrKeYDi/dFLEhyU1eSyYobMxqNzrGyBh3a
|
||||
YhQm4/bY+JXdv22neLhFLhkVuq+33e86fawezJzDbyWmHRY2cjZdRehH1nyWEzFJ
|
||||
ffyyJPRsNguCHtYgSC6F1fGVXmvJ/2JRXeMY/EgReZnIaweLpqQdfnpHj0NmzzxX
|
||||
foxKhmXjmFv3yZg/fiZ1eEKMlVMVRyE6IwDzhuUkMNpV+cwepu8FpsUP6ZGRJTVn
|
||||
8PYfhDmvZKGwfWetkdgujRPzl5UBfR7yPHiNNKrkXxuh9jxmxQ6tgofCmgJX8MAj
|
||||
JDAKN3yN7HXpxoiYgdQjBDZ9q7trfvUJNKZFQ/IidJPOKkEJAg6MXn9vLSolfyFV
|
||||
qlo0xa7JgnfgMPdfGncekBpFMdY1U6UHNpUd+EDSNQykjKHDal93BWUVPmG9iiPp
|
||||
3CNTQIbh4gC8PqEcb1vzvfGuUTT8ZbywzOfP3ydhkEQbIGQHP7P9IqwV8uH7pyVp
|
||||
LsqPMey2G6xloigq7uQu0FC59DmYYysvXkROpwDo3rPF63S22k2uCRhKAUbHmUL0
|
||||
zHvnJAwslgloNqdwkVdx3Rxq/xq9QHvWTB+b3n2IdjLoM3jqN8OjZr3NjFy3q6fX
|
||||
L/kJUpi1pzO2/U59kw6+9NCfp7CV0/zWuwlETKq+eKKgGk3lids+Jds9
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,27 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIEijCCAnICAQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUx
|
||||
ITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDCCAiIwDQYJKoZIhvcN
|
||||
AQEBBQADggIPADCCAgoCggIBANbcHBybfkSZuPYvrLjOrX9W24YpwQvfRWLGYFXU
|
||||
Abyu3kTjZkuYUI4nWgFcZXHoTGoes92SNL5OnOXPh2MQbyBU/5sVsuZnObtSPt80
|
||||
95UeJrQSyAlSV5J5Q1yHs3qIEtq7MHJ02EgaysupNmiSctzdys+hGCavQ0Yl8StO
|
||||
g4HF+0LD2OKfdxDSsYTWaZ10F6/AyPX4d4/tCm9RqZOJx/XRiDJ8uZjShApiJ+Hb
|
||||
QkIybqVGx7NQSlA7kCbrS4s/Zl292l2G+O4/Wa0dxQSg9JjKg7/QwLt/m/MhNWEm
|
||||
3fEWxfRYxABG1Y11OZDyXDNjX55gRHRJTZLMEgW+Dex38gHjKk2L6xuG7xrkBmk7
|
||||
fB8UD42dEa/vToJ7L4hlvsaJZyhNinwsNf+ap+STfe34skokKawE5ASqwsK8cyBu
|
||||
eX5CMjUYHSKdgR/B59v9HXbpvfh+SKN1j+dt4VrIsIMWLs8jzJ63vUdLyl19/29V
|
||||
K/AKVouWvV/egF4IKAmZcRJ0V6kNqPI4PvlDgIiBmqafX7UArh9gNNf77cfOp6Xd
|
||||
6PmEof1OW/WXtoI5QZMTTcJZJHZYH1S3WPQJYYsk7OKWy9LHKiieBAV7X0y+25yf
|
||||
wZeWl/PJTWJiqkxjwoee3FF5Y0OpGGkZBUK/RTuVryHelMRucuS+oTsqk4HKiWp8
|
||||
Ds8tAgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAgEAZb2YXQ6hIBUM43neMJgS5FXU
|
||||
JE6JjoDUSQQJhOLwpr9XMGhIBUZ6KPL7gh23ROk/LGIgZN7AxiLVS0Lx2zo9OpPb
|
||||
lPXVn+NNTz8NU+WhsDP88aF0yfzr2YLs0wAsYE0tcFO4T8F4AzzIv5tEYewXn8rt
|
||||
TKunAzimsgjYG6Sv+cWRfBj6c7SERHejbZ1oXajGovEN0LEOpdfuPnDuxFeicpCY
|
||||
USDVSlsaK+QdB5IWg7Pp1kqC3MtksYTM1F79b/e5duv8xlpEasp5WxEgxPbM2ftK
|
||||
1yvlYnk9Tn5W8lsG3Q2PW0pgEpCe2sb4UPqovyZHxIlY6689c2u/47+hTiwH6TRm
|
||||
IoLDUJGhTHWMWUEFo41G9thjo082W0YtLkCfSHXGuazyhXPmWNYsVOaM4Md+7SeK
|
||||
Pw0Btu1xj5MfHxL8RV8KP16TgCXYUjwIJ0oNp29i6KxW7HNabTM2npMEmg71m0OL
|
||||
PJsBXXiJltBzHJ/J9oPrtnRrM6POLRm1A+QTeW0WngcOp2ivQqPjjByL7mHi767l
|
||||
BdHYF55qHBzGlvyMFX3GrDZA4tg5dQER8sg3zErTC9amcfcidPq9Exym8GcY0fmg
|
||||
ZK3SYc2M/pwKC8qcEe42I2qpSogUNkNIb1mQXE1hvk/Q6v+T8C5ZsLvrfQUFQPxX
|
||||
OFc3s+ni/Q3lsi68jHc=
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
@@ -0,0 +1,52 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDW3Bwcm35Embj2
|
||||
L6y4zq1/VtuGKcEL30VixmBV1AG8rt5E42ZLmFCOJ1oBXGVx6ExqHrPdkjS+Tpzl
|
||||
z4djEG8gVP+bFbLmZzm7Uj7fNPeVHia0EsgJUleSeUNch7N6iBLauzBydNhIGsrL
|
||||
qTZoknLc3crPoRgmr0NGJfErToOBxftCw9jin3cQ0rGE1mmddBevwMj1+HeP7Qpv
|
||||
UamTicf10YgyfLmY0oQKYifh20JCMm6lRsezUEpQO5Am60uLP2ZdvdpdhvjuP1mt
|
||||
HcUEoPSYyoO/0MC7f5vzITVhJt3xFsX0WMQARtWNdTmQ8lwzY1+eYER0SU2SzBIF
|
||||
vg3sd/IB4ypNi+sbhu8a5AZpO3wfFA+NnRGv706Cey+IZb7GiWcoTYp8LDX/mqfk
|
||||
k33t+LJKJCmsBOQEqsLCvHMgbnl+QjI1GB0inYEfwefb/R126b34fkijdY/nbeFa
|
||||
yLCDFi7PI8yet71HS8pdff9vVSvwClaLlr1f3oBeCCgJmXESdFepDajyOD75Q4CI
|
||||
gZqmn1+1AK4fYDTX++3Hzqel3ej5hKH9Tlv1l7aCOUGTE03CWSR2WB9Ut1j0CWGL
|
||||
JOzilsvSxyoongQFe19Mvtucn8GXlpfzyU1iYqpMY8KHntxReWNDqRhpGQVCv0U7
|
||||
la8h3pTEbnLkvqE7KpOByolqfA7PLQIDAQABAoICAGAblwuI1kNTS7P7gVQtRtg1
|
||||
/v4VQT/RQFU9jSv3KEvBILVJzqEz4Zykp5MCRHJeSYgScbxDwQn7Wh1F5jZ+zGZ2
|
||||
/trdKuf69oz+7hajt7dhBEj6ObZJudhQG7yRCsxdf6mNn88iyvf93AabizXdhDmd
|
||||
kDGtyoLLVNlU8XrApPxwlcK4nhRI5laFGFjmG9oNaub34ix8VubvTgKbUbIoKGSh
|
||||
tD15Iv/j8qI+Y76YeBvqOSn+7iccXBFlg0aVa3Y/BsgZu0qorELN3YwdS9qVMLQD
|
||||
qkkr1HpKS3TGvvzVCOPlnuh8qDfDd5TOAdD/SBTId6X9Q8GMZIGsfMdKyymiQYKa
|
||||
EbF8IFSNX2EUWhYNIAxa5VZttz08YgoYmMQW5Fav4NZtzdqevHidQjUUdMpo7J1G
|
||||
+rKt4tGIGV5oyxLjKKTL+vdset9t/GmrxolkaZZTwY1WnGjYkm39kYepy1pUqkz4
|
||||
Wkv3wcSLcKiP7EqqT4gRNC196nbukG01o3L5N/2D7/YdNWaHQMNW/RpEJL62i10n
|
||||
mLW1PhCgpGAk2TNPh3yvSQMquoF2RYSOkvziy9p5HEMQzKrffBEdnrigGCbKljHH
|
||||
/Pj++74briaz5UAf644ncEE/p2z0i+F5aSmXGXmrhLfGzmHytqgSTT2mKa8T/JTK
|
||||
9nEsVAXW2fzdHkyE77gVAoIBAQD+70LYBRMTdV/V5evoCnGJB7zudggVXRwYRPCQ
|
||||
zQenKPDbej7kWpRnfhPwsGqEdvWfm8h/N9aYOPFP/u3TDIynJyCuogdbtXsmDxtP
|
||||
osuh2PctcrTMJ/KSqKjqPnQtcOvDy4hpMpzZ2Mp2xVSG7QabTWLgUYoInTsUKDZj
|
||||
sAdpQLVEwGqrd/4n3UByWoS6d/24nP36DyndJyvo4bSYKe/+u1IuCR7EjnkFPSGZ
|
||||
w66JC+4oEPDu54AzWRXGx0kLFfV2slf5S7Bu35Y6w/NMjQR4eqr/BbfgPIr6rH0K
|
||||
v6wZqQYvBS1s0ra58t2ja40ujsDi5l1MbOc6mGaHGuhtdeoTAoIBAQDXwfmhvq1q
|
||||
OmfcXcowidiNYd97y5BYm9vRj7Any/Z5dFSkZ7hdBkIqyA7OpGjiAIE067LgMRRq
|
||||
l2Jgd+c06oeRP0oJLHpOJ1b0qCCZMXcA825IBsvwyPalhPSpqi6yNYVjPePtXbu3
|
||||
dFRZLRry527LJ7wnupIoFdc7JdnJ40Bmo7J/Vtxxna26uhJZ45oE4jwCuLM+qOY4
|
||||
ymRhskZkiiQkdITcmGt+JvRf9KjBPMOhFwCRYEeKPY6u5zF/o4tSiY9mOTFXYqDf
|
||||
Fh9F/pA5xQxfJLoz8uad+1+/9CiHj/jyO67OP5+rmS0GyT7+eC0KrBYLhmo8tLuE
|
||||
dws86Cq4C4m/AoIBAGzHMsJyB925q5bdcHemXSOXRaqKepCDFkXUxMFEewt8kKlV
|
||||
1Bgj/kbaqS9+VzUGfXAJTNfbv5lcUrtLj7cKF8oLDAr34CPloBJxR7oHQNRie7XM
|
||||
yBCEyyCBDvJEi9YH5NG6uw4IJp1dv6ZGNPcNlFAYCSSmJjveuyKyteJ7be4fSjl3
|
||||
0QwxOyVPZvxkW1YldQGdG1Hjvn07BaVtCV4UJu+OhlZWVeaQ1FrD5t5xfLvFd21p
|
||||
LSUDatR+IqiayDQOvppTJu6cuT/V74hLrDjxwwKVdPk0O21W6AZmK0S23Hxmftj5
|
||||
YJSapJVbZ+8fKTLAftVSbmT54wBBnx3vAVYThjkCggEBALGKBIh8BubquJw08TOP
|
||||
uopchzGvCFBhsDh5LFMTGvZGK4A9eQ/THo9loAmacFPIZonNiZvBxzMO7vzCrZZ1
|
||||
hqiWk62I0/uLk5ou3uQwN+Soa48JSLgSJiN9jHYwe8xZDjHjs7KW9ui26NGYtBw9
|
||||
JIY3ZDSs6afikQEy3EusnEnZWgA+0ZcMUPDePEuLZimuoAL9SUG+afNBV+ischA5
|
||||
PBRjbRC4u3tLQrvS7ypTfgcIjocR2sx+avKxe6G0SejZGQ7c8SUfG5F2+rT2DGf9
|
||||
JXkFF9O3hN1rBBdIKjGi3w803VsKL7FckhiLcTKkYSvu/xTsvm7FqagO7UhpIv3f
|
||||
QLECggEAVdcOO0ysyxQkntH2GQU8MoFeCYZjeaYxBreUZWV/yXlcwwtbjmfoXcs9
|
||||
CwV2FOTy68Gsd2dX8hqkhm+USsctAlUdiUT0DWcHp3bNYaodaPX58I0GzvR4SZf1
|
||||
e259Lmyn/lzr5zo1va4mWkgd+IT9TplIQr/OCglGXXTiFkcr3eiqIWwf/otp2926
|
||||
t3Vp0kaY22OlogHUPgmOuolnvBAS6Wk/GcB19Pi+9pbsSPoFUk44bRhixIJbLiO/
|
||||
c40Ydt1bWVrJI9BYEoS1oyktFoBtgg+3VbE0E69WRmCrHElSF3U76qI+ZVH1+ldR
|
||||
WW/Y0mIie3sbuxnOlxZ1ASzbJ66GFA==
|
||||
-----END PRIVATE KEY-----
|
||||
Generated
+252
-38
@@ -857,9 +857,9 @@
|
||||
}
|
||||
},
|
||||
"babel-preset-env": {
|
||||
"version": "1.6.1",
|
||||
"resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.6.1.tgz",
|
||||
"integrity": "sha512-W6VIyA6Ch9ePMI7VptNn2wBM6dbG0eSz25HEiL40nQXCsXGTGZSTZu1Iap+cj3Q0S5a7T9+529l/5Bkvd+afNA==",
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-preset-env/-/babel-preset-env-1.7.0.tgz",
|
||||
"integrity": "sha512-9OR2afuKDneX2/q2EurSftUYM0xGu4O2D9adAhVfADDhrYDaxXV0rBbevVYoY9n6nyX1PmQW/0jtpJvUNr9CHg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"babel-plugin-check-es2015-constants": "6.22.0",
|
||||
@@ -889,7 +889,7 @@
|
||||
"babel-plugin-transform-es2015-unicode-regex": "6.24.1",
|
||||
"babel-plugin-transform-exponentiation-operator": "6.24.1",
|
||||
"babel-plugin-transform-regenerator": "6.26.0",
|
||||
"browserslist": "2.11.3",
|
||||
"browserslist": "3.2.7",
|
||||
"invariant": "2.2.4",
|
||||
"semver": "5.5.0"
|
||||
}
|
||||
@@ -1187,15 +1187,20 @@
|
||||
}
|
||||
},
|
||||
"browserslist": {
|
||||
"version": "2.11.3",
|
||||
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-2.11.3.tgz",
|
||||
"integrity": "sha512-yWu5cXT7Av6mVwzWc8lMsJMHWn4xyjSuGYi4IozbVTLUOEYPSagUB8kiMDUHA1fS3zjr8nkxkn9jdvug4BBRmA==",
|
||||
"version": "3.2.7",
|
||||
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-3.2.7.tgz",
|
||||
"integrity": "sha512-oYVLxFVqpX9uMhOIQBLtZL+CX4uY8ZpWcjNTaxyWl5rO8yA9SSNikFnAfvk8J3P/7z3BZwNmEqFKaJoYltj3MQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"caniuse-lite": "1.0.30000833",
|
||||
"electron-to-chromium": "1.3.45"
|
||||
"caniuse-lite": "1.0.30000843",
|
||||
"electron-to-chromium": "1.3.47"
|
||||
}
|
||||
},
|
||||
"buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
||||
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
|
||||
},
|
||||
"buffer-from": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.0.0.tgz",
|
||||
@@ -1269,10 +1274,15 @@
|
||||
"integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
|
||||
"dev": true
|
||||
},
|
||||
"camelize": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.0.tgz",
|
||||
"integrity": "sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs="
|
||||
},
|
||||
"caniuse-lite": {
|
||||
"version": "1.0.30000833",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000833.tgz",
|
||||
"integrity": "sha512-tKNuKu4WLImh4NxoTgntxFpDrRiA0Q6Q1NycNhuMST0Kx+Pt8YnRDW6V8xsyH6AtO2CpAoibatEk5eaEhP3O1g==",
|
||||
"version": "1.0.30000843",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000843.tgz",
|
||||
"integrity": "sha512-1ntiW826MhRBmM0CeI7w1cQr16gxwOoM8doJWh3BFalPZoKWdZXs27Bc04xth/3NR1/wNXn9cpP4F92lVenCvg==",
|
||||
"dev": true
|
||||
},
|
||||
"capture-stack-trace": {
|
||||
@@ -1330,7 +1340,7 @@
|
||||
"normalize-path": "2.1.1",
|
||||
"path-is-absolute": "1.0.1",
|
||||
"readdirp": "2.1.0",
|
||||
"upath": "1.0.5"
|
||||
"upath": "1.1.0"
|
||||
}
|
||||
},
|
||||
"ci-info": {
|
||||
@@ -1506,7 +1516,7 @@
|
||||
"requires": {
|
||||
"dot-prop": "4.2.0",
|
||||
"graceful-fs": "4.1.11",
|
||||
"make-dir": "1.2.0",
|
||||
"make-dir": "1.3.0",
|
||||
"unique-string": "1.0.0",
|
||||
"write-file-atomic": "2.3.0",
|
||||
"xdg-basedir": "3.0.0"
|
||||
@@ -1523,6 +1533,11 @@
|
||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
|
||||
"integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ="
|
||||
},
|
||||
"content-security-policy-builder": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/content-security-policy-builder/-/content-security-policy-builder-2.0.0.tgz",
|
||||
"integrity": "sha512-j+Nhmj1yfZAikJLImCvPJFE29x/UuBi+/MWqggGGc515JKaZrjuei2RhULJmy0MsstW3E3htl002bwmBNMKr7w=="
|
||||
},
|
||||
"content-type": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
|
||||
@@ -1556,6 +1571,15 @@
|
||||
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
|
||||
"dev": true
|
||||
},
|
||||
"cors": {
|
||||
"version": "2.8.4",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz",
|
||||
"integrity": "sha1-K9OB8usgECAQXNUOpZ2mMJBpRoY=",
|
||||
"requires": {
|
||||
"object-assign": "4.1.1",
|
||||
"vary": "1.1.2"
|
||||
}
|
||||
},
|
||||
"create-error-class": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz",
|
||||
@@ -1606,6 +1630,11 @@
|
||||
"integrity": "sha1-gIrcLnnPhHOAabZGyyDsJ762KeA=",
|
||||
"dev": true
|
||||
},
|
||||
"dasherize": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dasherize/-/dasherize-2.0.0.tgz",
|
||||
"integrity": "sha1-bYCcnNDPe7iVLYD8hPoT1H3bEwg="
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
@@ -1723,6 +1752,11 @@
|
||||
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
|
||||
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
|
||||
},
|
||||
"dns-prefetch-control": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/dns-prefetch-control/-/dns-prefetch-control-0.1.0.tgz",
|
||||
"integrity": "sha1-YN20V3dOF48flBXwyrsOhbCzALI="
|
||||
},
|
||||
"doctrine": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
|
||||
@@ -1732,6 +1766,11 @@
|
||||
"esutils": "2.0.2"
|
||||
}
|
||||
},
|
||||
"dont-sniff-mimetype": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dont-sniff-mimetype/-/dont-sniff-mimetype-1.0.0.tgz",
|
||||
"integrity": "sha1-WTKJDcn04vGeXrAqIAJuXl78j1g="
|
||||
},
|
||||
"dot": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dot/-/dot-1.0.3.tgz",
|
||||
@@ -1774,15 +1813,23 @@
|
||||
"integrity": "sha1-RNZW3p2kFWlEZzNTZfsxR7hXK3w=",
|
||||
"dev": true
|
||||
},
|
||||
"ecdsa-sig-formatter": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz",
|
||||
"integrity": "sha1-HFlQAPBKiJffuFAAiSoPTDOvhsM=",
|
||||
"requires": {
|
||||
"safe-buffer": "5.1.2"
|
||||
}
|
||||
},
|
||||
"ee-first": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"electron-to-chromium": {
|
||||
"version": "1.3.45",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.45.tgz",
|
||||
"integrity": "sha1-RYrBscXHYM6IEaFtK/vZfsMLr7g=",
|
||||
"version": "1.3.47",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.47.tgz",
|
||||
"integrity": "sha1-dk6IfKkQTQGgrI6r7n38DizhQQQ=",
|
||||
"dev": true
|
||||
},
|
||||
"encodeurl": {
|
||||
@@ -2206,6 +2253,11 @@
|
||||
"os-homedir": "1.0.2"
|
||||
}
|
||||
},
|
||||
"expect-ct": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/expect-ct/-/expect-ct-0.1.1.tgz",
|
||||
"integrity": "sha512-ngXzTfoRGG7fYens3/RMb6yYoVLvLMfmsSllP/mZPxNHgFq41TmPSLF/nLY7fwoclI2vElvAmILFWGUYqdjfCg=="
|
||||
},
|
||||
"express": {
|
||||
"version": "4.16.3",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-4.16.3.tgz",
|
||||
@@ -2801,6 +2853,11 @@
|
||||
"map-cache": "0.2.2"
|
||||
}
|
||||
},
|
||||
"frameguard": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/frameguard/-/frameguard-3.0.0.tgz",
|
||||
"integrity": "sha1-e8rUae57lukdEs6zlZx4I1qScuk="
|
||||
},
|
||||
"fresh": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||
@@ -3600,6 +3657,42 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"helmet": {
|
||||
"version": "3.12.1",
|
||||
"resolved": "https://registry.npmjs.org/helmet/-/helmet-3.12.1.tgz",
|
||||
"integrity": "sha512-/CsAcbPIHgiGde395IkHUZyRLW126RJ6AtxFy6Y6bxhd44Qq8cZ5BBFZ0xNUSbcgX57j32Emh3OhWz/0XgAB5Q==",
|
||||
"requires": {
|
||||
"dns-prefetch-control": "0.1.0",
|
||||
"dont-sniff-mimetype": "1.0.0",
|
||||
"expect-ct": "0.1.1",
|
||||
"frameguard": "3.0.0",
|
||||
"helmet-csp": "2.7.0",
|
||||
"hide-powered-by": "1.0.0",
|
||||
"hpkp": "2.0.0",
|
||||
"hsts": "2.1.0",
|
||||
"ienoopen": "1.0.0",
|
||||
"nocache": "2.0.0",
|
||||
"referrer-policy": "1.1.0",
|
||||
"x-xss-protection": "1.1.0"
|
||||
}
|
||||
},
|
||||
"helmet-csp": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/helmet-csp/-/helmet-csp-2.7.0.tgz",
|
||||
"integrity": "sha512-IGIAkWnxjRbgMXFA2/kmDqSIrIaSfZ6vhMHlSHw7jm7Gm9nVVXqwJ2B1YEpYrJsLrqY+w2Bbimk7snux9+sZAw==",
|
||||
"requires": {
|
||||
"camelize": "1.0.0",
|
||||
"content-security-policy-builder": "2.0.0",
|
||||
"dasherize": "2.0.0",
|
||||
"lodash.reduce": "4.6.0",
|
||||
"platform": "1.3.5"
|
||||
}
|
||||
},
|
||||
"hide-powered-by": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/hide-powered-by/-/hide-powered-by-1.0.0.tgz",
|
||||
"integrity": "sha1-SoWtZYgfYoV/xwr3F0oRhNzM4ys="
|
||||
},
|
||||
"homedir-polyfill": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz",
|
||||
@@ -3615,6 +3708,16 @@
|
||||
"integrity": "sha512-lIbgIIQA3lz5XaB6vxakj6sDHADJiZadYEJB+FgA+C4nubM1NwcuvUr9EJPmnH1skZqpqUzWborWo8EIUi0Sdw==",
|
||||
"dev": true
|
||||
},
|
||||
"hpkp": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/hpkp/-/hpkp-2.0.0.tgz",
|
||||
"integrity": "sha1-EOFCJk52IVpdMMROxD3mTe5tFnI="
|
||||
},
|
||||
"hsts": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/hsts/-/hsts-2.1.0.tgz",
|
||||
"integrity": "sha512-zXhh/DqgrTXJ7erTN6Fh5k/xjMhDGXCqdYN3wvxUvGUQvnxcFfUd8E+6vLg/nk3ss1TYMb+DhRl25fYABioTvA=="
|
||||
},
|
||||
"http-errors": {
|
||||
"version": "1.6.3",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
|
||||
@@ -3635,6 +3738,11 @@
|
||||
"safer-buffer": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ienoopen": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ienoopen/-/ienoopen-1.0.0.tgz",
|
||||
"integrity": "sha1-NGpCj0dKrI9QzzeE6i0PFvYr2ms="
|
||||
},
|
||||
"ignore": {
|
||||
"version": "3.3.8",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.8.tgz",
|
||||
@@ -4117,6 +4225,30 @@
|
||||
"graceful-fs": "4.1.11"
|
||||
}
|
||||
},
|
||||
"jsonwebtoken": {
|
||||
"version": "8.2.1",
|
||||
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.2.1.tgz",
|
||||
"integrity": "sha512-l8rUBr0fqYYwPc8/ZGrue7GiW7vWdZtZqelxo4Sd5lMvuEeCK8/wS54sEo6tJhdZ6hqfutsj6COgC0d1XdbHGw==",
|
||||
"requires": {
|
||||
"jws": "3.1.5",
|
||||
"lodash.includes": "4.3.0",
|
||||
"lodash.isboolean": "3.0.3",
|
||||
"lodash.isinteger": "4.0.4",
|
||||
"lodash.isnumber": "3.0.3",
|
||||
"lodash.isplainobject": "4.0.6",
|
||||
"lodash.isstring": "4.0.1",
|
||||
"lodash.once": "4.1.1",
|
||||
"ms": "2.1.1",
|
||||
"xtend": "4.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"jsx-ast-utils": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz",
|
||||
@@ -4126,6 +4258,25 @@
|
||||
"array-includes": "3.0.3"
|
||||
}
|
||||
},
|
||||
"jwa": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.6.tgz",
|
||||
"integrity": "sha512-tBO/cf++BUsJkYql/kBbJroKOgHWEigTKBAjjBEmrMGYd1QMBC74Hr4Wo2zCZw6ZrVhlJPvoMrkcOnlWR/DJfw==",
|
||||
"requires": {
|
||||
"buffer-equal-constant-time": "1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.10",
|
||||
"safe-buffer": "5.1.2"
|
||||
}
|
||||
},
|
||||
"jws": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-3.1.5.tgz",
|
||||
"integrity": "sha512-GsCSexFADNQUr8T5HPJvayTjvPIfoyJPtLQBwn5a4WZQchcrPMPMAWcC1AzJVRDKyD6ZPROPAxgv6rfHViO4uQ==",
|
||||
"requires": {
|
||||
"jwa": "1.1.6",
|
||||
"safe-buffer": "5.1.2"
|
||||
}
|
||||
},
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
@@ -4217,6 +4368,46 @@
|
||||
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.includes": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
||||
"integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8="
|
||||
},
|
||||
"lodash.isboolean": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
|
||||
"integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY="
|
||||
},
|
||||
"lodash.isinteger": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
||||
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
|
||||
},
|
||||
"lodash.isnumber": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
|
||||
"integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w="
|
||||
},
|
||||
"lodash.isplainobject": {
|
||||
"version": "4.0.6",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
||||
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
|
||||
},
|
||||
"lodash.isstring": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
|
||||
"integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE="
|
||||
},
|
||||
"lodash.once": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
||||
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
|
||||
},
|
||||
"lodash.reduce": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.reduce/-/lodash.reduce-4.6.0.tgz",
|
||||
"integrity": "sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs="
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
|
||||
@@ -4238,9 +4429,9 @@
|
||||
"integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI="
|
||||
},
|
||||
"make-dir": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.2.0.tgz",
|
||||
"integrity": "sha512-aNUAa4UMg/UougV25bbrU4ZaaKNjJ/3/xnvg/twpmKROPdKZPZ9wGgI0opdZzO8q/zUFawoUuixuOv33eZ61Iw==",
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
||||
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"pify": "3.0.0"
|
||||
@@ -4471,6 +4662,11 @@
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
|
||||
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk="
|
||||
},
|
||||
"nocache": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/nocache/-/nocache-2.0.0.tgz",
|
||||
"integrity": "sha1-ICtIAhoMTL3i34DeFaF0Q8i0OYA="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
@@ -4482,9 +4678,9 @@
|
||||
}
|
||||
},
|
||||
"nodemon": {
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.17.3.tgz",
|
||||
"integrity": "sha512-8AtS+wA5u6qoE12LONjqOzUzxAI5ObzSw6U5LgqpaO/0y6wwId4l5dN0ZulYyYdpLZD1MbkBp7GjG1hqaoRqYg==",
|
||||
"version": "1.17.4",
|
||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.17.4.tgz",
|
||||
"integrity": "sha512-ZQcvYd8I4sWhbLoqImIiCPBTaHcq3YRRQXYwePchFK3Zk5+LT8HYQR4urf1UkSDiY/gSxjq6ao34RxJp7rRe1w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chokidar": "2.0.3",
|
||||
@@ -4547,8 +4743,7 @@
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
|
||||
"dev": true
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||
},
|
||||
"object-copy": {
|
||||
"version": "0.1.0",
|
||||
@@ -4864,6 +5059,11 @@
|
||||
"find-up": "1.1.2"
|
||||
}
|
||||
},
|
||||
"platform": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/platform/-/platform-1.3.5.tgz",
|
||||
"integrity": "sha512-TuvHS8AOIZNAlE77WUDiR4rySV/VMptyMfcfeoMgs4P8apaZM3JrnbzBiixKUv+XR6i+BXrQh8WAnjaSPFO65Q=="
|
||||
},
|
||||
"pluralize": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz",
|
||||
@@ -5135,10 +5335,15 @@
|
||||
"set-immediate-shim": "1.0.1"
|
||||
}
|
||||
},
|
||||
"referrer-policy": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/referrer-policy/-/referrer-policy-1.1.0.tgz",
|
||||
"integrity": "sha1-NXdOtzW/UPtsB46DM0tHI1AgfXk="
|
||||
},
|
||||
"regenerate": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.3.3.tgz",
|
||||
"integrity": "sha512-jVpo1GadrDAK59t/0jRx5VxYWQEDkkEKi6+HjE3joFVLfDOh9Xrdh0dF1eSq+BI/SwvTQ44gSscJ8N5zYL61sg==",
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.0.tgz",
|
||||
"integrity": "sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==",
|
||||
"dev": true
|
||||
},
|
||||
"regenerator-runtime": {
|
||||
@@ -5180,7 +5385,7 @@
|
||||
"integrity": "sha1-SdA4g3uNz4v6W5pCE5k45uoq4kA=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"regenerate": "1.3.3",
|
||||
"regenerate": "1.4.0",
|
||||
"regjsgen": "0.2.0",
|
||||
"regjsparser": "0.1.5"
|
||||
}
|
||||
@@ -5350,8 +5555,7 @@
|
||||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"dev": true
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||
},
|
||||
"safe-regex": {
|
||||
"version": "1.1.0",
|
||||
@@ -5523,7 +5727,7 @@
|
||||
"extend-shallow": "2.0.1",
|
||||
"map-cache": "0.2.2",
|
||||
"source-map": "0.5.7",
|
||||
"source-map-resolve": "0.5.1",
|
||||
"source-map-resolve": "0.5.2",
|
||||
"use": "3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -5634,9 +5838,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"source-map-resolve": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.1.tgz",
|
||||
"integrity": "sha512-0KW2wvzfxm8NCTb30z0LMNyPqWCdDGE2viwzUaucqJdkTRXtZiSY3I+2A6nVAjmdOy0I4gU8DwnVVGsk9jvP2A==",
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.5.2.tgz",
|
||||
"integrity": "sha512-MjqsvNwyz1s0k81Goz/9vRBe9SZdB09Bdw+/zYyO+3CuPk6fouTaxscHkgtE8jKvf01kVfl8riHzERQ/kefaSA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"atob": "2.1.1",
|
||||
@@ -6221,9 +6425,9 @@
|
||||
}
|
||||
},
|
||||
"upath": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/upath/-/upath-1.0.5.tgz",
|
||||
"integrity": "sha512-qbKn90aDQ0YEwvXoLqj0oiuUYroLX2lVHZ+b+xwjozFasAOC4GneDq5+OaIG5Zj+jFmbz/uO+f7a9qxjktJQww==",
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/upath/-/upath-1.1.0.tgz",
|
||||
"integrity": "sha512-bzpH/oBhoS/QI/YtbkqCg6VEiPYjSZtrHQM6/QnJS6OL9pKUFLqb3aFh4Scvwm45+7iAgiMkLhSbaZxUqmrprw==",
|
||||
"dev": true
|
||||
},
|
||||
"update-notifier": {
|
||||
@@ -6412,12 +6616,22 @@
|
||||
"signal-exit": "3.0.2"
|
||||
}
|
||||
},
|
||||
"x-xss-protection": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/x-xss-protection/-/x-xss-protection-1.1.0.tgz",
|
||||
"integrity": "sha512-rx3GzJlgEeZ08MIcDsU2vY2B1QEriUKJTSiNHHUIem6eg9pzVOr2TL3Y4Pd6TMAM5D5azGjcxqI62piITBDHVg=="
|
||||
},
|
||||
"xdg-basedir": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-3.0.0.tgz",
|
||||
"integrity": "sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ=",
|
||||
"dev": true
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
|
||||
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
|
||||
},
|
||||
"y18n": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
|
||||
|
||||
+16
-30
@@ -5,7 +5,8 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "flow-remove-types src/ -d out/",
|
||||
"buildWithMaps": "flow-remove-types src/ -d out/ --pretty --sourcemaps",
|
||||
"buildWithMaps":
|
||||
"flow-remove-types src/ -d out/ --pretty --sourcemaps",
|
||||
"start": "npm run build && node out/doroundmath.js",
|
||||
"start-db": "npm run build && node out/dbaccess.js",
|
||||
"nodemon": "nodemon --watch src --delay 1 --exec npm start",
|
||||
@@ -19,10 +20,7 @@
|
||||
"author": "Federico Kereki",
|
||||
"license": "ISC",
|
||||
"babel": {
|
||||
"presets": [
|
||||
"env",
|
||||
"flow"
|
||||
]
|
||||
"presets": ["env", "node", "flow"]
|
||||
},
|
||||
"eslintConfig": {
|
||||
"parserOptions": {
|
||||
@@ -34,37 +32,22 @@
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:flowtype/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"babel",
|
||||
"flowtype"
|
||||
],
|
||||
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
|
||||
"plugins": ["babel", "flowtype"],
|
||||
"rules": {
|
||||
"no-console": "off",
|
||||
"no-var": "error",
|
||||
"prefer-const": "error"
|
||||
"prefer-const": "error",
|
||||
"flowtype/no-types-missing-file-annotation": 0
|
||||
}
|
||||
},
|
||||
"eslintIgnore": [
|
||||
"**/out/*.js"
|
||||
],
|
||||
"eslintIgnore": ["**/out/*.js"],
|
||||
"flow-coverage-report": {
|
||||
"concurrentFiles": 1,
|
||||
"excludeGlob": [
|
||||
"node_modules/**"
|
||||
],
|
||||
"includeGlob": [
|
||||
"src/**/*.js"
|
||||
],
|
||||
"excludeGlob": ["node_modules/**"],
|
||||
"includeGlob": ["src/**/*.js"],
|
||||
"threshold": 90,
|
||||
"type": [
|
||||
"text",
|
||||
"html",
|
||||
"json"
|
||||
]
|
||||
"type": ["text", "html", "json"]
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 4,
|
||||
@@ -72,12 +55,15 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"cors": "^2.8.4",
|
||||
"express": "^4.16.3",
|
||||
"helmet": "^3.12.1",
|
||||
"jsonwebtoken": "^8.2.1",
|
||||
"mariasql": "^0.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^8.2.2",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-flow": "^6.23.0",
|
||||
"eslint": "^4.19.0",
|
||||
"eslint-config-recommended": "^2.0.0",
|
||||
@@ -86,7 +72,7 @@
|
||||
"flow-coverage-report": "^0.5.0",
|
||||
"flow-remove-types": "^1.2.3",
|
||||
"flow-typed": "^2.4.0",
|
||||
"nodemon": "^1.17.3",
|
||||
"nodemon": "^1.17.4",
|
||||
"prettier": "^1.11.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<html>
|
||||
|
||||
<head></head>
|
||||
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
const req = new XMLHttpRequest();
|
||||
req.open('GET', 'http://www.corsserver.com:8080/', true);
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState === 4) {
|
||||
if (req.status >= 200 && req.status < 400) {
|
||||
console.log(req.responseText)
|
||||
} else {
|
||||
console.warn("Problems!")
|
||||
}
|
||||
}
|
||||
};
|
||||
req.setRequestHeader("dummy", "value");
|
||||
req.send();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,15 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.get("/", (req, res) => res.send("Server alive, with CORS!"));
|
||||
|
||||
app.listen(8080, () =>
|
||||
console.log("CORS server ready at http://localhost:8080/!")
|
||||
);
|
||||
@@ -6,4 +6,8 @@ const app = express();
|
||||
|
||||
app.get("/", (req, res) => res.send("Server alive, with Express!"));
|
||||
|
||||
app.listen(8080, () => console.log("Mini server (with Express) ready at http://localhost:8080/!"));
|
||||
app.listen(8080, () =>
|
||||
console.log(
|
||||
"Mini server (with Express) ready at http://localhost:8080/!"
|
||||
)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
const helmet = require("helmet");
|
||||
app.use(helmet());
|
||||
|
||||
app.get("/", (req, res) => res.send("Server alive, with Express!"));
|
||||
|
||||
app.listen(8081, () =>
|
||||
console.log(
|
||||
"Mini server (with Express) ready at http://localhost:8080/!"
|
||||
)
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const http = require("http");
|
||||
|
||||
http.createServer(app).listen(8080);
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.secure) {
|
||||
next();
|
||||
} else {
|
||||
res.redirect(
|
||||
`https://${req.headers.host.replace(/8080/, "8443")}${req.url}`
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const https = require("https");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const keysPath = path.join(__dirname, "../../certificates");
|
||||
const ca = fs.readFileSync(`${keysPath}/modernjsbook.csr`);
|
||||
const cert = fs.readFileSync(`${keysPath}/modernjsbook.crt`);
|
||||
const key = fs.readFileSync(`${keysPath}/modernjsbook.key`);
|
||||
|
||||
https.createServer({ ca, cert, key }, app).listen(8443);
|
||||
|
||||
app.get("/", (req, res) => res.send("Secure server!"));
|
||||
@@ -0,0 +1,69 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const jwt = require("jsonwebtoken");
|
||||
const bodyParser = require("body-parser");
|
||||
|
||||
const validateUser = require("./validate_user.js");
|
||||
|
||||
const SECRET_JWT_KEY = "modernJSbook";
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
|
||||
app.get("/public", (req, res) => {
|
||||
res.send("the /public endpoint needs no token!");
|
||||
});
|
||||
|
||||
app.post("/gettoken", (req, res) => {
|
||||
validateUser(req.body.user, req.body.password, (idErr, userid) => {
|
||||
if (idErr !== null) {
|
||||
res.status(401).send(idErr);
|
||||
} else {
|
||||
jwt.sign(
|
||||
{ userid },
|
||||
SECRET_JWT_KEY,
|
||||
{ algorithm: "HS256", expiresIn: "1h" },
|
||||
(err, token) => res.status(200).send(token)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
// First check for the Authorization header
|
||||
const authHeader = req.headers.authorization;
|
||||
if (!authHeader || !authHeader.startsWith("Bearer")) {
|
||||
return res.status(401).send("No token specified");
|
||||
}
|
||||
|
||||
// Now validate the token itself
|
||||
const token = authHeader.split(" ")[1];
|
||||
|
||||
jwt.verify(token, SECRET_JWT_KEY, (err, decoded) => {
|
||||
if (err) {
|
||||
// Token bad formed, or expired, or other problem
|
||||
return res.status(403).send("Token expired or not valid");
|
||||
} else {
|
||||
// Token OK; get the user id from it
|
||||
req.userid = decoded.userid;
|
||||
// Keep processing the request
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/private", (req, res) => {
|
||||
res.send("the /private endpoint needs JWT, but it was provided: OK!");
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
console.error("Error....", err.message);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
app.listen(8080, () =>
|
||||
console.log("Mini JWT server ready, at http://localhost:8080/!")
|
||||
);
|
||||
@@ -0,0 +1,171 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
// eslint-disable
|
||||
|
||||
const getCity = async (res: any, dbConn: any, city: string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
let sqlQuery = "";
|
||||
sqlQuery = `
|
||||
SELECT *
|
||||
FROM cities
|
||||
WHERE cityId=?
|
||||
`;
|
||||
|
||||
const cities = await dbConn.query(sqlQuery, [city]);
|
||||
if (cities.length === 0) {
|
||||
res.status(404).send("City not found");
|
||||
} else {
|
||||
res
|
||||
.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(cities));
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteCity = async (res: any, dbConn: any, city: string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
const deleteCity = `
|
||||
DELETE FROM cities
|
||||
WHERE cityId=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteCity, [city]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("City not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const postCity = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
name: string,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
population: number,
|
||||
country: string,
|
||||
region: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlRegion = `
|
||||
SELECT 1
|
||||
FROM regions
|
||||
WHERE countryCode=? AND regionCode=?
|
||||
`;
|
||||
const regions = await dbConn.query(sqlRegion, [country, region]);
|
||||
if (regions.length === 0) {
|
||||
res.status(403).send("Region must exist");
|
||||
return;
|
||||
}
|
||||
|
||||
const sqlGetId = `
|
||||
SELECT MAX(CAST(cityId AS INTEGER)) AS maxr
|
||||
FROM cities
|
||||
`;
|
||||
const cities = await dbConn.query(sqlGetId);
|
||||
const newId = cities.length === 0 ? 1 : 1 + Number(cities[0].maxr);
|
||||
|
||||
const sqlAddCity = `
|
||||
INSERT INTO cities SET
|
||||
cityId=?
|
||||
cityName=?,
|
||||
latitude=?,
|
||||
longitude=?,
|
||||
population=?,
|
||||
countryCode=?,
|
||||
regionCode=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlAddCity, [
|
||||
newId,
|
||||
name,
|
||||
latitude,
|
||||
longitude,
|
||||
population,
|
||||
country,
|
||||
region
|
||||
]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res
|
||||
.status(201)
|
||||
.header("Location", `/cities/${newId}`)
|
||||
.send("City created");
|
||||
} else {
|
||||
res.status(409).send("City not created");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const putCity = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
city: string,
|
||||
name: string,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
population: number,
|
||||
country: string,
|
||||
region: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlUpdateCity = `
|
||||
UPDATE cities
|
||||
SET
|
||||
cityName=?,
|
||||
latitude=?,
|
||||
longitude=?,
|
||||
population=?,
|
||||
countryCode=?,
|
||||
regionCode=?
|
||||
WHERE cityId=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlUpdateCity, [
|
||||
name,
|
||||
latitude,
|
||||
longitude,
|
||||
population,
|
||||
country,
|
||||
region,
|
||||
city
|
||||
]);
|
||||
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(409).send("City not updated");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getCity, deleteCity, postCity, putCity };
|
||||
@@ -0,0 +1,107 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const getCountry = async (res: any, dbConn: any, country: ?string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
let sqlQuery = "";
|
||||
let countries;
|
||||
if (country == null) {
|
||||
sqlQuery = `
|
||||
SELECT cc.*
|
||||
FROM countries cc
|
||||
ORDER BY cc.countryCode
|
||||
`;
|
||||
countries = await dbConn.query(sqlQuery);
|
||||
} else {
|
||||
sqlQuery = `
|
||||
SELECT cc.*
|
||||
FROM countries cc
|
||||
WHERE cc.countryCode=?
|
||||
`;
|
||||
countries = await dbConn.query(sqlQuery, [country]);
|
||||
}
|
||||
|
||||
if (countries.length > 0) {
|
||||
res
|
||||
.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(countries));
|
||||
} else {
|
||||
res.status(404).send("Not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteCountry = async (res: any, dbConn: any, country: string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
const sqlRegions = `
|
||||
SELECT 1 FROM regions
|
||||
WHERE countryCode=?
|
||||
LIMIT 1
|
||||
`;
|
||||
const regions = await dbConn.query(sqlRegions, [country]);
|
||||
if (regions.length > 0) {
|
||||
res.status(405).send("Cannot delete a country with regions");
|
||||
return;
|
||||
}
|
||||
|
||||
const deleteCountry = `
|
||||
DELETE FROM countries
|
||||
WHERE countryCode=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteCountry, [country]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("Country not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const putCountry = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
name: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlInsertOrUpdateCountry = `
|
||||
INSERT INTO countries (countryCode, countryName)
|
||||
VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
countryName = ?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlInsertOrUpdateCountry, [
|
||||
country,
|
||||
name,
|
||||
name
|
||||
]);
|
||||
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(409).send("Country not updated");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getCountry, deleteCountry, putCountry };
|
||||
@@ -0,0 +1,20 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const mariaSQL = require("mariasql");
|
||||
const { promisify } = require("util");
|
||||
|
||||
const DB_HOST = "127.0.0.1";
|
||||
const DB_USER = "fkereki";
|
||||
const DB_PASS = "modernJS!!";
|
||||
const DB_SCHEMA = "world";
|
||||
|
||||
const getDbConnection = (host, user, password, db) => {
|
||||
const dbConn = new mariaSQL({ host, user, password, db });
|
||||
dbConn.query = promisify(dbConn.query);
|
||||
return dbConn;
|
||||
};
|
||||
|
||||
const dbConn = getDbConnection(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA);
|
||||
|
||||
module.exports = dbConn;
|
||||
@@ -0,0 +1,206 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const getRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: ?string,
|
||||
region: ?string
|
||||
) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
let sqlQuery = "";
|
||||
let regions;
|
||||
if (country == null) {
|
||||
sqlQuery = `
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
ORDER BY cc.countryCode, rr.regionCode
|
||||
`;
|
||||
regions = await dbConn.query(sqlQuery);
|
||||
} else if (region == null) {
|
||||
sqlQuery = `
|
||||
SELECT 1
|
||||
FROM countries
|
||||
WHERE countryCode=?
|
||||
`;
|
||||
|
||||
const countries = await dbConn.query(sqlQuery, [country]);
|
||||
if (countries.length === 0) {
|
||||
res.status(404).send("Country not found");
|
||||
return;
|
||||
}
|
||||
|
||||
sqlQuery = `
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
WHERE rr.countryCode=?
|
||||
ORDER BY rr.regionCode
|
||||
`;
|
||||
regions = await dbConn.query(sqlQuery, [country]);
|
||||
} else {
|
||||
sqlQuery = `
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
WHERE rr.countryCode=?
|
||||
AND rr.regionCode=?
|
||||
`;
|
||||
regions = await dbConn.query(sqlQuery, [country, region]);
|
||||
}
|
||||
|
||||
if (regions.length > 0 || region === null) {
|
||||
res
|
||||
.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(regions));
|
||||
} else {
|
||||
res.status(404).send("Not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
region: string
|
||||
) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
const sqlCities = `
|
||||
SELECT 1 FROM cities
|
||||
WHERE countryCode=?
|
||||
AND regionCode=?
|
||||
LIMIT 1
|
||||
`;
|
||||
const cities = await dbConn.query(sqlCities, [country, region]);
|
||||
if (cities.length > 0) {
|
||||
res.status(405).send("Cannot delete a region with cities");
|
||||
return;
|
||||
}
|
||||
|
||||
const deleteRegion = `
|
||||
DELETE FROM regions
|
||||
WHERE countryCode=?
|
||||
AND regionCode=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteRegion, [country, region]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("Region not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const postRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
name: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlCountry = `
|
||||
SELECT 1
|
||||
FROM countries
|
||||
WHERE countryCode=?
|
||||
`;
|
||||
const countries = await dbConn.query(sqlCountry, [country]);
|
||||
if (countries.length === 0) {
|
||||
res.status(403).send("Country must exist");
|
||||
return;
|
||||
}
|
||||
|
||||
const sqlGetId = `
|
||||
SELECT MAX(CAST(regionCode AS INTEGER)) AS maxr
|
||||
FROM regions
|
||||
WHERE countryCode=?
|
||||
`;
|
||||
const regions = await dbConn.query(sqlGetId, [country]);
|
||||
const newId =
|
||||
regions.length === 0 ? 1 : 1 + Number(regions[0].maxr);
|
||||
|
||||
const sqlAddRegion = `
|
||||
INSERT INTO regions SET
|
||||
countryCode=?,
|
||||
regionCode=?,
|
||||
regionName=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlAddRegion, [
|
||||
country,
|
||||
newId,
|
||||
name
|
||||
]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res
|
||||
.status(201)
|
||||
.header("Location", `/regions/${country}/${newId}`)
|
||||
.send("Region created");
|
||||
} else {
|
||||
res.status(409).send("Region not created");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const putRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
region: string,
|
||||
name: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlUpdateRegion = `
|
||||
UPDATE regions
|
||||
SET regionName=?
|
||||
WHERE countryCode=?
|
||||
AND regionCode=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlUpdateRegion, [
|
||||
name,
|
||||
country,
|
||||
region
|
||||
]);
|
||||
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(409).send("Region not updated");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getRegion, deleteRegion, postRegion, putRegion };
|
||||
@@ -0,0 +1,147 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const bodyParser = require("body-parser");
|
||||
|
||||
const dbConn = require("./restful_db.js");
|
||||
|
||||
app.get("/", (req, res) => res.send("Secure server!"));
|
||||
|
||||
/*
|
||||
Add here the logic for CORS
|
||||
|
||||
const cors = require("cors");
|
||||
app.use(cors());
|
||||
*/
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
|
||||
/*
|
||||
Add here the logic for providing a JWT at /gettoken
|
||||
and the logic for validating a JWT, as shown earlier
|
||||
*/
|
||||
|
||||
const {
|
||||
getCountry,
|
||||
deleteCountry,
|
||||
putCountry
|
||||
} = require("./restful_countries.js");
|
||||
|
||||
app.get("/countries", (req, res) => getCountry(res, dbConn));
|
||||
|
||||
app.get("/countries/:country", (req, res) =>
|
||||
getCountry(res, dbConn, req.params.country)
|
||||
);
|
||||
|
||||
app.delete("/countries/:country", (req, res) =>
|
||||
deleteCountry(res, dbConn, req.params.country)
|
||||
);
|
||||
|
||||
app.put("/countries/:country", (req, res) =>
|
||||
putCountry(res, dbConn, req.params.country, req.body.name)
|
||||
);
|
||||
|
||||
const {
|
||||
getRegion,
|
||||
deleteRegion,
|
||||
postRegion,
|
||||
putRegion
|
||||
} = require("./restful_regions.js");
|
||||
|
||||
app.get("/regions", (req, res) => getRegion(res, dbConn));
|
||||
|
||||
app.get("/regions/:country", (req, res) =>
|
||||
getRegion(res, dbConn, req.params.country)
|
||||
);
|
||||
|
||||
app.get("/regions/:country/:region", (req, res) =>
|
||||
getRegion(res, dbConn, req.params.country, req.params.region)
|
||||
);
|
||||
|
||||
app.delete("/regions/:country/:region", (req, res) =>
|
||||
deleteRegion(res, dbConn, req.params.country, req.params.region)
|
||||
);
|
||||
|
||||
app.post("/regions/:country", (req, res) =>
|
||||
postRegion(res, dbConn, req.params.country, req.body.name)
|
||||
);
|
||||
|
||||
app.put("/regions/:country/:region", (req, res) =>
|
||||
putRegion(
|
||||
res,
|
||||
dbConn,
|
||||
req.params.country,
|
||||
req.params.region,
|
||||
req.body.name
|
||||
)
|
||||
);
|
||||
|
||||
const {
|
||||
getCity,
|
||||
deleteCity,
|
||||
postCity,
|
||||
putCity
|
||||
} = require("./restful_cities.js");
|
||||
|
||||
// We do not allow calling /cities to get every city in the world
|
||||
|
||||
app.get("/cities/:city", (req, res) =>
|
||||
getCity(res, dbConn, req.params.city)
|
||||
);
|
||||
|
||||
app.delete("/cities/:city", (req, res) =>
|
||||
deleteCity(res, dbConn, req.params.city)
|
||||
);
|
||||
|
||||
app.post("/cities/:city", (req, res) =>
|
||||
postCity(
|
||||
res,
|
||||
dbConn,
|
||||
req.body.name,
|
||||
req.body.latitude,
|
||||
req.body.longitude,
|
||||
req.body.population,
|
||||
req.body.country,
|
||||
req.body.region
|
||||
)
|
||||
);
|
||||
|
||||
app.put("/cities/:city", (req, res) =>
|
||||
putCity(
|
||||
res,
|
||||
dbConn,
|
||||
req.params.city,
|
||||
req.body.name,
|
||||
req.body.latitude,
|
||||
req.body.longitude,
|
||||
req.body.population,
|
||||
req.body.country,
|
||||
req.body.region
|
||||
)
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
console.error("Error....", err.message);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
/*
|
||||
Add here the logic for HTTPS
|
||||
|
||||
const https = require("https");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const keysPath = path.join(__dirname, "../../certificates");
|
||||
const ca = fs.readFileSync(`${keysPath}/modernjsbook.csr`);
|
||||
const cert = fs.readFileSync(`${keysPath}/modernjsbook.crt`);
|
||||
const key = fs.readFileSync(`${keysPath}/modernjsbook.key`);
|
||||
|
||||
https.createServer({ ca, cert, key }, app);
|
||||
|
||||
*/
|
||||
app.listen(8080, () =>
|
||||
console.log("Routing ready at http://localhost:8080")
|
||||
);
|
||||
@@ -7,7 +7,7 @@ const app = express();
|
||||
|
||||
app.get("/", (req, res) => res.send("Server alive, with Express!"));
|
||||
|
||||
app.get(
|
||||
app.use(
|
||||
"/static",
|
||||
express.static(path.join(__dirname, "../flags"), {
|
||||
immutable: true,
|
||||
@@ -15,6 +15,7 @@ app.get(
|
||||
})
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
console.error("Error....", err.message);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
In real life, validateUser could check a database,
|
||||
look into an Active Directory, call another service,
|
||||
etc. -- but for this demo, let's keep it quite
|
||||
simple and only accept a single hardcoded user.
|
||||
*/
|
||||
|
||||
const validateUser = (
|
||||
userName: string,
|
||||
password: string,
|
||||
callback: (?string, ?string) => void
|
||||
) => {
|
||||
if (!userName || !password) {
|
||||
callback("Missing user/password", null);
|
||||
} else if (userName === "fkereki" && password === "modernjsbook") {
|
||||
callback(null, "fkereki"); // OK, send userName back
|
||||
} else {
|
||||
callback("Not valid user", null);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = validateUser;
|
||||
@@ -0,0 +1,14 @@
|
||||
[ignore]
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
|
||||
[lints]
|
||||
all=warn
|
||||
unsafe-getters-setters=off
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
|
||||
[strict]
|
||||
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<coverage generated="1527819763397" clover="3.2.0">
|
||||
<project timestamp="1527819763397" name="All files">
|
||||
<metrics statements="77" coveredstatements="35" conditionals="36" coveredconditionals="14" methods="11" coveredmethods="5" elements="124" coveredelements="54" complexity="0" loc="77" ncloc="77" packages="1" files="3" classes="3">
|
||||
<file name="restful_regions.js" path="/home/fkereki/MODERNJS/chapter05/out/restful_regions.js">
|
||||
<metrics statements="57" coveredstatements="15" conditionals="26" coveredconditionals="4" methods="4" coveredmethods="1"/>
|
||||
<line num="4" count="1" type="stmt"/>
|
||||
<line num="10" count="0" type="stmt"/>
|
||||
<line num="11" count="0" type="stmt"/>
|
||||
<line num="12" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="13" count="0" type="stmt"/>
|
||||
<line num="20" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="21" count="0" type="stmt"/>
|
||||
<line num="27" count="0" type="stmt"/>
|
||||
<line num="28" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="29" count="0" type="stmt"/>
|
||||
<line num="32" count="0" type="stmt"/>
|
||||
<line num="41" count="0" type="stmt"/>
|
||||
<line num="51" count="0" type="stmt"/>
|
||||
<line num="52" count="0" type="cond" truecount="0" falsecount="4"/>
|
||||
<line num="53" count="0" type="stmt"/>
|
||||
<line num="58" count="0" type="stmt"/>
|
||||
<line num="61" count="0" type="stmt"/>
|
||||
<line num="65" count="1" type="stmt"/>
|
||||
<line num="71" count="3" type="stmt"/>
|
||||
<line num="72" count="3" type="stmt"/>
|
||||
<line num="78" count="3" type="stmt"/>
|
||||
<line num="79" count="3" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="80" count="1" type="stmt"/>
|
||||
<line num="82" count="2" type="stmt"/>
|
||||
<line num="88" count="2" type="stmt"/>
|
||||
<line num="89" count="2" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="90" count="1" type="stmt"/>
|
||||
<line num="92" count="1" type="stmt"/>
|
||||
<line num="96" count="0" type="stmt"/>
|
||||
<line num="100" count="1" type="stmt"/>
|
||||
<line num="106" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="107" count="0" type="stmt"/>
|
||||
<line num="110" count="0" type="stmt"/>
|
||||
<line num="111" count="0" type="stmt"/>
|
||||
<line num="116" count="0" type="stmt"/>
|
||||
<line num="117" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="118" count="0" type="stmt"/>
|
||||
<line num="121" count="0" type="stmt"/>
|
||||
<line num="126" count="0" type="stmt"/>
|
||||
<line num="128" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="130" count="0" type="stmt"/>
|
||||
<line num="137" count="0" type="stmt"/>
|
||||
<line num="138" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="139" count="0" type="stmt"/>
|
||||
<line num="144" count="0" type="stmt"/>
|
||||
<line num="147" count="0" type="stmt"/>
|
||||
<line num="151" count="1" type="stmt"/>
|
||||
<line num="158" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="159" count="0" type="stmt"/>
|
||||
<line num="162" count="0" type="stmt"/>
|
||||
<line num="163" count="0" type="stmt"/>
|
||||
<line num="170" count="0" type="stmt"/>
|
||||
<line num="172" count="0" type="cond" truecount="0" falsecount="2"/>
|
||||
<line num="173" count="0" type="stmt"/>
|
||||
<line num="175" count="0" type="stmt"/>
|
||||
<line num="178" count="0" type="stmt"/>
|
||||
<line num="182" count="1" type="stmt"/>
|
||||
</file>
|
||||
<file name="roundmath.js" path="/home/fkereki/MODERNJS/chapter05/out/roundmath.js">
|
||||
<metrics statements="13" coveredstatements="13" conditionals="2" coveredconditionals="2" methods="6" coveredmethods="3"/>
|
||||
<line num="6" count="3" type="stmt"/>
|
||||
<line num="8" count="1" type="stmt"/>
|
||||
<line num="12" count="2" type="stmt"/>
|
||||
<line num="14" count="1" type="stmt"/>
|
||||
<line num="16" count="1" type="stmt"/>
|
||||
<line num="18" count="1" type="stmt"/>
|
||||
<line num="19" count="2" type="cond" truecount="2" falsecount="0"/>
|
||||
<line num="20" count="1" type="stmt"/>
|
||||
<line num="22" count="1" type="stmt"/>
|
||||
<line num="31" count="1" type="stmt"/>
|
||||
<line num="32" count="1" type="stmt"/>
|
||||
<line num="33" count="1" type="stmt"/>
|
||||
<line num="34" count="1" type="stmt"/>
|
||||
</file>
|
||||
<file name="validate_user.js" path="/home/fkereki/MODERNJS/chapter05/out/validate_user.js">
|
||||
<metrics statements="7" coveredstatements="7" conditionals="8" coveredconditionals="8" methods="1" coveredmethods="1"/>
|
||||
<line num="11" count="1" type="stmt"/>
|
||||
<line num="16" count="3" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="17" count="1" type="stmt"/>
|
||||
<line num="18" count="2" type="cond" truecount="4" falsecount="0"/>
|
||||
<line num="19" count="1" type="stmt"/>
|
||||
<line num="21" count="1" type="stmt"/>
|
||||
<line num="25" count="1" type="stmt"/>
|
||||
</file>
|
||||
</metrics>
|
||||
</project>
|
||||
</coverage>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,223 @@
|
||||
body, html {
|
||||
margin:0; padding: 0;
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
font-family: Helvetica Neue, Helvetica, Arial;
|
||||
font-size: 14px;
|
||||
color:#333;
|
||||
}
|
||||
.small { font-size: 12px; }
|
||||
*, *:after, *:before {
|
||||
-webkit-box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
box-sizing:border-box;
|
||||
}
|
||||
h1 { font-size: 20px; margin: 0;}
|
||||
h2 { font-size: 14px; }
|
||||
pre {
|
||||
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
-moz-tab-size: 2;
|
||||
-o-tab-size: 2;
|
||||
tab-size: 2;
|
||||
}
|
||||
a { color:#0074D9; text-decoration:none; }
|
||||
a:hover { text-decoration:underline; }
|
||||
.strong { font-weight: bold; }
|
||||
.space-top1 { padding: 10px 0 0 0; }
|
||||
.pad2y { padding: 20px 0; }
|
||||
.pad1y { padding: 10px 0; }
|
||||
.pad2x { padding: 0 20px; }
|
||||
.pad2 { padding: 20px; }
|
||||
.pad1 { padding: 10px; }
|
||||
.space-left2 { padding-left:55px; }
|
||||
.space-right2 { padding-right:20px; }
|
||||
.center { text-align:center; }
|
||||
.clearfix { display:block; }
|
||||
.clearfix:after {
|
||||
content:'';
|
||||
display:block;
|
||||
height:0;
|
||||
clear:both;
|
||||
visibility:hidden;
|
||||
}
|
||||
.fl { float: left; }
|
||||
@media only screen and (max-width:640px) {
|
||||
.col3 { width:100%; max-width:100%; }
|
||||
.hide-mobile { display:none!important; }
|
||||
}
|
||||
|
||||
.quiet {
|
||||
color: #7f7f7f;
|
||||
color: rgba(0,0,0,0.5);
|
||||
}
|
||||
.quiet a { opacity: 0.7; }
|
||||
|
||||
.fraction {
|
||||
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
||||
font-size: 10px;
|
||||
color: #555;
|
||||
background: #E8E8E8;
|
||||
padding: 4px 5px;
|
||||
border-radius: 3px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.path a:link, div.path a:visited { color: #333; }
|
||||
table.coverage {
|
||||
border-collapse: collapse;
|
||||
margin: 10px 0 0 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
table.coverage td {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
vertical-align: top;
|
||||
}
|
||||
table.coverage td.line-count {
|
||||
text-align: right;
|
||||
padding: 0 5px 0 20px;
|
||||
}
|
||||
table.coverage td.line-coverage {
|
||||
text-align: right;
|
||||
padding-right: 10px;
|
||||
min-width:20px;
|
||||
}
|
||||
|
||||
table.coverage td span.cline-any {
|
||||
display: inline-block;
|
||||
padding: 0 5px;
|
||||
width: 100%;
|
||||
}
|
||||
.missing-if-branch {
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
border-radius: 3px;
|
||||
position: relative;
|
||||
padding: 0 4px;
|
||||
background: #333;
|
||||
color: yellow;
|
||||
}
|
||||
|
||||
.skip-if-branch {
|
||||
display: none;
|
||||
margin-right: 10px;
|
||||
position: relative;
|
||||
padding: 0 4px;
|
||||
background: #ccc;
|
||||
color: white;
|
||||
}
|
||||
.missing-if-branch .typ, .skip-if-branch .typ {
|
||||
color: inherit !important;
|
||||
}
|
||||
.coverage-summary {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
.coverage-summary tr { border-bottom: 1px solid #bbb; }
|
||||
.keyline-all { border: 1px solid #ddd; }
|
||||
.coverage-summary td, .coverage-summary th { padding: 10px; }
|
||||
.coverage-summary tbody { border: 1px solid #bbb; }
|
||||
.coverage-summary td { border-right: 1px solid #bbb; }
|
||||
.coverage-summary td:last-child { border-right: none; }
|
||||
.coverage-summary th {
|
||||
text-align: left;
|
||||
font-weight: normal;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.coverage-summary th.file { border-right: none !important; }
|
||||
.coverage-summary th.pct { }
|
||||
.coverage-summary th.pic,
|
||||
.coverage-summary th.abs,
|
||||
.coverage-summary td.pct,
|
||||
.coverage-summary td.abs { text-align: right; }
|
||||
.coverage-summary td.file { white-space: nowrap; }
|
||||
.coverage-summary td.pic { min-width: 120px !important; }
|
||||
.coverage-summary tfoot td { }
|
||||
|
||||
.coverage-summary .sorter {
|
||||
height: 10px;
|
||||
width: 7px;
|
||||
display: inline-block;
|
||||
margin-left: 0.5em;
|
||||
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
|
||||
}
|
||||
.coverage-summary .sorted .sorter {
|
||||
background-position: 0 -20px;
|
||||
}
|
||||
.coverage-summary .sorted-desc .sorter {
|
||||
background-position: 0 -10px;
|
||||
}
|
||||
.status-line { height: 10px; }
|
||||
/* yellow */
|
||||
.cbranch-no { background: yellow !important; color: #111; }
|
||||
/* dark red */
|
||||
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
|
||||
.low .chart { border:1px solid #C21F39 }
|
||||
.highlighted,
|
||||
.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{
|
||||
background: #C21F39 !important;
|
||||
}
|
||||
/* medium red */
|
||||
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
|
||||
/* light red */
|
||||
.low, .cline-no { background:#FCE1E5 }
|
||||
/* light green */
|
||||
.high, .cline-yes { background:rgb(230,245,208) }
|
||||
/* medium green */
|
||||
.cstat-yes { background:rgb(161,215,106) }
|
||||
/* dark green */
|
||||
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
|
||||
.high .chart { border:1px solid rgb(77,146,33) }
|
||||
|
||||
.medium .chart { border:1px solid #666; }
|
||||
.medium .cover-fill { background: #666; }
|
||||
|
||||
.cstat-skip { background: #ddd; color: #111; }
|
||||
.fstat-skip { background: #ddd; color: #111 !important; }
|
||||
.cbranch-skip { background: #ddd !important; color: #111; }
|
||||
|
||||
span.cline-neutral { background: #eaeaea; }
|
||||
.medium { background: #eaeaea; }
|
||||
|
||||
.coverage-summary td.empty {
|
||||
opacity: .5;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
line-height: 1;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.cover-fill, .cover-empty {
|
||||
display:inline-block;
|
||||
height: 12px;
|
||||
}
|
||||
.chart {
|
||||
line-height: 0;
|
||||
}
|
||||
.cover-empty {
|
||||
background: white;
|
||||
}
|
||||
.cover-full {
|
||||
border-right: none !important;
|
||||
}
|
||||
pre.prettyprint {
|
||||
border: none !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
}
|
||||
.com { color: #999 !important; }
|
||||
.ignore-none { color: #999; font-weight: normal; }
|
||||
|
||||
.wrapper {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
margin: 0 auto -48px;
|
||||
}
|
||||
.footer, .push {
|
||||
height: 48px;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
var jumpToCode = (function init () {
|
||||
// Classes of code we would like to highlight
|
||||
var missingCoverageClasses = [ '.cbranch-no', '.cstat-no', '.fstat-no' ];
|
||||
|
||||
// We don't want to select elements that are direct descendants of another match
|
||||
var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > `
|
||||
|
||||
// Selecter that finds elements on the page to which we can jump
|
||||
var selector = notSelector + missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b`
|
||||
|
||||
// The NodeList of matching elements
|
||||
var missingCoverageElements = document.querySelectorAll(selector);
|
||||
|
||||
var currentIndex;
|
||||
|
||||
function toggleClass(index) {
|
||||
missingCoverageElements.item(currentIndex).classList.remove('highlighted');
|
||||
missingCoverageElements.item(index).classList.add('highlighted');
|
||||
}
|
||||
|
||||
function makeCurrent(index) {
|
||||
toggleClass(index);
|
||||
currentIndex = index;
|
||||
missingCoverageElements.item(index)
|
||||
.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
|
||||
}
|
||||
|
||||
function goToPrevious() {
|
||||
var nextIndex = 0;
|
||||
if (typeof currentIndex !== 'number' || currentIndex === 0) {
|
||||
nextIndex = missingCoverageElements.length - 1;
|
||||
} else if (missingCoverageElements.length > 1) {
|
||||
nextIndex = currentIndex - 1;
|
||||
}
|
||||
|
||||
makeCurrent(nextIndex);
|
||||
}
|
||||
|
||||
function goToNext() {
|
||||
var nextIndex = 0;
|
||||
|
||||
if (typeof currentIndex === 'number' && currentIndex < (missingCoverageElements.length - 1)) {
|
||||
nextIndex = currentIndex + 1;
|
||||
}
|
||||
|
||||
makeCurrent(nextIndex);
|
||||
}
|
||||
|
||||
return function jump(event) {
|
||||
switch (event.which) {
|
||||
case 78: // n
|
||||
case 74: // j
|
||||
goToNext();
|
||||
break;
|
||||
case 66: // b
|
||||
case 75: // k
|
||||
case 80: // p
|
||||
goToPrevious();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}());
|
||||
window.addEventListener('keydown', jumpToCode);
|
||||
@@ -0,0 +1,123 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Code coverage report for All files</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1>
|
||||
All files
|
||||
</h1>
|
||||
<div class='clearfix'>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">45.12% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>37/82</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">38.89% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>14/36</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">45.45% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>5/11</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">45.45% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>35/77</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
</div>
|
||||
<div class='status-line low'></div>
|
||||
<div class="pad1">
|
||||
<table class="coverage-summary">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
||||
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
||||
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
||||
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
||||
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
||||
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
||||
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td class="file low" data-value="restful_regions.js"><a href="restful_regions.js.html">restful_regions.js</a></td>
|
||||
<td data-value="26.32" class="pic low"><div class="chart"><div class="cover-fill" style="width: 26%;"></div><div class="cover-empty" style="width:74%;"></div></div></td>
|
||||
<td data-value="26.32" class="pct low">26.32%</td>
|
||||
<td data-value="57" class="abs low">15/57</td>
|
||||
<td data-value="15.38" class="pct low">15.38%</td>
|
||||
<td data-value="26" class="abs low">4/26</td>
|
||||
<td data-value="25" class="pct low">25%</td>
|
||||
<td data-value="4" class="abs low">1/4</td>
|
||||
<td data-value="26.32" class="pct low">26.32%</td>
|
||||
<td data-value="57" class="abs low">15/57</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file high" data-value="roundmath.js"><a href="roundmath.js.html">roundmath.js</a></td>
|
||||
<td data-value="83.33" class="pic high"><div class="chart"><div class="cover-fill" style="width: 83%;"></div><div class="cover-empty" style="width:17%;"></div></div></td>
|
||||
<td data-value="83.33" class="pct high">83.33%</td>
|
||||
<td data-value="18" class="abs high">15/18</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="2" class="abs high">2/2</td>
|
||||
<td data-value="50" class="pct medium">50%</td>
|
||||
<td data-value="6" class="abs medium">3/6</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="13" class="abs high">13/13</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="file high" data-value="validate_user.js"><a href="validate_user.js.html">validate_user.js</a></td>
|
||||
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="7" class="abs high">7/7</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="8" class="abs high">8/8</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="1" class="abs high">1/1</td>
|
||||
<td data-value="100" class="pct high">100%</td>
|
||||
<td data-value="7" class="abs high">7/7</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div><div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage
|
||||
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu May 31 2018 22:22:43 GMT-0400 (EDT)
|
||||
</div>
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
if (typeof prettyPrint === 'function') {
|
||||
prettyPrint();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,615 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Code coverage report for restful_regions.js</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1>
|
||||
<a href="index.html">All files</a> restful_regions.js
|
||||
</h1>
|
||||
<div class='clearfix'>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">26.32% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>15/57</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">15.38% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>4/26</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">25% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>1/4</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">26.32% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>15/57</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
</div>
|
||||
<div class='status-line low'></div>
|
||||
<pre><table class="coverage">
|
||||
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
||||
<a name='L2'></a><a href='#L2'>2</a>
|
||||
<a name='L3'></a><a href='#L3'>3</a>
|
||||
<a name='L4'></a><a href='#L4'>4</a>
|
||||
<a name='L5'></a><a href='#L5'>5</a>
|
||||
<a name='L6'></a><a href='#L6'>6</a>
|
||||
<a name='L7'></a><a href='#L7'>7</a>
|
||||
<a name='L8'></a><a href='#L8'>8</a>
|
||||
<a name='L9'></a><a href='#L9'>9</a>
|
||||
<a name='L10'></a><a href='#L10'>10</a>
|
||||
<a name='L11'></a><a href='#L11'>11</a>
|
||||
<a name='L12'></a><a href='#L12'>12</a>
|
||||
<a name='L13'></a><a href='#L13'>13</a>
|
||||
<a name='L14'></a><a href='#L14'>14</a>
|
||||
<a name='L15'></a><a href='#L15'>15</a>
|
||||
<a name='L16'></a><a href='#L16'>16</a>
|
||||
<a name='L17'></a><a href='#L17'>17</a>
|
||||
<a name='L18'></a><a href='#L18'>18</a>
|
||||
<a name='L19'></a><a href='#L19'>19</a>
|
||||
<a name='L20'></a><a href='#L20'>20</a>
|
||||
<a name='L21'></a><a href='#L21'>21</a>
|
||||
<a name='L22'></a><a href='#L22'>22</a>
|
||||
<a name='L23'></a><a href='#L23'>23</a>
|
||||
<a name='L24'></a><a href='#L24'>24</a>
|
||||
<a name='L25'></a><a href='#L25'>25</a>
|
||||
<a name='L26'></a><a href='#L26'>26</a>
|
||||
<a name='L27'></a><a href='#L27'>27</a>
|
||||
<a name='L28'></a><a href='#L28'>28</a>
|
||||
<a name='L29'></a><a href='#L29'>29</a>
|
||||
<a name='L30'></a><a href='#L30'>30</a>
|
||||
<a name='L31'></a><a href='#L31'>31</a>
|
||||
<a name='L32'></a><a href='#L32'>32</a>
|
||||
<a name='L33'></a><a href='#L33'>33</a>
|
||||
<a name='L34'></a><a href='#L34'>34</a>
|
||||
<a name='L35'></a><a href='#L35'>35</a>
|
||||
<a name='L36'></a><a href='#L36'>36</a>
|
||||
<a name='L37'></a><a href='#L37'>37</a>
|
||||
<a name='L38'></a><a href='#L38'>38</a>
|
||||
<a name='L39'></a><a href='#L39'>39</a>
|
||||
<a name='L40'></a><a href='#L40'>40</a>
|
||||
<a name='L41'></a><a href='#L41'>41</a>
|
||||
<a name='L42'></a><a href='#L42'>42</a>
|
||||
<a name='L43'></a><a href='#L43'>43</a>
|
||||
<a name='L44'></a><a href='#L44'>44</a>
|
||||
<a name='L45'></a><a href='#L45'>45</a>
|
||||
<a name='L46'></a><a href='#L46'>46</a>
|
||||
<a name='L47'></a><a href='#L47'>47</a>
|
||||
<a name='L48'></a><a href='#L48'>48</a>
|
||||
<a name='L49'></a><a href='#L49'>49</a>
|
||||
<a name='L50'></a><a href='#L50'>50</a>
|
||||
<a name='L51'></a><a href='#L51'>51</a>
|
||||
<a name='L52'></a><a href='#L52'>52</a>
|
||||
<a name='L53'></a><a href='#L53'>53</a>
|
||||
<a name='L54'></a><a href='#L54'>54</a>
|
||||
<a name='L55'></a><a href='#L55'>55</a>
|
||||
<a name='L56'></a><a href='#L56'>56</a>
|
||||
<a name='L57'></a><a href='#L57'>57</a>
|
||||
<a name='L58'></a><a href='#L58'>58</a>
|
||||
<a name='L59'></a><a href='#L59'>59</a>
|
||||
<a name='L60'></a><a href='#L60'>60</a>
|
||||
<a name='L61'></a><a href='#L61'>61</a>
|
||||
<a name='L62'></a><a href='#L62'>62</a>
|
||||
<a name='L63'></a><a href='#L63'>63</a>
|
||||
<a name='L64'></a><a href='#L64'>64</a>
|
||||
<a name='L65'></a><a href='#L65'>65</a>
|
||||
<a name='L66'></a><a href='#L66'>66</a>
|
||||
<a name='L67'></a><a href='#L67'>67</a>
|
||||
<a name='L68'></a><a href='#L68'>68</a>
|
||||
<a name='L69'></a><a href='#L69'>69</a>
|
||||
<a name='L70'></a><a href='#L70'>70</a>
|
||||
<a name='L71'></a><a href='#L71'>71</a>
|
||||
<a name='L72'></a><a href='#L72'>72</a>
|
||||
<a name='L73'></a><a href='#L73'>73</a>
|
||||
<a name='L74'></a><a href='#L74'>74</a>
|
||||
<a name='L75'></a><a href='#L75'>75</a>
|
||||
<a name='L76'></a><a href='#L76'>76</a>
|
||||
<a name='L77'></a><a href='#L77'>77</a>
|
||||
<a name='L78'></a><a href='#L78'>78</a>
|
||||
<a name='L79'></a><a href='#L79'>79</a>
|
||||
<a name='L80'></a><a href='#L80'>80</a>
|
||||
<a name='L81'></a><a href='#L81'>81</a>
|
||||
<a name='L82'></a><a href='#L82'>82</a>
|
||||
<a name='L83'></a><a href='#L83'>83</a>
|
||||
<a name='L84'></a><a href='#L84'>84</a>
|
||||
<a name='L85'></a><a href='#L85'>85</a>
|
||||
<a name='L86'></a><a href='#L86'>86</a>
|
||||
<a name='L87'></a><a href='#L87'>87</a>
|
||||
<a name='L88'></a><a href='#L88'>88</a>
|
||||
<a name='L89'></a><a href='#L89'>89</a>
|
||||
<a name='L90'></a><a href='#L90'>90</a>
|
||||
<a name='L91'></a><a href='#L91'>91</a>
|
||||
<a name='L92'></a><a href='#L92'>92</a>
|
||||
<a name='L93'></a><a href='#L93'>93</a>
|
||||
<a name='L94'></a><a href='#L94'>94</a>
|
||||
<a name='L95'></a><a href='#L95'>95</a>
|
||||
<a name='L96'></a><a href='#L96'>96</a>
|
||||
<a name='L97'></a><a href='#L97'>97</a>
|
||||
<a name='L98'></a><a href='#L98'>98</a>
|
||||
<a name='L99'></a><a href='#L99'>99</a>
|
||||
<a name='L100'></a><a href='#L100'>100</a>
|
||||
<a name='L101'></a><a href='#L101'>101</a>
|
||||
<a name='L102'></a><a href='#L102'>102</a>
|
||||
<a name='L103'></a><a href='#L103'>103</a>
|
||||
<a name='L104'></a><a href='#L104'>104</a>
|
||||
<a name='L105'></a><a href='#L105'>105</a>
|
||||
<a name='L106'></a><a href='#L106'>106</a>
|
||||
<a name='L107'></a><a href='#L107'>107</a>
|
||||
<a name='L108'></a><a href='#L108'>108</a>
|
||||
<a name='L109'></a><a href='#L109'>109</a>
|
||||
<a name='L110'></a><a href='#L110'>110</a>
|
||||
<a name='L111'></a><a href='#L111'>111</a>
|
||||
<a name='L112'></a><a href='#L112'>112</a>
|
||||
<a name='L113'></a><a href='#L113'>113</a>
|
||||
<a name='L114'></a><a href='#L114'>114</a>
|
||||
<a name='L115'></a><a href='#L115'>115</a>
|
||||
<a name='L116'></a><a href='#L116'>116</a>
|
||||
<a name='L117'></a><a href='#L117'>117</a>
|
||||
<a name='L118'></a><a href='#L118'>118</a>
|
||||
<a name='L119'></a><a href='#L119'>119</a>
|
||||
<a name='L120'></a><a href='#L120'>120</a>
|
||||
<a name='L121'></a><a href='#L121'>121</a>
|
||||
<a name='L122'></a><a href='#L122'>122</a>
|
||||
<a name='L123'></a><a href='#L123'>123</a>
|
||||
<a name='L124'></a><a href='#L124'>124</a>
|
||||
<a name='L125'></a><a href='#L125'>125</a>
|
||||
<a name='L126'></a><a href='#L126'>126</a>
|
||||
<a name='L127'></a><a href='#L127'>127</a>
|
||||
<a name='L128'></a><a href='#L128'>128</a>
|
||||
<a name='L129'></a><a href='#L129'>129</a>
|
||||
<a name='L130'></a><a href='#L130'>130</a>
|
||||
<a name='L131'></a><a href='#L131'>131</a>
|
||||
<a name='L132'></a><a href='#L132'>132</a>
|
||||
<a name='L133'></a><a href='#L133'>133</a>
|
||||
<a name='L134'></a><a href='#L134'>134</a>
|
||||
<a name='L135'></a><a href='#L135'>135</a>
|
||||
<a name='L136'></a><a href='#L136'>136</a>
|
||||
<a name='L137'></a><a href='#L137'>137</a>
|
||||
<a name='L138'></a><a href='#L138'>138</a>
|
||||
<a name='L139'></a><a href='#L139'>139</a>
|
||||
<a name='L140'></a><a href='#L140'>140</a>
|
||||
<a name='L141'></a><a href='#L141'>141</a>
|
||||
<a name='L142'></a><a href='#L142'>142</a>
|
||||
<a name='L143'></a><a href='#L143'>143</a>
|
||||
<a name='L144'></a><a href='#L144'>144</a>
|
||||
<a name='L145'></a><a href='#L145'>145</a>
|
||||
<a name='L146'></a><a href='#L146'>146</a>
|
||||
<a name='L147'></a><a href='#L147'>147</a>
|
||||
<a name='L148'></a><a href='#L148'>148</a>
|
||||
<a name='L149'></a><a href='#L149'>149</a>
|
||||
<a name='L150'></a><a href='#L150'>150</a>
|
||||
<a name='L151'></a><a href='#L151'>151</a>
|
||||
<a name='L152'></a><a href='#L152'>152</a>
|
||||
<a name='L153'></a><a href='#L153'>153</a>
|
||||
<a name='L154'></a><a href='#L154'>154</a>
|
||||
<a name='L155'></a><a href='#L155'>155</a>
|
||||
<a name='L156'></a><a href='#L156'>156</a>
|
||||
<a name='L157'></a><a href='#L157'>157</a>
|
||||
<a name='L158'></a><a href='#L158'>158</a>
|
||||
<a name='L159'></a><a href='#L159'>159</a>
|
||||
<a name='L160'></a><a href='#L160'>160</a>
|
||||
<a name='L161'></a><a href='#L161'>161</a>
|
||||
<a name='L162'></a><a href='#L162'>162</a>
|
||||
<a name='L163'></a><a href='#L163'>163</a>
|
||||
<a name='L164'></a><a href='#L164'>164</a>
|
||||
<a name='L165'></a><a href='#L165'>165</a>
|
||||
<a name='L166'></a><a href='#L166'>166</a>
|
||||
<a name='L167'></a><a href='#L167'>167</a>
|
||||
<a name='L168'></a><a href='#L168'>168</a>
|
||||
<a name='L169'></a><a href='#L169'>169</a>
|
||||
<a name='L170'></a><a href='#L170'>170</a>
|
||||
<a name='L171'></a><a href='#L171'>171</a>
|
||||
<a name='L172'></a><a href='#L172'>172</a>
|
||||
<a name='L173'></a><a href='#L173'>173</a>
|
||||
<a name='L174'></a><a href='#L174'>174</a>
|
||||
<a name='L175'></a><a href='#L175'>175</a>
|
||||
<a name='L176'></a><a href='#L176'>176</a>
|
||||
<a name='L177'></a><a href='#L177'>177</a>
|
||||
<a name='L178'></a><a href='#L178'>178</a>
|
||||
<a name='L179'></a><a href='#L179'>179</a>
|
||||
<a name='L180'></a><a href='#L180'>180</a>
|
||||
<a name='L181'></a><a href='#L181'>181</a>
|
||||
<a name='L182'></a><a href='#L182'>182</a>
|
||||
<a name='L183'></a><a href='#L183'>183</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-no"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/* */
|
||||
"use strict";
|
||||
|
||||
const getRegion = <span class="fstat-no" title="function not covered" >as</span>ync (
|
||||
res ,
|
||||
dbConn ,
|
||||
country ,
|
||||
region
|
||||
) => {
|
||||
<span class="cstat-no" title="statement not covered" > try {</span>
|
||||
let sqlQuery = <span class="cstat-no" title="statement not covered" >"";</span>
|
||||
<span class="cstat-no" title="statement not covered" > if (country == null) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > sqlQuery = `</span>
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
ORDER BY cc.countryCode, rr.regionCode
|
||||
`;
|
||||
} else <span class="cstat-no" title="statement not covered" >if (region == null) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > sqlQuery = `</span>
|
||||
SELECT 1
|
||||
FROM countries
|
||||
WHERE countryCode="${country}"
|
||||
`;
|
||||
|
||||
const countries = <span class="cstat-no" title="statement not covered" >await dbConn.query(sqlQuery);</span>
|
||||
<span class="cstat-no" title="statement not covered" > if (countries.length === 0) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > return res.status(404).send("Country not found");</span>
|
||||
}
|
||||
|
||||
<span class="cstat-no" title="statement not covered" > sqlQuery = `</span>
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
WHERE rr.countryCode="${country}"
|
||||
ORDER BY rr.regionCode
|
||||
`;
|
||||
} else {
|
||||
<span class="cstat-no" title="statement not covered" > sqlQuery = `</span>
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
WHERE rr.countryCode="${country}"
|
||||
AND rr.regionCode="${region}"
|
||||
`;
|
||||
}
|
||||
|
||||
const regions = <span class="cstat-no" title="statement not covered" >await dbConn.query(sqlQuery);</span>
|
||||
<span class="cstat-no" title="statement not covered" > if (regions.length > 0 || region === null) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > res</span>
|
||||
.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(regions));
|
||||
} else {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(404).send("Not found");</span>
|
||||
}
|
||||
} catch (e) {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(500).send("Server error");</span>
|
||||
}
|
||||
};
|
||||
|
||||
const deleteRegion = async (
|
||||
res ,
|
||||
dbConn ,
|
||||
country ,
|
||||
region
|
||||
) => {
|
||||
try {
|
||||
const sqlCities = `
|
||||
SELECT 1 FROM cities
|
||||
WHERE countryCode="${country}"
|
||||
AND regionCode="${region}"
|
||||
LIMIT 1
|
||||
`;
|
||||
const cities = await dbConn.query(sqlCities);
|
||||
if (cities.length > 0) {
|
||||
res.status(405).send("Cannot delete a region with cities");
|
||||
} else {
|
||||
const deleteRegion = `
|
||||
DELETE FROM regions
|
||||
WHERE countryCode="${country}"
|
||||
AND regionCode="${region}"
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteRegion);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("Region not found");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(500).send("Server error");</span>
|
||||
}
|
||||
};
|
||||
|
||||
const postRegion = <span class="fstat-no" title="function not covered" >as</span>ync (
|
||||
res ,
|
||||
dbConn ,
|
||||
country ,
|
||||
name
|
||||
) => {
|
||||
<span class="cstat-no" title="statement not covered" > if (!name) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > return res.status(400).send("Missing name");</span>
|
||||
}
|
||||
|
||||
<span class="cstat-no" title="statement not covered" > try {</span>
|
||||
const sqlCountry = <span class="cstat-no" title="statement not covered" >`</span>
|
||||
SELECT 1
|
||||
FROM countries
|
||||
WHERE countryCode="${country}"
|
||||
`;
|
||||
const countries = <span class="cstat-no" title="statement not covered" >await dbConn.query(sqlCountry);</span>
|
||||
<span class="cstat-no" title="statement not covered" > if (countries.length === 0) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > res.status(403).send("Country must exist");</span>
|
||||
}
|
||||
|
||||
const sqlGetId = <span class="cstat-no" title="statement not covered" >`</span>
|
||||
SELECT MAX(CAST(regionCode AS INTEGER)) AS maxr
|
||||
FROM regions
|
||||
WHERE countryCode="${country}"
|
||||
`;
|
||||
const regions = <span class="cstat-no" title="statement not covered" >await dbConn.query(sqlGetId);</span>
|
||||
const newId =
|
||||
<span class="cstat-no" title="statement not covered" > regions.length === 0 ? 1 : 1 + Number(regions[0].maxr);</span>
|
||||
|
||||
const sqlAddRegion = <span class="cstat-no" title="statement not covered" >`</span>
|
||||
INSERT INTO regions SET
|
||||
countryCode="${country}",
|
||||
regionCode="${newId}",
|
||||
regionName="${name}"
|
||||
`;
|
||||
|
||||
const result = <span class="cstat-no" title="statement not covered" >await dbConn.query(sqlAddRegion);</span>
|
||||
<span class="cstat-no" title="statement not covered" > if (result.info.affectedRows > 0) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > res</span>
|
||||
.status(201)
|
||||
.header("Location", `/regions/${country}/${newId}`)
|
||||
.send("Region created");
|
||||
} else {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(409).send("Region not created");</span>
|
||||
}
|
||||
} catch (e) {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(500).send("Server error");</span>
|
||||
}
|
||||
};
|
||||
|
||||
const putRegion = <span class="fstat-no" title="function not covered" >as</span>ync (
|
||||
res ,
|
||||
dbConn ,
|
||||
country ,
|
||||
region ,
|
||||
name
|
||||
) => {
|
||||
<span class="cstat-no" title="statement not covered" > if (!name) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > return res.status(400).send("Missing name");</span>
|
||||
}
|
||||
|
||||
<span class="cstat-no" title="statement not covered" > try {</span>
|
||||
const sqlUpdateRegion = <span class="cstat-no" title="statement not covered" >`</span>
|
||||
UPDATE regions
|
||||
SET regionName="${name}"
|
||||
WHERE countryCode="${country}"
|
||||
AND regionCode="${region}"
|
||||
`;
|
||||
|
||||
const result = <span class="cstat-no" title="statement not covered" >await dbConn.query(sqlUpdateRegion);</span>
|
||||
|
||||
<span class="cstat-no" title="statement not covered" > if (result.info.affectedRows > 0) {</span>
|
||||
<span class="cstat-no" title="statement not covered" > res.status(204).send();</span>
|
||||
} else {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(409).send("Region not updated");</span>
|
||||
}
|
||||
} catch (e) {
|
||||
<span class="cstat-no" title="statement not covered" > res.status(500).send("Server error");</span>
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getRegion, deleteRegion, postRegion, putRegion };
|
||||
</pre></td></tr>
|
||||
</table></pre>
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage
|
||||
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu May 31 2018 22:22:43 GMT-0400 (EDT)
|
||||
</div>
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
if (typeof prettyPrint === 'function') {
|
||||
prettyPrint();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,171 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Code coverage report for roundmath.js</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1>
|
||||
<a href="index.html">All files</a> roundmath.js
|
||||
</h1>
|
||||
<div class='clearfix'>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">83.33% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>15/18</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>2/2</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">50% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>3/6</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>13/13</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<pre><table class="coverage">
|
||||
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
||||
<a name='L2'></a><a href='#L2'>2</a>
|
||||
<a name='L3'></a><a href='#L3'>3</a>
|
||||
<a name='L4'></a><a href='#L4'>4</a>
|
||||
<a name='L5'></a><a href='#L5'>5</a>
|
||||
<a name='L6'></a><a href='#L6'>6</a>
|
||||
<a name='L7'></a><a href='#L7'>7</a>
|
||||
<a name='L8'></a><a href='#L8'>8</a>
|
||||
<a name='L9'></a><a href='#L9'>9</a>
|
||||
<a name='L10'></a><a href='#L10'>10</a>
|
||||
<a name='L11'></a><a href='#L11'>11</a>
|
||||
<a name='L12'></a><a href='#L12'>12</a>
|
||||
<a name='L13'></a><a href='#L13'>13</a>
|
||||
<a name='L14'></a><a href='#L14'>14</a>
|
||||
<a name='L15'></a><a href='#L15'>15</a>
|
||||
<a name='L16'></a><a href='#L16'>16</a>
|
||||
<a name='L17'></a><a href='#L17'>17</a>
|
||||
<a name='L18'></a><a href='#L18'>18</a>
|
||||
<a name='L19'></a><a href='#L19'>19</a>
|
||||
<a name='L20'></a><a href='#L20'>20</a>
|
||||
<a name='L21'></a><a href='#L21'>21</a>
|
||||
<a name='L22'></a><a href='#L22'>22</a>
|
||||
<a name='L23'></a><a href='#L23'>23</a>
|
||||
<a name='L24'></a><a href='#L24'>24</a>
|
||||
<a name='L25'></a><a href='#L25'>25</a>
|
||||
<a name='L26'></a><a href='#L26'>26</a>
|
||||
<a name='L27'></a><a href='#L27'>27</a>
|
||||
<a name='L28'></a><a href='#L28'>28</a>
|
||||
<a name='L29'></a><a href='#L29'>29</a>
|
||||
<a name='L30'></a><a href='#L30'>30</a>
|
||||
<a name='L31'></a><a href='#L31'>31</a>
|
||||
<a name='L32'></a><a href='#L32'>32</a>
|
||||
<a name='L33'></a><a href='#L33'>33</a>
|
||||
<a name='L34'></a><a href='#L34'>34</a>
|
||||
<a name='L35'></a><a href='#L35'>35</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/* */
|
||||
"use strict";
|
||||
|
||||
// These won't be exported:
|
||||
|
||||
const roundToCents = (x ) => Math.round(x * 100) / 100;
|
||||
|
||||
const changeSign = <span class="fstat-no" title="function not covered" >(x</span> ) => <span class="cstat-no" title="statement not covered" >-x;</span>
|
||||
|
||||
// The following will be exported:
|
||||
|
||||
const addR = (x , y ) => roundToCents(x + y);
|
||||
|
||||
const subR = <span class="fstat-no" title="function not covered" >(x</span> , y ) => <span class="cstat-no" title="statement not covered" >addR(x, changeSign(y));</span>
|
||||
|
||||
const multR = <span class="fstat-no" title="function not covered" >(x</span> , y ) => <span class="cstat-no" title="statement not covered" >roundToCents(x * y);</span>
|
||||
|
||||
const divR = (x , y ) => {
|
||||
if (y === 0) {
|
||||
throw new Error("Divisor must be nonzero");
|
||||
} else {
|
||||
return roundToCents(x / y);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
NOTES:
|
||||
1. Exports are all together, at the end, per convention
|
||||
2. roundToCents and changeSign are not exported, on purpose
|
||||
*/
|
||||
exports.addR = addR;
|
||||
exports.subR = subR;
|
||||
exports.multR = multR;
|
||||
exports.divR = divR;
|
||||
</pre></td></tr>
|
||||
</table></pre>
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage
|
||||
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu May 31 2018 22:22:43 GMT-0400 (EDT)
|
||||
</div>
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
if (typeof prettyPrint === 'function') {
|
||||
prettyPrint();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 209 B |
@@ -0,0 +1,158 @@
|
||||
var addSorting = (function () {
|
||||
"use strict";
|
||||
var cols,
|
||||
currentSort = {
|
||||
index: 0,
|
||||
desc: false
|
||||
};
|
||||
|
||||
// returns the summary table element
|
||||
function getTable() { return document.querySelector('.coverage-summary'); }
|
||||
// returns the thead element of the summary table
|
||||
function getTableHeader() { return getTable().querySelector('thead tr'); }
|
||||
// returns the tbody element of the summary table
|
||||
function getTableBody() { return getTable().querySelector('tbody'); }
|
||||
// returns the th element for nth column
|
||||
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }
|
||||
|
||||
// loads all columns
|
||||
function loadColumns() {
|
||||
var colNodes = getTableHeader().querySelectorAll('th'),
|
||||
colNode,
|
||||
cols = [],
|
||||
col,
|
||||
i;
|
||||
|
||||
for (i = 0; i < colNodes.length; i += 1) {
|
||||
colNode = colNodes[i];
|
||||
col = {
|
||||
key: colNode.getAttribute('data-col'),
|
||||
sortable: !colNode.getAttribute('data-nosort'),
|
||||
type: colNode.getAttribute('data-type') || 'string'
|
||||
};
|
||||
cols.push(col);
|
||||
if (col.sortable) {
|
||||
col.defaultDescSort = col.type === 'number';
|
||||
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
|
||||
}
|
||||
}
|
||||
return cols;
|
||||
}
|
||||
// attaches a data attribute to every tr element with an object
|
||||
// of data values keyed by column name
|
||||
function loadRowData(tableRow) {
|
||||
var tableCols = tableRow.querySelectorAll('td'),
|
||||
colNode,
|
||||
col,
|
||||
data = {},
|
||||
i,
|
||||
val;
|
||||
for (i = 0; i < tableCols.length; i += 1) {
|
||||
colNode = tableCols[i];
|
||||
col = cols[i];
|
||||
val = colNode.getAttribute('data-value');
|
||||
if (col.type === 'number') {
|
||||
val = Number(val);
|
||||
}
|
||||
data[col.key] = val;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// loads all row data
|
||||
function loadData() {
|
||||
var rows = getTableBody().querySelectorAll('tr'),
|
||||
i;
|
||||
|
||||
for (i = 0; i < rows.length; i += 1) {
|
||||
rows[i].data = loadRowData(rows[i]);
|
||||
}
|
||||
}
|
||||
// sorts the table using the data for the ith column
|
||||
function sortByIndex(index, desc) {
|
||||
var key = cols[index].key,
|
||||
sorter = function (a, b) {
|
||||
a = a.data[key];
|
||||
b = b.data[key];
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
},
|
||||
finalSorter = sorter,
|
||||
tableBody = document.querySelector('.coverage-summary tbody'),
|
||||
rowNodes = tableBody.querySelectorAll('tr'),
|
||||
rows = [],
|
||||
i;
|
||||
|
||||
if (desc) {
|
||||
finalSorter = function (a, b) {
|
||||
return -1 * sorter(a, b);
|
||||
};
|
||||
}
|
||||
|
||||
for (i = 0; i < rowNodes.length; i += 1) {
|
||||
rows.push(rowNodes[i]);
|
||||
tableBody.removeChild(rowNodes[i]);
|
||||
}
|
||||
|
||||
rows.sort(finalSorter);
|
||||
|
||||
for (i = 0; i < rows.length; i += 1) {
|
||||
tableBody.appendChild(rows[i]);
|
||||
}
|
||||
}
|
||||
// removes sort indicators for current column being sorted
|
||||
function removeSortIndicators() {
|
||||
var col = getNthColumn(currentSort.index),
|
||||
cls = col.className;
|
||||
|
||||
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
||||
col.className = cls;
|
||||
}
|
||||
// adds sort indicators for current column being sorted
|
||||
function addSortIndicators() {
|
||||
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
|
||||
}
|
||||
// adds event listeners for all sorter widgets
|
||||
function enableUI() {
|
||||
var i,
|
||||
el,
|
||||
ithSorter = function ithSorter(i) {
|
||||
var col = cols[i];
|
||||
|
||||
return function () {
|
||||
var desc = col.defaultDescSort;
|
||||
|
||||
if (currentSort.index === i) {
|
||||
desc = !currentSort.desc;
|
||||
}
|
||||
sortByIndex(i, desc);
|
||||
removeSortIndicators();
|
||||
currentSort.index = i;
|
||||
currentSort.desc = desc;
|
||||
addSortIndicators();
|
||||
};
|
||||
};
|
||||
for (i =0 ; i < cols.length; i += 1) {
|
||||
if (cols[i].sortable) {
|
||||
// add the click event handler on the th so users
|
||||
// dont have to click on those tiny arrows
|
||||
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
||||
if (el.addEventListener) {
|
||||
el.addEventListener('click', ithSorter(i));
|
||||
} else {
|
||||
el.attachEvent('onclick', ithSorter(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// adds sorting functionality to the UI
|
||||
return function () {
|
||||
if (!getTable()) {
|
||||
return;
|
||||
}
|
||||
cols = loadColumns();
|
||||
loadData(cols);
|
||||
addSortIndicators();
|
||||
enableUI();
|
||||
};
|
||||
})();
|
||||
|
||||
window.addEventListener('load', addSorting);
|
||||
@@ -0,0 +1,144 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Code coverage report for validate_user.js</title>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="prettify.css" />
|
||||
<link rel="stylesheet" href="base.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type='text/css'>
|
||||
.coverage-summary .sorter {
|
||||
background-image: url(sort-arrow-sprite.png);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='wrapper'>
|
||||
<div class='pad1'>
|
||||
<h1>
|
||||
<a href="index.html">All files</a> validate_user.js
|
||||
</h1>
|
||||
<div class='clearfix'>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Statements</span>
|
||||
<span class='fraction'>7/7</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Branches</span>
|
||||
<span class='fraction'>8/8</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Functions</span>
|
||||
<span class='fraction'>1/1</span>
|
||||
</div>
|
||||
<div class='fl pad1y space-right2'>
|
||||
<span class="strong">100% </span>
|
||||
<span class="quiet">Lines</span>
|
||||
<span class='fraction'>7/7</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="quiet">
|
||||
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
||||
</p>
|
||||
</div>
|
||||
<div class='status-line high'></div>
|
||||
<pre><table class="coverage">
|
||||
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
||||
<a name='L2'></a><a href='#L2'>2</a>
|
||||
<a name='L3'></a><a href='#L3'>3</a>
|
||||
<a name='L4'></a><a href='#L4'>4</a>
|
||||
<a name='L5'></a><a href='#L5'>5</a>
|
||||
<a name='L6'></a><a href='#L6'>6</a>
|
||||
<a name='L7'></a><a href='#L7'>7</a>
|
||||
<a name='L8'></a><a href='#L8'>8</a>
|
||||
<a name='L9'></a><a href='#L9'>9</a>
|
||||
<a name='L10'></a><a href='#L10'>10</a>
|
||||
<a name='L11'></a><a href='#L11'>11</a>
|
||||
<a name='L12'></a><a href='#L12'>12</a>
|
||||
<a name='L13'></a><a href='#L13'>13</a>
|
||||
<a name='L14'></a><a href='#L14'>14</a>
|
||||
<a name='L15'></a><a href='#L15'>15</a>
|
||||
<a name='L16'></a><a href='#L16'>16</a>
|
||||
<a name='L17'></a><a href='#L17'>17</a>
|
||||
<a name='L18'></a><a href='#L18'>18</a>
|
||||
<a name='L19'></a><a href='#L19'>19</a>
|
||||
<a name='L20'></a><a href='#L20'>20</a>
|
||||
<a name='L21'></a><a href='#L21'>21</a>
|
||||
<a name='L22'></a><a href='#L22'>22</a>
|
||||
<a name='L23'></a><a href='#L23'>23</a>
|
||||
<a name='L24'></a><a href='#L24'>24</a>
|
||||
<a name='L25'></a><a href='#L25'>25</a>
|
||||
<a name='L26'></a><a href='#L26'>26</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">3x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-yes">2x</span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-neutral"> </span>
|
||||
<span class="cline-any cline-yes">1x</span>
|
||||
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/* */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
In real life, validateUser could check a database,
|
||||
look into an Active Directory, call another service,
|
||||
etc. -- but for this demo, let's keep it quite
|
||||
simple and only accept a single hardcoded user.
|
||||
*/
|
||||
|
||||
const validateUser = (
|
||||
userName ,
|
||||
password ,
|
||||
callback
|
||||
) => {
|
||||
if (!userName || !password) {
|
||||
callback("Missing user/password", null);
|
||||
} else if (userName === "fkereki" && password === "modernjsbook") {
|
||||
callback(null, "fkereki"); // OK, send userName back
|
||||
} else {
|
||||
callback("Not valid user", null);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = validateUser;
|
||||
</pre></td></tr>
|
||||
</table></pre>
|
||||
<div class='push'></div><!-- for sticky footer -->
|
||||
</div><!-- /wrapper -->
|
||||
<div class='footer quiet pad2 space-top1 center small'>
|
||||
Code coverage
|
||||
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu May 31 2018 22:22:43 GMT-0400 (EDT)
|
||||
</div>
|
||||
</div>
|
||||
<script src="prettify.js"></script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
if (typeof prettyPrint === 'function') {
|
||||
prettyPrint();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="sorter.js"></script>
|
||||
<script src="block-navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,162 @@
|
||||
TN:
|
||||
SF:/home/fkereki/MODERNJS/chapter05/out/restful_regions.js
|
||||
FN:4,(anonymous_0)
|
||||
FN:65,(anonymous_1)
|
||||
FN:100,(anonymous_2)
|
||||
FN:151,(anonymous_3)
|
||||
FNF:4
|
||||
FNH:1
|
||||
FNDA:0,(anonymous_0)
|
||||
FNDA:3,(anonymous_1)
|
||||
FNDA:0,(anonymous_2)
|
||||
FNDA:0,(anonymous_3)
|
||||
DA:4,1
|
||||
DA:10,0
|
||||
DA:11,0
|
||||
DA:12,0
|
||||
DA:13,0
|
||||
DA:20,0
|
||||
DA:21,0
|
||||
DA:27,0
|
||||
DA:28,0
|
||||
DA:29,0
|
||||
DA:32,0
|
||||
DA:41,0
|
||||
DA:51,0
|
||||
DA:52,0
|
||||
DA:53,0
|
||||
DA:58,0
|
||||
DA:61,0
|
||||
DA:65,1
|
||||
DA:71,3
|
||||
DA:72,3
|
||||
DA:78,3
|
||||
DA:79,3
|
||||
DA:80,1
|
||||
DA:82,2
|
||||
DA:88,2
|
||||
DA:89,2
|
||||
DA:90,1
|
||||
DA:92,1
|
||||
DA:96,0
|
||||
DA:100,1
|
||||
DA:106,0
|
||||
DA:107,0
|
||||
DA:110,0
|
||||
DA:111,0
|
||||
DA:116,0
|
||||
DA:117,0
|
||||
DA:118,0
|
||||
DA:121,0
|
||||
DA:126,0
|
||||
DA:128,0
|
||||
DA:130,0
|
||||
DA:137,0
|
||||
DA:138,0
|
||||
DA:139,0
|
||||
DA:144,0
|
||||
DA:147,0
|
||||
DA:151,1
|
||||
DA:158,0
|
||||
DA:159,0
|
||||
DA:162,0
|
||||
DA:163,0
|
||||
DA:170,0
|
||||
DA:172,0
|
||||
DA:173,0
|
||||
DA:175,0
|
||||
DA:178,0
|
||||
DA:182,1
|
||||
LF:57
|
||||
LH:15
|
||||
BRDA:12,0,0,0
|
||||
BRDA:12,0,1,0
|
||||
BRDA:20,1,0,0
|
||||
BRDA:20,1,1,0
|
||||
BRDA:28,2,0,0
|
||||
BRDA:28,2,1,0
|
||||
BRDA:52,3,0,0
|
||||
BRDA:52,3,1,0
|
||||
BRDA:52,4,0,0
|
||||
BRDA:52,4,1,0
|
||||
BRDA:79,5,0,1
|
||||
BRDA:79,5,1,2
|
||||
BRDA:89,6,0,1
|
||||
BRDA:89,6,1,1
|
||||
BRDA:106,7,0,0
|
||||
BRDA:106,7,1,0
|
||||
BRDA:117,8,0,0
|
||||
BRDA:117,8,1,0
|
||||
BRDA:128,9,0,0
|
||||
BRDA:128,9,1,0
|
||||
BRDA:138,10,0,0
|
||||
BRDA:138,10,1,0
|
||||
BRDA:158,11,0,0
|
||||
BRDA:158,11,1,0
|
||||
BRDA:172,12,0,0
|
||||
BRDA:172,12,1,0
|
||||
BRF:26
|
||||
BRH:4
|
||||
end_of_record
|
||||
TN:
|
||||
SF:/home/fkereki/MODERNJS/chapter05/out/roundmath.js
|
||||
FN:6,(anonymous_0)
|
||||
FN:8,(anonymous_1)
|
||||
FN:12,(anonymous_2)
|
||||
FN:14,(anonymous_3)
|
||||
FN:16,(anonymous_4)
|
||||
FN:18,(anonymous_5)
|
||||
FNF:6
|
||||
FNH:3
|
||||
FNDA:3,(anonymous_0)
|
||||
FNDA:0,(anonymous_1)
|
||||
FNDA:2,(anonymous_2)
|
||||
FNDA:0,(anonymous_3)
|
||||
FNDA:0,(anonymous_4)
|
||||
FNDA:2,(anonymous_5)
|
||||
DA:6,3
|
||||
DA:8,1
|
||||
DA:12,2
|
||||
DA:14,1
|
||||
DA:16,1
|
||||
DA:18,1
|
||||
DA:19,2
|
||||
DA:20,1
|
||||
DA:22,1
|
||||
DA:31,1
|
||||
DA:32,1
|
||||
DA:33,1
|
||||
DA:34,1
|
||||
LF:13
|
||||
LH:13
|
||||
BRDA:19,0,0,1
|
||||
BRDA:19,0,1,1
|
||||
BRF:2
|
||||
BRH:2
|
||||
end_of_record
|
||||
TN:
|
||||
SF:/home/fkereki/MODERNJS/chapter05/out/validate_user.js
|
||||
FN:11,(anonymous_0)
|
||||
FNF:1
|
||||
FNH:1
|
||||
FNDA:3,(anonymous_0)
|
||||
DA:11,1
|
||||
DA:16,3
|
||||
DA:17,1
|
||||
DA:18,2
|
||||
DA:19,1
|
||||
DA:21,1
|
||||
DA:25,1
|
||||
LF:7
|
||||
LH:7
|
||||
BRDA:16,0,0,1
|
||||
BRDA:16,0,1,2
|
||||
BRDA:16,1,0,3
|
||||
BRDA:16,1,1,2
|
||||
BRDA:18,2,0,1
|
||||
BRDA:18,2,1,1
|
||||
BRDA:18,3,0,2
|
||||
BRDA:18,3,1,2
|
||||
BRF:8
|
||||
BRH:8
|
||||
end_of_record
|
||||
Generated
+10260
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,107 @@
|
||||
{
|
||||
"name": "simpleproject",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple project to show package.json creation",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "flow-remove-types src/ -d out/",
|
||||
"buildWithMaps": "flow-remove-types src/ -d out/ --pretty --sourcemaps",
|
||||
"start": "npm run build && node out/doroundmath.js",
|
||||
"start-db": "npm run build && node out/dbaccess.js",
|
||||
"nodemon": "nodemon --watch src --delay 1 --exec npm start",
|
||||
"addTypes": "flow-typed install",
|
||||
"update": "npm install && flow-typed install",
|
||||
"flow": "flow",
|
||||
"flow-coverage": "flow-coverage-report",
|
||||
"eslint": "eslint src",
|
||||
"testNoCoverage": "jest out/",
|
||||
"test": "jest out/ --coverage --no-cache",
|
||||
"newman": "newman run postman_collection.json"
|
||||
},
|
||||
"author": "Federico Kereki",
|
||||
"license": "ISC",
|
||||
"babel": {
|
||||
"presets": [
|
||||
"env",
|
||||
"flow"
|
||||
]
|
||||
},
|
||||
"eslintConfig": {
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"parser": "babel-eslint",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:flowtype/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"babel",
|
||||
"flowtype"
|
||||
],
|
||||
"rules": {
|
||||
"no-console": "off",
|
||||
"no-var": "error",
|
||||
"prefer-const": "error",
|
||||
"flowtype/no-types-missing-file-annotation": 0
|
||||
}
|
||||
},
|
||||
"eslintIgnore": [
|
||||
"**/out/*.js"
|
||||
],
|
||||
"flow-coverage-report": {
|
||||
"concurrentFiles": 1,
|
||||
"excludeGlob": [
|
||||
"node_modules/**"
|
||||
],
|
||||
"includeGlob": [
|
||||
"src/**/*.js"
|
||||
],
|
||||
"threshold": 90,
|
||||
"type": [
|
||||
"text",
|
||||
"html",
|
||||
"json"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 4,
|
||||
"printWidth": 75
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"cors": "^2.8.4",
|
||||
"dotenv": "^5.0.1",
|
||||
"express": "^4.16.3",
|
||||
"helmet": "^3.12.1",
|
||||
"jsonwebtoken": "^8.2.2",
|
||||
"mariasql": "^0.2.6",
|
||||
"morgan": "^1.9.0",
|
||||
"node-mocks-http": "^1.7.0",
|
||||
"swagger-ui-express": "^3.0.9",
|
||||
"winston": "^3.0.0-rc6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^8.2.2",
|
||||
"babel-jest": "^23.0.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-flow": "^6.23.0",
|
||||
"eslint": "^4.19.0",
|
||||
"eslint-config-recommended": "^2.0.0",
|
||||
"eslint-plugin-flowtype": "^2.48.0",
|
||||
"flow-bin": "^0.68.0",
|
||||
"flow-coverage-report": "^0.5.0",
|
||||
"flow-remove-types": "^1.2.3",
|
||||
"flow-typed": "^2.4.0",
|
||||
"jest": "^23.1.0",
|
||||
"newman": "^3.9.4",
|
||||
"nodemon": "^1.17.5",
|
||||
"prettier": "^1.13.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
{
|
||||
"info": {
|
||||
"_postman_id": "056f86ef-903d-4d01-9f6c-9d83998db7c2",
|
||||
"name": "Restful server testing for regions",
|
||||
"description": "This test is for /regions ",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "Test Delete",
|
||||
"description": "",
|
||||
"item": [
|
||||
{
|
||||
"name": "Get JWT",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "f5ba5984-536c-461b-8ac9-53369abd1386",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
"pm.test(\"Response is long enough\", () => ",
|
||||
" pm.expect(pm.response.text()).to.have.lengthOf.above(40)); ",
|
||||
" ",
|
||||
"pm.test(\"Response has three parts\", () => ",
|
||||
" pm.expect(pm.response.text().split(\".\")).to.have.lengthOf(3));",
|
||||
" ",
|
||||
"pm.environment.set(\"token\", responseBody); // for later scripts",
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/x-www-form-urlencoded"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "urlencoded",
|
||||
"urlencoded": [
|
||||
{
|
||||
"key": "user",
|
||||
"value": "fkereki",
|
||||
"description": "",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "password",
|
||||
"value": "modernjsbook",
|
||||
"description": "",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:8443/gettoken",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8443",
|
||||
"path": [
|
||||
"gettoken"
|
||||
]
|
||||
},
|
||||
"description": "The HTTP `GET` request method is meant to retrieve data from a server. The data\nis identified by a unique URI (Uniform Resource Identifier). \n\nA `GET` request can pass parameters to the server using \"Query String \nParameters\". For example, in the following request,\n\n> http://example.com/hi/there?hand=wave\n\nThe parameter \"hand\" has the value \"wave\".\n\nThis endpoint echoes the HTTP headers, request parameters and the complete\nURI requested."
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Delete non-existing region",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "706fe7f8-7417-48a9-b03d-0677eee4aad9",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 404 baby!!\", () => ",
|
||||
" pm.response.to.have.status(404));"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"method": "DELETE",
|
||||
"header": [
|
||||
{
|
||||
"key": "Authorization",
|
||||
"value": "Bearer {{token}}"
|
||||
}
|
||||
],
|
||||
"body": {},
|
||||
"url": {
|
||||
"raw": "localhost:8443/regions/zz/99",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8443",
|
||||
"path": [
|
||||
"regions",
|
||||
"zz",
|
||||
"99"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Test Get",
|
||||
"description": "",
|
||||
"item": [
|
||||
{
|
||||
"name": "Get JWT",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "f5ba5984-536c-461b-8ac9-53369abd1386",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
"pm.test(\"Response is long enough\", () => ",
|
||||
" pm.expect(pm.response.text()).to.have.lengthOf.above(40)); ",
|
||||
" ",
|
||||
"pm.test(\"Response has three parts\", () => ",
|
||||
" pm.expect(pm.response.text().split(\".\")).to.have.lengthOf(3));",
|
||||
" ",
|
||||
"pm.environment.set(\"token\", responseBody); // for later scripts",
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/x-www-form-urlencoded"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "urlencoded",
|
||||
"urlencoded": [
|
||||
{
|
||||
"key": "user",
|
||||
"value": "fkereki",
|
||||
"description": "",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"key": "password",
|
||||
"value": "modernjsbook",
|
||||
"description": "",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
"url": {
|
||||
"raw": "localhost:8443/gettoken",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8443",
|
||||
"path": [
|
||||
"gettoken"
|
||||
]
|
||||
},
|
||||
"description": "The HTTP `GET` request method is meant to retrieve data from a server. The data\nis identified by a unique URI (Uniform Resource Identifier). \n\nA `GET` request can pass parameters to the server using \"Query String \nParameters\". For example, in the following request,\n\n> http://example.com/hi/there?hand=wave\n\nThe parameter \"hand\" has the value \"wave\".\n\nThis endpoint echoes the HTTP headers, request parameters and the complete\nURI requested."
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Get /regions/uy",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "4a0fe82d-a640-42c1-b451-f7e6a5e3705e",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
"pm.test(\"Answer should be JSON\", () => {",
|
||||
" pm.response.to.be.success;",
|
||||
" pm.response.to.have.jsonBody(); ",
|
||||
"});",
|
||||
" ",
|
||||
"pm.test(\"Answer should have at least 19 regions\", () => {",
|
||||
" const regions = JSON.parse(pm.response.text());",
|
||||
" pm.expect(regions).to.have.lengthOf.at.least(19);",
|
||||
"});",
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Authorization",
|
||||
"value": "Bearer {{token}}"
|
||||
},
|
||||
{
|
||||
"key": "",
|
||||
"value": ""
|
||||
}
|
||||
],
|
||||
"body": {},
|
||||
"url": {
|
||||
"raw": "localhost:8443/regions/uy",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8443",
|
||||
"path": [
|
||||
"regions",
|
||||
"uy"
|
||||
]
|
||||
},
|
||||
"description": "Attempt getting all regions of UY\n"
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Get /regions/uy/10",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "c8a43643-d266-4e1a-9576-7647a544b796",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
"pm.test(\"Answer is valid, JSON\", function () {",
|
||||
" pm.response.to.be.success;",
|
||||
" pm.response.to.have.jsonBody(); ",
|
||||
" ",
|
||||
" const jsonData = pm.response.json();",
|
||||
" ",
|
||||
" pm.test(\"Answer has a single region\", ",
|
||||
" () => pm.expect(jsonData).to.have.lengthOf(1));",
|
||||
" ",
|
||||
" pm.test(\"Country code is UY\", ",
|
||||
" () => pm.expect(jsonData[0].countryCode).to.equal(\"UY\"));",
|
||||
"",
|
||||
" pm.test(\"Region code is 11\", ",
|
||||
" () => pm.expect(jsonData[0].regionCode).to.equal(\"11\"));",
|
||||
"",
|
||||
" pm.test(\"Region name is Paysandu\", ",
|
||||
" () => pm.expect(jsonData[0].regionName).to.equal(\"Paysandu\"));",
|
||||
"});",
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Authorization",
|
||||
"value": "Bearer {{token}}"
|
||||
}
|
||||
],
|
||||
"body": {},
|
||||
"url": {
|
||||
"raw": "localhost:8443/regions/uy/11",
|
||||
"host": [
|
||||
"localhost"
|
||||
],
|
||||
"port": "8443",
|
||||
"path": [
|
||||
"regions",
|
||||
"uy",
|
||||
"11"
|
||||
]
|
||||
},
|
||||
"description": "Attempt getting a single region of UY\n"
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"event": [
|
||||
{
|
||||
"listen": "prerequest",
|
||||
"script": {
|
||||
"id": "bd5384f0-4651-4701-a733-e4e2c12aba7a",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "4af046c3-048a-4a41-b070-32481a04d094",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
{"message":"UNKNOWN ROUTE /invented","level":"warn"}
|
||||
{"message":"GENERAL ERROR res.say_xyzzy is not a function\nTypeError: res.say_xyzzy is not a function\n at app.get (/home/fkereki/MODERNJS/chapter05/out/morgan_in_winston_server.js:67:9)\n at Layer.handle [as handle_request] (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/layer.js:95:5)\n at next (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/route.js:137:13)\n at Route.dispatch (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/route.js:112:3)\n at Layer.handle [as handle_request] (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/layer.js:95:5)\n at /home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/index.js:281:22\n at Function.process_params (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/index.js:335:12)\n at next (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/index.js:275:10)\n at logger (/home/fkereki/MODERNJS/chapter05/node_modules/morgan/index.js:144:5)\n at Layer.handle [as handle_request] (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/layer.js:95:5)","level":"error"}
|
||||
@@ -0,0 +1,13 @@
|
||||
2018-05-28T20:04:04.479Z [serv] warn UNKNOWN ROUTE /invented
|
||||
2018-05-28T20:04:07.641Z [serv] error GENERAL ERROR res.say_xyzzy is not a function
|
||||
TypeError: res.say_xyzzy is not a function
|
||||
at app.get (/home/fkereki/MODERNJS/chapter05/out/morgan_in_winston_server.js:67:9)
|
||||
at Layer.handle [as handle_request] (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/layer.js:95:5)
|
||||
at next (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/route.js:137:13)
|
||||
at Route.dispatch (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/route.js:112:3)
|
||||
at Layer.handle [as handle_request] (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/layer.js:95:5)
|
||||
at /home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/index.js:281:22
|
||||
at Function.process_params (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/index.js:335:12)
|
||||
at next (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/index.js:275:10)
|
||||
at logger (/home/fkereki/MODERNJS/chapter05/node_modules/morgan/index.js:144:5)
|
||||
at Layer.handle [as handle_request] (/home/fkereki/MODERNJS/chapter05/node_modules/express/lib/router/layer.js:95:5)
|
||||
@@ -0,0 +1,84 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const winston = require("winston");
|
||||
const morgan = require("morgan");
|
||||
|
||||
const app = express();
|
||||
|
||||
const logger = winston.createLogger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: "info",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.label({ label: "serv" }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [${msg.label}] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.txt.log",
|
||||
level: "warn",
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [serv] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.json.log",
|
||||
level: "warn"
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
app.use(
|
||||
morgan(
|
||||
`:method :url (:status) :res[content-length] - :response-time ms`,
|
||||
{
|
||||
stream: {
|
||||
write: message => logger.info(message.trim())
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
logger.info("Doing some processing...");
|
||||
logger.debug("Some fake step 1; starting");
|
||||
logger.debug("Some fake step 2; working");
|
||||
logger.debug("Some fake step 3; finished!");
|
||||
res.send("Winston server!");
|
||||
});
|
||||
|
||||
app.get("/xyzzy", (req, res) => {
|
||||
logger.info("Adventurer says 'XYZZY'");
|
||||
res.say_xyzzy(); // this will fail
|
||||
res.send("Nothing happens.");
|
||||
});
|
||||
|
||||
app.use((req, res) => {
|
||||
logger.warn(`UNKNOWN ROUTE ${req.originalUrl}`);
|
||||
res.status(404).send("NOT FOUND");
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
logger.error(`GENERAL ERROR ${err.message}\n${err.stack}`);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
app.listen(8080, () => {
|
||||
logger.info("Ready at http://localhost:8080");
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const winston = require("winston");
|
||||
const morgan = require("morgan");
|
||||
const fs = require("fs");
|
||||
|
||||
const app = express();
|
||||
|
||||
const logger = winston.createLogger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: "info",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.label({ label: "serv" }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [${msg.label}] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.txt.log",
|
||||
level: "warn",
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [serv] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.json.log",
|
||||
level: "warn"
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
const morganStream = fs.createWriteStream("serv_http_errors.log", {
|
||||
flags: "a"
|
||||
});
|
||||
|
||||
app.use(
|
||||
morgan(
|
||||
(tokens, req, res) =>
|
||||
`${new Date().toISOString()} [http] ` +
|
||||
`${tokens.method(req, res)} ${tokens.url(req, res)}`,
|
||||
{
|
||||
immediate: true,
|
||||
stream: morganStream
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
app.use(
|
||||
morgan(
|
||||
`:date[iso] [http] ` +
|
||||
`:method :url (:status) :res[content-length] - :response-time ms`,
|
||||
{
|
||||
skip: (req, res) => res.statusCode < 400
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
logger.info("Doing some processing...");
|
||||
logger.debug("Some fake step 1; starting");
|
||||
logger.debug("Some fake step 2; working");
|
||||
logger.debug("Some fake step 3; finished!");
|
||||
res.send("Winston server!");
|
||||
});
|
||||
|
||||
app.get("/xyzzy", (req, res) => {
|
||||
logger.info("Adventurer says 'XYZZY'");
|
||||
res.say_xyzzy(); // this will fail
|
||||
res.send("Nothing happens.");
|
||||
});
|
||||
|
||||
app.use((req, res) => {
|
||||
logger.warn(`UNKNOWN ROUTE ${req.originalUrl}`);
|
||||
res.status(404).send("NOT FOUND");
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
logger.error(`GENERAL ERROR ${err.message}\n${err.stack}`);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
app.listen(8080, () => {
|
||||
logger.info("Ready at http://localhost:8080");
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const winston = require("winston");
|
||||
const morgan = require("morgan");
|
||||
const fs = require("fs");
|
||||
|
||||
const app = express();
|
||||
|
||||
const logger = winston.createLogger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: "info",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.label({ label: "serv" }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [${msg.label}] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.txt.log",
|
||||
level: "warn",
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [serv] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.json.log",
|
||||
level: "warn"
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
const morganStream = fs.createWriteStream("serv_http_errors.log", {
|
||||
flags: "a"
|
||||
});
|
||||
|
||||
app.use(
|
||||
morgan(
|
||||
(tokens, req, res) =>
|
||||
`${new Date().toISOString()} [http] ` +
|
||||
`${tokens.method(req, res)} ${tokens.url(req, res)}`,
|
||||
{
|
||||
immediate: true,
|
||||
stream: morganStream
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
app.use(
|
||||
morgan(
|
||||
`:date[iso] [http] ` +
|
||||
`:method :url (:status) :res[content-length] - :response-time ms`,
|
||||
{
|
||||
skip: (req, res) => res.statusCode < 400
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
logger.info("Doing some processing...");
|
||||
logger.debug("Some fake step 1; starting");
|
||||
logger.debug("Some fake step 2; working");
|
||||
logger.debug("Some fake step 3; finished!");
|
||||
res.send("Winston server!");
|
||||
});
|
||||
|
||||
app.get("/xyzzy", (req, res) => {
|
||||
logger.info("Adventurer says 'XYZZY'");
|
||||
res.say_xyzzy(); // this will fail
|
||||
res.send("Nothing happens.");
|
||||
});
|
||||
|
||||
app.use((req, res) => {
|
||||
logger.warn(`UNKNOWN ROUTE ${req.originalUrl}`);
|
||||
res.status(404).send("NOT FOUND");
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
logger.error(`GENERAL ERROR ${err.message}\n${err.stack}`);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
app.listen(8080, () => {
|
||||
logger.info("Ready at http://localhost:8080");
|
||||
});
|
||||
@@ -0,0 +1,171 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
// eslint-disable
|
||||
|
||||
const getCity = async (res: any, dbConn: any, city: string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
let sqlQuery = "";
|
||||
sqlQuery = `
|
||||
SELECT *
|
||||
FROM cities
|
||||
WHERE cityId=?
|
||||
`;
|
||||
|
||||
const cities = await dbConn.query(sqlQuery, [city]);
|
||||
if (cities.length === 0) {
|
||||
res.status(404).send("City not found");
|
||||
} else {
|
||||
res
|
||||
.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(cities));
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteCity = async (res: any, dbConn: any, city: string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
const deleteCity = `
|
||||
DELETE FROM cities
|
||||
WHERE cityId=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteCity, [city]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("City not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const postCity = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
name: string,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
population: number,
|
||||
country: string,
|
||||
region: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlRegion = `
|
||||
SELECT 1
|
||||
FROM regions
|
||||
WHERE countryCode=? AND regionCode=?
|
||||
`;
|
||||
const regions = await dbConn.query(sqlRegion, [country, region]);
|
||||
if (regions.length === 0) {
|
||||
res.status(403).send("Region must exist");
|
||||
return;
|
||||
}
|
||||
|
||||
const sqlGetId = `
|
||||
SELECT MAX(CAST(cityId AS INTEGER)) AS maxr
|
||||
FROM cities
|
||||
`;
|
||||
const cities = await dbConn.query(sqlGetId);
|
||||
const newId = cities.length === 0 ? 1 : 1 + Number(cities[0].maxr);
|
||||
|
||||
const sqlAddCity = `
|
||||
INSERT INTO cities SET
|
||||
cityId=?
|
||||
cityName=?,
|
||||
latitude=?,
|
||||
longitude=?,
|
||||
population=?,
|
||||
countryCode=?,
|
||||
regionCode=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlAddCity, [
|
||||
newId,
|
||||
name,
|
||||
latitude,
|
||||
longitude,
|
||||
population,
|
||||
country,
|
||||
region
|
||||
]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res
|
||||
.status(201)
|
||||
.header("Location", `/cities/${newId}`)
|
||||
.send("City created");
|
||||
} else {
|
||||
res.status(409).send("City not created");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const putCity = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
city: string,
|
||||
name: string,
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
population: number,
|
||||
country: string,
|
||||
region: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlUpdateCity = `
|
||||
UPDATE cities
|
||||
SET
|
||||
cityName=?,
|
||||
latitude=?,
|
||||
longitude=?,
|
||||
population=?,
|
||||
countryCode=?,
|
||||
regionCode=?
|
||||
WHERE cityId=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlUpdateCity, [
|
||||
name,
|
||||
latitude,
|
||||
longitude,
|
||||
population,
|
||||
country,
|
||||
region,
|
||||
city
|
||||
]);
|
||||
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(409).send("City not updated");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getCity, deleteCity, postCity, putCity };
|
||||
@@ -0,0 +1,107 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const getCountry = async (res: any, dbConn: any, country: ?string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
let sqlQuery = "";
|
||||
let countries;
|
||||
if (country == null) {
|
||||
sqlQuery = `
|
||||
SELECT cc.*
|
||||
FROM countries cc
|
||||
ORDER BY cc.countryCode
|
||||
`;
|
||||
countries = await dbConn.query(sqlQuery);
|
||||
} else {
|
||||
sqlQuery = `
|
||||
SELECT cc.*
|
||||
FROM countries cc
|
||||
WHERE cc.countryCode=?
|
||||
`;
|
||||
countries = await dbConn.query(sqlQuery, [country]);
|
||||
}
|
||||
|
||||
if (countries.length > 0) {
|
||||
res
|
||||
.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(countries));
|
||||
} else {
|
||||
res.status(404).send("Not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteCountry = async (res: any, dbConn: any, country: string) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
const sqlRegions = `
|
||||
SELECT 1 FROM regions
|
||||
WHERE countryCode=?
|
||||
LIMIT 1
|
||||
`;
|
||||
const regions = await dbConn.query(sqlRegions, [country]);
|
||||
if (regions.length > 0) {
|
||||
res.status(405).send("Cannot delete a country with regions");
|
||||
return;
|
||||
}
|
||||
|
||||
const deleteCountry = `
|
||||
DELETE FROM countries
|
||||
WHERE countryCode=?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteCountry, [country]);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("Country not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const putCountry = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
name: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
res.status(400).send("Missing name");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlInsertOrUpdateCountry = `
|
||||
INSERT INTO countries (countryCode, countryName)
|
||||
VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
countryName = ?
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlInsertOrUpdateCountry, [
|
||||
country,
|
||||
name,
|
||||
name
|
||||
]);
|
||||
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(409).send("Country not updated");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getCountry, deleteCountry, putCountry };
|
||||
@@ -0,0 +1,20 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const mariaSQL = require("mariasql");
|
||||
const { promisify } = require("util");
|
||||
|
||||
const DB_HOST = "127.0.0.1";
|
||||
const DB_USER = "fkereki";
|
||||
const DB_PASS = "modernJS!!";
|
||||
const DB_SCHEMA = "world";
|
||||
|
||||
const getDbConnection = (host, user, password, db) => {
|
||||
const dbConn = new mariaSQL({ host, user, password, db });
|
||||
dbConn.query = promisify(dbConn.query);
|
||||
return dbConn;
|
||||
};
|
||||
|
||||
const dbConn = getDbConnection(DB_HOST, DB_USER, DB_PASS, DB_SCHEMA);
|
||||
|
||||
module.exports = dbConn;
|
||||
@@ -0,0 +1,188 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const getRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: ?string,
|
||||
region: ?string
|
||||
) => {
|
||||
try {
|
||||
let sqlQuery = "";
|
||||
if (country == null) {
|
||||
sqlQuery = `
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
ORDER BY cc.countryCode, rr.regionCode
|
||||
`;
|
||||
} else if (region == null) {
|
||||
sqlQuery = `
|
||||
SELECT 1
|
||||
FROM countries
|
||||
WHERE countryCode="${country}"
|
||||
`;
|
||||
|
||||
const countries = await dbConn.query(sqlQuery);
|
||||
if (countries.length === 0) {
|
||||
return res.status(404).send("Country not found");
|
||||
}
|
||||
|
||||
sqlQuery = `
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
WHERE rr.countryCode="${country}"
|
||||
ORDER BY rr.regionCode
|
||||
`;
|
||||
} else {
|
||||
sqlQuery = `
|
||||
SELECT rr.*
|
||||
FROM regions rr
|
||||
JOIN countries cc
|
||||
ON cc.countryCode=rr.countryCode
|
||||
WHERE rr.countryCode="${country}"
|
||||
AND rr.regionCode="${region}"
|
||||
`;
|
||||
}
|
||||
|
||||
res.set("Connection", "close");
|
||||
|
||||
const regions = await dbConn.query(sqlQuery);
|
||||
if (regions.length > 0 || region === null) {
|
||||
res.status(200)
|
||||
.set("Content-Type", "application/json")
|
||||
.send(JSON.stringify(regions));
|
||||
} else {
|
||||
res.status(404).send("Not found");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const deleteRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
region: string
|
||||
) => {
|
||||
try {
|
||||
res.set("Connection", "close");
|
||||
|
||||
const sqlCities = `
|
||||
SELECT 1 FROM cities
|
||||
WHERE countryCode="${country}"
|
||||
AND regionCode="${region}"
|
||||
LIMIT 1
|
||||
`;
|
||||
const cities = await dbConn.query(sqlCities);
|
||||
if (cities.length > 0) {
|
||||
res.status(405).send("Cannot delete a region with cities");
|
||||
} else {
|
||||
const deleteRegion = `
|
||||
DELETE FROM regions
|
||||
WHERE countryCode="${country}"
|
||||
AND regionCode="${region}"
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(deleteRegion);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(404).send("Region not found");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const postRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
name: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
return res.status(400).send("Missing name");
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlCountry = `
|
||||
SELECT 1
|
||||
FROM countries
|
||||
WHERE countryCode="${country}"
|
||||
`;
|
||||
const countries = await dbConn.query(sqlCountry);
|
||||
if (countries.length === 0) {
|
||||
res.status(403).send("Country must exist");
|
||||
}
|
||||
|
||||
const sqlGetId = `
|
||||
SELECT MAX(CAST(regionCode AS INTEGER)) AS maxr
|
||||
FROM regions
|
||||
WHERE countryCode="${country}"
|
||||
`;
|
||||
const regions = await dbConn.query(sqlGetId);
|
||||
const newId =
|
||||
regions.length === 0 ? 1 : 1 + Number(regions[0].maxr);
|
||||
|
||||
const sqlAddRegion = `
|
||||
INSERT INTO regions SET
|
||||
countryCode="${country}",
|
||||
regionCode="${newId}",
|
||||
regionName="${name}"
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlAddRegion);
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(201)
|
||||
.header("Location", `/regions/${country}/${newId}`)
|
||||
.send("Region created");
|
||||
} else {
|
||||
res.status(409).send("Region not created");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
const putRegion = async (
|
||||
res: any,
|
||||
dbConn: any,
|
||||
country: string,
|
||||
region: string,
|
||||
name: string
|
||||
) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (!name) {
|
||||
return res.status(400).send("Missing name");
|
||||
}
|
||||
|
||||
try {
|
||||
const sqlUpdateRegion = `
|
||||
UPDATE regions
|
||||
SET regionName="${name}"
|
||||
WHERE countryCode="${country}"
|
||||
AND regionCode="${region}"
|
||||
`;
|
||||
|
||||
const result = await dbConn.query(sqlUpdateRegion);
|
||||
|
||||
if (result.info.affectedRows > 0) {
|
||||
res.status(204).send();
|
||||
} else {
|
||||
res.status(409).send("Region not updated");
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send("Server error");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { getRegion, deleteRegion, postRegion, putRegion };
|
||||
@@ -0,0 +1,45 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const { deleteRegion } = require("./restful_regions");
|
||||
|
||||
const mockRes = require("node-mocks-http");
|
||||
|
||||
describe("deleteRegion", () => {
|
||||
let mDb;
|
||||
let mRes;
|
||||
beforeEach(() => {
|
||||
mDb = { query: jest.fn() };
|
||||
mRes = new mockRes.createResponse();
|
||||
});
|
||||
|
||||
it("should not delete a region with cities", async () => {
|
||||
mDb.query.mockReturnValueOnce(Promise.resolve([1]));
|
||||
await deleteRegion(mRes, mDb, "FK", "22");
|
||||
expect(mRes.statusCode).toBe(405);
|
||||
});
|
||||
|
||||
it("should delete a region without cities", async () => {
|
||||
mDb.query
|
||||
.mockReturnValueOnce(Promise.resolve([]))
|
||||
.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
info: { affectedRows: 1 }
|
||||
})
|
||||
);
|
||||
await deleteRegion(mRes, mDb, "ST", "12");
|
||||
expect(mRes.statusCode).toBe(204);
|
||||
});
|
||||
|
||||
it("should produce a 404 for non-existing region", async () => {
|
||||
mDb.query
|
||||
.mockReturnValueOnce(Promise.resolve([]))
|
||||
.mockReturnValueOnce(
|
||||
Promise.resolve({
|
||||
info: { affectedRows: 0 }
|
||||
})
|
||||
);
|
||||
await deleteRegion(mRes, mDb, "IP", "24");
|
||||
expect(mRes.statusCode).toBe(404);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const app = express();
|
||||
const bodyParser = require("body-parser");
|
||||
const cors = require("cors");
|
||||
const swaggerUi = require("swagger-ui-express");
|
||||
const swaggerDocument = require("../swagger.json");
|
||||
|
||||
const dbConn = require("./restful_db.js");
|
||||
const validateUser = require("./validate_user.js");
|
||||
|
||||
const SECRET_JWT_KEY = "modernJSbook";
|
||||
|
||||
const https = require("https");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const keysPath = path.join(__dirname, "../../certificates");
|
||||
const ca = fs.readFileSync(`${keysPath}/modernjsbook.csr`);
|
||||
const cert = fs.readFileSync(`${keysPath}/modernjsbook.crt`);
|
||||
const key = fs.readFileSync(`${keysPath}/modernjsbook.key`);
|
||||
|
||||
https.createServer({ ca, cert, key }, app);
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
|
||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
|
||||
app.get("/", (req, res) =>
|
||||
res
|
||||
.status(200)
|
||||
.set("Connection", "close")
|
||||
.send("Ready")
|
||||
);
|
||||
|
||||
app.post("/gettoken", (req, res) => {
|
||||
validateUser(req.body.user, req.body.password, (idErr, userid) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
if (idErr !== null) {
|
||||
res.status(401).send(idErr);
|
||||
} else {
|
||||
jwt.sign(
|
||||
{ userid },
|
||||
SECRET_JWT_KEY,
|
||||
{ algorithm: "HS256", expiresIn: "1h" },
|
||||
(err, token) => res.status(200).send(token)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
res.set("Connection", "close");
|
||||
|
||||
// First check for the Authorization header
|
||||
const authHeader = req.headers.authorization;
|
||||
if (!authHeader || !authHeader.startsWith("Bearer")) {
|
||||
return res.status(401).send("No token specified");
|
||||
}
|
||||
|
||||
// Now validate the token itself
|
||||
const token = authHeader.split(" ")[1];
|
||||
|
||||
jwt.verify(token, SECRET_JWT_KEY, (err, decoded) => {
|
||||
if (err) {
|
||||
// Token bad formed, or expired, or other problem
|
||||
return res.status(403).send("Token expired or not valid");
|
||||
} else {
|
||||
// Token OK; get the user id from it
|
||||
req.userid = decoded.userid;
|
||||
// Keep processing the request
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const {
|
||||
getCountry,
|
||||
deleteCountry,
|
||||
putCountry
|
||||
} = require("./restful_countries.js");
|
||||
|
||||
app.get("/countries", (req, res) => getCountry(res, dbConn));
|
||||
|
||||
app.get("/countries/:country", (req, res) =>
|
||||
getCountry(res, dbConn, req.params.country)
|
||||
);
|
||||
|
||||
app.delete("/countries/:country", (req, res) =>
|
||||
deleteCountry(res, dbConn, req.params.country)
|
||||
);
|
||||
|
||||
app.put("/countries/:country", (req, res) =>
|
||||
putCountry(res, dbConn, req.params.country, req.body.name)
|
||||
);
|
||||
|
||||
const {
|
||||
getRegion,
|
||||
deleteRegion,
|
||||
postRegion,
|
||||
putRegion
|
||||
} = require("./restful_regions.js");
|
||||
|
||||
app.get("/regions", (req, res) => getRegion(res, dbConn));
|
||||
|
||||
app.get("/regions/:country", (req, res) =>
|
||||
getRegion(res, dbConn, req.params.country)
|
||||
);
|
||||
|
||||
app.get("/regions/:country/:region", (req, res) =>
|
||||
getRegion(res, dbConn, req.params.country, req.params.region)
|
||||
);
|
||||
|
||||
app.delete("/regions/:country/:region", (req, res) =>
|
||||
deleteRegion(res, dbConn, req.params.country, req.params.region)
|
||||
);
|
||||
|
||||
app.post("/regions/:country", (req, res) =>
|
||||
postRegion(res, dbConn, req.params.country, req.body.name)
|
||||
);
|
||||
|
||||
app.put("/regions/:country/:region", (req, res) =>
|
||||
putRegion(
|
||||
res,
|
||||
dbConn,
|
||||
req.params.country,
|
||||
req.params.region,
|
||||
req.body.name
|
||||
)
|
||||
);
|
||||
|
||||
const {
|
||||
getCity,
|
||||
deleteCity,
|
||||
postCity,
|
||||
putCity
|
||||
} = require("./restful_cities.js");
|
||||
|
||||
// We do not allow calling /cities to get every city in the world
|
||||
|
||||
app.get("/cities/:city", (req, res) =>
|
||||
getCity(res, dbConn, req.params.city)
|
||||
);
|
||||
|
||||
app.delete("/cities/:city", (req, res) =>
|
||||
deleteCity(res, dbConn, req.params.city)
|
||||
);
|
||||
|
||||
app.post("/cities/:city", (req, res) =>
|
||||
postCity(
|
||||
res,
|
||||
dbConn,
|
||||
req.body.name,
|
||||
req.body.latitude,
|
||||
req.body.longitude,
|
||||
req.body.population,
|
||||
req.body.country,
|
||||
req.body.region
|
||||
)
|
||||
);
|
||||
|
||||
app.put("/cities/:city", (req, res) =>
|
||||
putCity(
|
||||
res,
|
||||
dbConn,
|
||||
req.params.city,
|
||||
req.body.name,
|
||||
req.body.latitude,
|
||||
req.body.longitude,
|
||||
req.body.population,
|
||||
req.body.country,
|
||||
req.body.region
|
||||
)
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
console.error("Error....", err.message);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
app.listen(8443, () =>
|
||||
console.log("Server ready at http://localhost:8443")
|
||||
);
|
||||
@@ -0,0 +1,34 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
// These won't be exported:
|
||||
|
||||
const roundToCents = (x: number): number => Math.round(x * 100) / 100;
|
||||
|
||||
const changeSign = (x: number): number => -x;
|
||||
|
||||
// The following will be exported:
|
||||
|
||||
const addR = (x: number, y: number): number => roundToCents(x + y);
|
||||
|
||||
const subR = (x: number, y: number): number => addR(x, changeSign(y));
|
||||
|
||||
const multR = (x: number, y: number): number => roundToCents(x * y);
|
||||
|
||||
const divR = (x: number, y: number): number => {
|
||||
if (y === 0) {
|
||||
throw new Error("Divisor must be nonzero");
|
||||
} else {
|
||||
return roundToCents(x / y);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
NOTES:
|
||||
1. Exports are all together, at the end, per convention
|
||||
2. roundToCents and changeSign are not exported, on purpose
|
||||
*/
|
||||
exports.addR = addR;
|
||||
exports.subR = subR;
|
||||
exports.multR = multR;
|
||||
exports.divR = divR;
|
||||
@@ -0,0 +1,23 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const rm = require("./roundmath");
|
||||
|
||||
describe("addR", () => {
|
||||
it("should add first and round later", () => {
|
||||
expect(rm.addR(1.505, 2.505)).toBe(4.01);
|
||||
});
|
||||
|
||||
it("should handle negatives", () => {
|
||||
expect(rm.addR(3.15, -2.149)).toBe(1.0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("divR", () => {
|
||||
it("should divide first, then round", () => {
|
||||
expect(rm.divR(22.96, 0.001)).toBe(22960);
|
||||
});
|
||||
|
||||
it("should not divide by zero", () =>
|
||||
expect(() => rm.divR(22, 0)).toThrow());
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
// flow()
|
||||
"use strict";
|
||||
|
||||
const dotenv = require("dotenv");
|
||||
|
||||
console.log(process.env);
|
||||
|
||||
const dev = process.env.NODE_ENV || "development";
|
||||
const isDev = dev === "development";
|
||||
|
||||
if (isDev) {
|
||||
dotenv.load();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
In real life, validateUser could check a database,
|
||||
look into an Active Directory, call another service,
|
||||
etc. -- but for this demo, let's keep it quite
|
||||
simple and only accept a single hardcoded user.
|
||||
*/
|
||||
|
||||
const validateUser = (
|
||||
userName: string,
|
||||
password: string,
|
||||
callback: (?string, ?string) => void
|
||||
) => {
|
||||
if (!userName || !password) {
|
||||
callback("Missing user/password", null);
|
||||
} else if (userName === "fkereki" && password === "modernjsbook") {
|
||||
callback(null, "fkereki"); // OK, send userName back
|
||||
} else {
|
||||
callback("Not valid user", null);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = validateUser;
|
||||
@@ -0,0 +1,28 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const validateUser = require("./validate_user");
|
||||
|
||||
describe("validateUser", () => {
|
||||
let cb;
|
||||
|
||||
beforeEach(() => {
|
||||
cb = jest.fn();
|
||||
});
|
||||
|
||||
it("should reject a call with empty user", () => {
|
||||
validateUser("", "somepass", cb);
|
||||
expect(cb).toHaveBeenCalled();
|
||||
expect(cb).toHaveBeenCalledWith("Missing user/password", null);
|
||||
});
|
||||
|
||||
it("should reject a wrong password", () => {
|
||||
validateUser("fkereki", "wrongpassword", cb);
|
||||
expect(cb).toHaveBeenCalledWith("Not valid user", null);
|
||||
});
|
||||
|
||||
it("should accept a correct password", () => {
|
||||
validateUser("fkereki", "modernjsbook", cb);
|
||||
expect(cb).toHaveBeenCalledWith(null, "fkereki");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
/* @flow */
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const winston = require("winston");
|
||||
|
||||
const app = express();
|
||||
|
||||
const logger = winston.createLogger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: "info",
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize({ all: true }),
|
||||
winston.format.label({ label: "serv" }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [${msg.label}] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.txt.log",
|
||||
level: "warn",
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(
|
||||
msg =>
|
||||
`${msg.timestamp} [serv] ${msg.level} ${
|
||||
msg.message
|
||||
}`
|
||||
)
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: "serv_error.json.log",
|
||||
level: "warn"
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
app.use((req, res, next) => {
|
||||
logger.info(`${req.method} request for ${req.originalUrl}`);
|
||||
next();
|
||||
});
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
logger.info("Doing some processing...");
|
||||
logger.debug("Some fake step 1; starting");
|
||||
logger.debug("Some fake step 2; working");
|
||||
logger.debug("Some fake step 3; finished!");
|
||||
res.send("Winston server!");
|
||||
});
|
||||
|
||||
app.get("/xyzzy", (req, res) => {
|
||||
logger.info("Adventurer says 'XYZZY'");
|
||||
res.say_xyzzy(); // this will fail
|
||||
res.send("Nothing happens.");
|
||||
});
|
||||
|
||||
app.use((req, res) => {
|
||||
logger.warn(`UNKNOWN ROUTE ${req.originalUrl}`);
|
||||
res.status(404).send("NOT FOUND");
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
app.use((err, req, res, next) => {
|
||||
logger.error(`GENERAL ERROR ${err.message}\n${err.stack}`);
|
||||
res.status(500).send("INTERNAL SERVER ERROR");
|
||||
});
|
||||
|
||||
app.listen(8080, () => {
|
||||
logger.info("Ready at http://localhost:8080");
|
||||
});
|
||||
@@ -0,0 +1,711 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "This is a RESTful API to access world data, including countries, regions, and cities.",
|
||||
"version": "1.0.0",
|
||||
"title": "World Data API"
|
||||
},
|
||||
"host": "127.0.0.1:8443",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"name": "token",
|
||||
"description": "Get a JWT for authorization"
|
||||
},
|
||||
{
|
||||
"name": "countries",
|
||||
"description": "Access the world countries"
|
||||
},
|
||||
{
|
||||
"name": "regions",
|
||||
"description": "Access the regions of countries"
|
||||
},
|
||||
{
|
||||
"name": "cities",
|
||||
"description": "Access the world cities"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/gettoken": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"token"
|
||||
],
|
||||
"summary": "Get a token to authorize future requests",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "user",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "password",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A valid token to use for other requests"
|
||||
},
|
||||
"401": {
|
||||
"description": "Wrong user/password"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/regions": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"regions"
|
||||
],
|
||||
"summary": "Get all regions of all countries",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"tags": [
|
||||
"regions"
|
||||
],
|
||||
"summary": "Add a region to a given country",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new region's name."
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "OK, created"
|
||||
},
|
||||
"400": {
|
||||
"description": "Name missing, region not created"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"403": {
|
||||
"description": "Country not found, region not created"
|
||||
},
|
||||
"409": {
|
||||
"description": "Other failure, region not created"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/regions/{country}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"regions"
|
||||
],
|
||||
"summary": "Get all regions of a given country",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Country (id) whose regions are required",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "Country not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/regions/{country}/{id}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"regions"
|
||||
],
|
||||
"summary": "Get a specific region of a given country",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Country (id) of the region",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "Region (id) that is required",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "Country not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"regions"
|
||||
],
|
||||
"summary": "Delete a specific region of a given country",
|
||||
"description": "",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Country (id) of the region",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "Region (id) that is to be deleted",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "OK, region was deleted"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "Region does not exist"
|
||||
},
|
||||
"405": {
|
||||
"description": "Region has cities, cannot be deleted"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"regions"
|
||||
],
|
||||
"summary": "Update a specific region of a given country",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Country (id) of the region",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "Region (id) that is to be deleted",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The region's new name."
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "OK, region was updated"
|
||||
},
|
||||
"400": {
|
||||
"description": "Name missing, region not updated"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "Country not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/countries": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"countries"
|
||||
],
|
||||
"summary": "Get all countries",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/countries/{country}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"countries"
|
||||
],
|
||||
"summary": "Get a single country",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Required Country",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "Country not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"countries"
|
||||
],
|
||||
"summary": "Delete a specific country",
|
||||
"description": "",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Country to delete",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "OK, country was deleted"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "Country does not exist"
|
||||
},
|
||||
"405": {
|
||||
"description": "Country has regions, cannot be deleted"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"countries"
|
||||
],
|
||||
"summary": "Update or create a country",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "country",
|
||||
"in": "path",
|
||||
"description": "Country",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The region's new name."
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "OK, coutry was updated"
|
||||
},
|
||||
"400": {
|
||||
"description": "Name missing, country not updated"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/cities": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"cities"
|
||||
],
|
||||
"summary": "Add a city",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new city's name."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "latitude",
|
||||
"required": true,
|
||||
"type": "number",
|
||||
"description": "The new city's latitude."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "longitude",
|
||||
"required": true,
|
||||
"type": "number",
|
||||
"description": "The new city's longitude."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "population",
|
||||
"required": true,
|
||||
"type": "number",
|
||||
"description": "The new city's population."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "countryCode",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new city's country."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "regionCode",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new city's region."
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "OK, created"
|
||||
},
|
||||
"400": {
|
||||
"description": "Name missing, city not created"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"403": {
|
||||
"description": "Region not found, city not created"
|
||||
},
|
||||
"409": {
|
||||
"description": "Other failure, city not created"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/cities/{cityId}": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"cities"
|
||||
],
|
||||
"summary": "Get a specific city",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "cityId",
|
||||
"in": "path",
|
||||
"description": "Id of the city",
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "City not found"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"tags": [
|
||||
"cities"
|
||||
],
|
||||
"summary": "Delete a specific city",
|
||||
"description": "",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "cityId",
|
||||
"in": "path",
|
||||
"description": "Id of the city",
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "OK, city was deleted"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "City does not exist"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"tags": [
|
||||
"cities"
|
||||
],
|
||||
"summary": "Update a specific city",
|
||||
"consumes": [
|
||||
"application/x-www-form-urlencoded"
|
||||
],
|
||||
"produces": [
|
||||
"text/plain"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "cityId",
|
||||
"in": "path",
|
||||
"description": "Id of the city",
|
||||
"type": "number",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "name",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new city's name."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "latitude",
|
||||
"required": true,
|
||||
"type": "number",
|
||||
"description": "The new city's latitude."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "longitude",
|
||||
"required": true,
|
||||
"type": "number",
|
||||
"description": "The new city's longitude."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "population",
|
||||
"required": true,
|
||||
"type": "number",
|
||||
"description": "The new city's population."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "countryCode",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new city's country."
|
||||
},
|
||||
{
|
||||
"in": "formData",
|
||||
"name": "regionCode",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "The new city's region."
|
||||
},
|
||||
{
|
||||
"in": "header",
|
||||
"name": "Authorization",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"description": "Authorization Token"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "OK, city was updated"
|
||||
},
|
||||
"400": {
|
||||
"description": "Name missing, city not updated"
|
||||
},
|
||||
"401": {
|
||||
"description": "No token provided"
|
||||
},
|
||||
"404": {
|
||||
"description": "City not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,492 @@
|
||||
swagger: "2.0"
|
||||
info:
|
||||
description: "This is a RESTful API to access world data, including countries, regions, and cities."
|
||||
version: "1.0.0"
|
||||
title: "World Data API"
|
||||
|
||||
host: "127.0.0.1:8443"
|
||||
schemes:
|
||||
- "http"
|
||||
|
||||
tags:
|
||||
- name: "token"
|
||||
description: "Get a JWT for authorization"
|
||||
- name: "countries"
|
||||
description: "Access the world countries"
|
||||
- name: "regions"
|
||||
description: "Access the regions of countries"
|
||||
- name: "cities"
|
||||
description: "Access the world cities"
|
||||
|
||||
|
||||
paths:
|
||||
/gettoken:
|
||||
post:
|
||||
tags:
|
||||
- "token"
|
||||
summary: "Get a token to authorize future requests"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- text/plain
|
||||
parameters:
|
||||
- in: formData
|
||||
name: user
|
||||
required: true
|
||||
type: string
|
||||
- in: formData
|
||||
name: password
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: A valid token to use for other requests
|
||||
401:
|
||||
description: "Wrong user/password"
|
||||
|
||||
/regions:
|
||||
get:
|
||||
tags:
|
||||
- "regions"
|
||||
summary: "Get all regions of all countries"
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
200:
|
||||
description: "OK"
|
||||
401:
|
||||
description: "No token provided"
|
||||
|
||||
post:
|
||||
tags:
|
||||
- "regions"
|
||||
summary: "Add a region to a given country"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- text/plain
|
||||
parameters:
|
||||
- in: formData
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
description: The new region's name.
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
201:
|
||||
description: "OK, created"
|
||||
400:
|
||||
description: "Name missing, region not created"
|
||||
401:
|
||||
description: "No token provided"
|
||||
403:
|
||||
description: "Country not found, region not created"
|
||||
409:
|
||||
description: "Other failure, region not created"
|
||||
|
||||
/regions/{country}:
|
||||
get:
|
||||
tags:
|
||||
- "regions"
|
||||
summary: "Get all regions of a given country"
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Country (id) whose regions are required"
|
||||
type: string
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
200:
|
||||
description: "OK"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "Country not found"
|
||||
|
||||
/regions/{country}/{id}:
|
||||
|
||||
get:
|
||||
tags:
|
||||
- "regions"
|
||||
summary: "Get a specific region of a given country"
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Country (id) of the region"
|
||||
type: string
|
||||
required: true
|
||||
- name: id
|
||||
in: path
|
||||
description: "Region (id) that is required"
|
||||
type: string
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
200:
|
||||
description: "OK"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "Country not found"
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- "regions"
|
||||
summary: "Delete a specific region of a given country"
|
||||
description: ""
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Country (id) of the region"
|
||||
type: string
|
||||
required: true
|
||||
- name: id
|
||||
in: path
|
||||
description: "Region (id) that is to be deleted"
|
||||
type: string
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
204:
|
||||
description: "OK, region was deleted"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "Region does not exist"
|
||||
405:
|
||||
description: "Region has cities, cannot be deleted"
|
||||
|
||||
put:
|
||||
tags:
|
||||
- "regions"
|
||||
summary: "Update a specific region of a given country"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- text/plain
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Country (id) of the region"
|
||||
type: string
|
||||
required: true
|
||||
- name: id
|
||||
in: path
|
||||
description: "Region (id) that is to be deleted"
|
||||
type: string
|
||||
required: true
|
||||
- in: formData
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
description: The region's new name.
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
204:
|
||||
description: "OK, region was updated"
|
||||
400:
|
||||
description: "Name missing, region not updated"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "Country not found"
|
||||
|
||||
/countries:
|
||||
get:
|
||||
tags:
|
||||
- "countries"
|
||||
summary: "Get all countries"
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
200:
|
||||
description: "OK"
|
||||
401:
|
||||
description: "No token provided"
|
||||
|
||||
/countries/{country}:
|
||||
get:
|
||||
tags:
|
||||
- "countries"
|
||||
summary: "Get a single country"
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Required Country"
|
||||
type: string
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
200:
|
||||
description: "OK"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "Country not found"
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- "countries"
|
||||
summary: "Delete a specific country"
|
||||
description: ""
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Country to delete"
|
||||
type: string
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
204:
|
||||
description: "OK, country was deleted"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "Country does not exist"
|
||||
405:
|
||||
description: "Country has regions, cannot be deleted"
|
||||
|
||||
put:
|
||||
tags:
|
||||
- "countries"
|
||||
summary: "Update or create a country"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- text/plain
|
||||
parameters:
|
||||
- name: country
|
||||
in: path
|
||||
description: "Country"
|
||||
type: string
|
||||
required: true
|
||||
- in: formData
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
description: The region's new name.
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
204:
|
||||
description: "OK, coutry was updated"
|
||||
400:
|
||||
description: "Name missing, country not updated"
|
||||
401:
|
||||
description: "No token provided"
|
||||
|
||||
/cities:
|
||||
post:
|
||||
tags:
|
||||
- "cities"
|
||||
summary: "Add a city"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- text/plain
|
||||
parameters:
|
||||
- in: formData
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
description: The new city's name.
|
||||
- in: formData
|
||||
name: latitude
|
||||
required: true
|
||||
type: number
|
||||
description: The new city's latitude.
|
||||
- in: formData
|
||||
name: longitude
|
||||
required: true
|
||||
type: number
|
||||
description: The new city's longitude.
|
||||
- in: formData
|
||||
name: population
|
||||
required: true
|
||||
type: number
|
||||
description: The new city's population.
|
||||
- in: formData
|
||||
name: countryCode
|
||||
required: true
|
||||
type: string
|
||||
description: The new city's country.
|
||||
- in: formData
|
||||
name: regionCode
|
||||
required: true
|
||||
type: string
|
||||
description: The new city's region.
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
201:
|
||||
description: "OK, created"
|
||||
400:
|
||||
description: "Name missing, city not created"
|
||||
401:
|
||||
description: "No token provided"
|
||||
403:
|
||||
description: "Region not found, city not created"
|
||||
409:
|
||||
description: "Other failure, city not created"
|
||||
|
||||
/cities/{cityId}:
|
||||
get:
|
||||
tags:
|
||||
- "cities"
|
||||
summary: "Get a specific city"
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- name: cityId
|
||||
in: path
|
||||
description: "Id of the city"
|
||||
type: number
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
200:
|
||||
description: "OK"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "City not found"
|
||||
|
||||
delete:
|
||||
tags:
|
||||
- "cities"
|
||||
summary: "Delete a specific city"
|
||||
description: ""
|
||||
parameters:
|
||||
- name: cityId
|
||||
in: path
|
||||
description: "Id of the city"
|
||||
type: number
|
||||
required: true
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
204:
|
||||
description: "OK, city was deleted"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "City does not exist"
|
||||
|
||||
put:
|
||||
tags:
|
||||
- "cities"
|
||||
summary: "Update a specific city"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- text/plain
|
||||
parameters:
|
||||
- name: cityId
|
||||
in: path
|
||||
description: "Id of the city"
|
||||
type: number
|
||||
required: true
|
||||
- in: formData
|
||||
name: name
|
||||
required: true
|
||||
type: string
|
||||
description: The new city's name.
|
||||
- in: formData
|
||||
name: latitude
|
||||
required: true
|
||||
type: number
|
||||
description: The new city's latitude.
|
||||
- in: formData
|
||||
name: longitude
|
||||
required: true
|
||||
type: number
|
||||
description: The new city's longitude.
|
||||
- in: formData
|
||||
name: population
|
||||
required: true
|
||||
type: number
|
||||
description: The new city's population.
|
||||
- in: formData
|
||||
name: countryCode
|
||||
required: true
|
||||
type: string
|
||||
description: The new city's country.
|
||||
- in: formData
|
||||
name: regionCode
|
||||
required: true
|
||||
type: string
|
||||
description: The new city's region.
|
||||
- in: header
|
||||
name: "Authorization"
|
||||
required: true
|
||||
type: string
|
||||
description: Authorization Token
|
||||
responses:
|
||||
204:
|
||||
description: "OK, city was updated"
|
||||
400:
|
||||
description: "Name missing, city not updated"
|
||||
401:
|
||||
description: "No token provided"
|
||||
404:
|
||||
description: "City not found"
|
||||
Generated
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
Reference in New Issue
Block a user