aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2018-10-25 22:22:55 +0200
committerMarvin Borner2018-10-25 22:22:55 +0200
commit1309e462efc4a7bbdf538e9d209133c1b3c138a6 (patch)
tree74be20f30280b52e891f7f3507c9d8569fad6b61
parent185e0f26c6680c64cb5f2befdedd0cc3bbf09df5 (diff)
Added authentication and post endpoint
-rw-r--r--config/default.json25
-rw-r--r--package-lock.json504
-rw-r--r--package.json6
-rw-r--r--src/app.js7
-rw-r--r--src/authentication.js27
-rw-r--r--src/models/posts.model.js28
-rw-r--r--src/models/users.model.js36
-rw-r--r--src/sequelize.js70
-rw-r--r--src/services/index.js4
-rw-r--r--src/services/posts/posts.hooks.js33
-rw-r--r--src/services/posts/posts.service.js22
-rw-r--r--src/services/users/users.hooks.js41
-rw-r--r--src/services/users/users.service.js22
-rw-r--r--test/services/posts.test.js10
-rw-r--r--test/services/users.test.js10
15 files changed, 833 insertions, 12 deletions
diff --git a/config/default.json b/config/default.json
index 7d29175..186d94d 100644
--- a/config/default.json
+++ b/config/default.json
@@ -5,5 +5,30 @@
"paginate": {
"default": 10,
"max": 50
+ },
+ "mysql": "mysql://root:root@localhost:3306/texx",
+ "authentication": {
+ "secret": "545c26b716c16d00e792322ea4642185515eeb2ff11f1c497fe22e8bc97362873d60fe47c063deafdf30f9bb40115795a84ecc389647f5e80f4063b1ccf2de09e3c1dcbe32f235075e6356f36e06e115843a3f0713cec71bda8f01632858a33a3e0547a70c4d04c7e88ba123bf38178cfb2b0f5435e50394fa8c836c3e196eb1f03fd109c0a31a3ff146244edbbd90baf752405077b6506cd12951d282020903e06e789292ca833475fde9f28cff27ce122dad5137d6bcdd2129133e87caa4a466060b216be85046a6029b100b5f72f57b82f0a788197e4107cd77f66d4435b9631e3b06ffaa55ded2c92bf19576fb28f1b646a402ce05262f662c21e04d29f0",
+ "strategies": [
+ "jwt",
+ "local"
+ ],
+ "path": "/authentication",
+ "service": "users",
+ "jwt": {
+ "header": {
+ "typ": "access"
+ },
+ "audience": "https://yourdomain.com",
+ "subject": "anonymous",
+ "issuer": "feathers",
+ "algorithm": "HS256",
+ "expiresIn": "1d"
+ },
+ "local": {
+ "entity": "user",
+ "usernameField": "email",
+ "passwordField": "password"
+ }
}
}
diff --git a/package-lock.json b/package-lock.json
index c750eac..516d4b2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -24,6 +24,51 @@
"js-tokens": "^4.0.0"
}
},
+ "@feathersjs/authentication": {
+ "version": "2.1.11",
+ "resolved": "https://registry.npmjs.org/@feathersjs/authentication/-/authentication-2.1.11.tgz",
+ "integrity": "sha512-i8O30V0AdUQtIq79D6JxRZtNox/8M5ZG0xxtBFuwasy+iiIJK5FDG7r/YZUbhHuhdvt0OmUZeztaQC7Xihu4XQ==",
+ "requires": {
+ "@feathersjs/commons": "^3.0.1",
+ "@feathersjs/errors": "^3.3.4",
+ "@feathersjs/socket-commons": "^3.1.2",
+ "debug": "^4.0.0",
+ "jsonwebtoken": "^8.0.0",
+ "lodash.clone": "^4.5.0",
+ "lodash.merge": "^4.6.0",
+ "lodash.omit": "^4.5.0",
+ "lodash.pick": "^4.4.0",
+ "long-timeout": "^0.1.1",
+ "ms": "^2.0.0",
+ "passport": "^0.4.0",
+ "uuid": "^3.1.0"
+ }
+ },
+ "@feathersjs/authentication-jwt": {
+ "version": "2.0.5",
+ "resolved": "https://registry.npmjs.org/@feathersjs/authentication-jwt/-/authentication-jwt-2.0.5.tgz",
+ "integrity": "sha512-ajgQQ7m4JzWmWWR0uJR+R4UmnR3XIiEQC0VGunaTOblAJLk3pIKteVFWeGh45YO5HwmOF9h4txKBHsVT3qEf0g==",
+ "requires": {
+ "@feathersjs/errors": "^3.3.4",
+ "debug": "^4.0.0",
+ "lodash.merge": "^4.6.0",
+ "lodash.omit": "^4.5.0",
+ "lodash.pick": "^4.4.0",
+ "passport-jwt": "^4.0.0"
+ }
+ },
+ "@feathersjs/authentication-local": {
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/@feathersjs/authentication-local/-/authentication-local-1.2.5.tgz",
+ "integrity": "sha512-8wgxSrOOIge8RoAOWPLKkWz9JTMNIg13QCoZOx3K/zL6gp9s0tph3jygfWcX6kvHM07KI4QPK/7uSNbBBHGE6A==",
+ "requires": {
+ "@feathersjs/errors": "^3.3.4",
+ "bcryptjs": "^2.3.0",
+ "debug": "^4.0.0",
+ "lodash": "^4.17.5",
+ "passport-local": "^1.0.0"
+ }
+ },
"@feathersjs/commons": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@feathersjs/commons/-/commons-3.0.1.tgz",
@@ -69,6 +114,27 @@
"uberproto": "^2.0.2"
}
},
+ "@feathersjs/socket-commons": {
+ "version": "3.1.5",
+ "resolved": "https://registry.npmjs.org/@feathersjs/socket-commons/-/socket-commons-3.1.5.tgz",
+ "integrity": "sha512-cnMqVNGR0fOM00UqRmslmPiUZ2UKToTxesoGwZvhvq4unF032KzS4gz8bZ7qYsin9HmAP/E2gs2v0119CR7LKQ==",
+ "requires": {
+ "@feathersjs/errors": "^3.0.0",
+ "debug": "^3.1.0",
+ "lodash": "^4.17.4",
+ "url-pattern": "^1.0.3"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.2.6",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
+ "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
+ "requires": {
+ "ms": "^2.1.1"
+ }
+ }
+ }
+ },
"@feathersjs/socketio": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/@feathersjs/socketio/-/socketio-3.2.6.tgz",
@@ -92,6 +158,16 @@
"radix-router": "^3.0.1"
}
},
+ "@types/geojson": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-1.0.6.tgz",
+ "integrity": "sha512-Xqg/lIZMrUd0VRmSRbCAewtwGZiAk3mEUDvV4op1tGl+LvyPcb/MIOSxTl9z+9+J+R4/vpjiCAT4xeKzH9ji1w=="
+ },
+ "@types/node": {
+ "version": "10.12.0",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.0.tgz",
+ "integrity": "sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ=="
+ },
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@@ -175,6 +251,11 @@
"color-convert": "^1.9.0"
}
},
+ "ansicolors": {
+ "version": "0.3.2",
+ "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz",
+ "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk="
+ },
"anymatch": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz",
@@ -399,6 +480,11 @@
"tweetnacl": "^0.14.3"
}
},
+ "bcryptjs": {
+ "version": "2.4.3",
+ "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
+ "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms="
+ },
"better-assert": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz",
@@ -421,8 +507,7 @@
"bluebird": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.2.tgz",
- "integrity": "sha512-dhHTWMI7kMx5whMQntl7Vr9C6BvV10lFXDAasnqnrMYhXVCzzk6IO9Fo2L75jXHT07WrOngL1WDXOp+yYS91Yg==",
- "dev": true
+ "integrity": "sha512-dhHTWMI7kMx5whMQntl7Vr9C6BvV10lFXDAasnqnrMYhXVCzzk6IO9Fo2L75jXHT07WrOngL1WDXOp+yYS91Yg=="
},
"body-parser": {
"version": "1.18.3",
@@ -516,6 +601,11 @@
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
"dev": true
},
+ "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="
+ },
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
@@ -575,6 +665,15 @@
"integrity": "sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==",
"dev": true
},
+ "cardinal": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/cardinal/-/cardinal-2.1.1.tgz",
+ "integrity": "sha1-fMEFXYItISlU0HsIXeolHMe8VQU=",
+ "requires": {
+ "ansicolors": "~0.3.2",
+ "redeyed": "~2.1.0"
+ }
+ },
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
@@ -675,6 +774,15 @@
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=",
"dev": true
},
+ "cls-bluebird": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/cls-bluebird/-/cls-bluebird-2.1.0.tgz",
+ "integrity": "sha1-N+8eCAqP+1XC9BZPU28ZGeeWiu4=",
+ "requires": {
+ "is-bluebird": "^1.0.2",
+ "shimmer": "^1.1.0"
+ }
+ },
"co": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
@@ -1018,6 +1126,11 @@
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"dev": true
},
+ "denque": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/denque/-/denque-1.3.0.tgz",
+ "integrity": "sha512-4SRaSj+PqmrS1soW5/Avd7eJIM2JJIqLLmwhRqIGleZM/8KwZq80njbSS2Iqas+6oARkSkLDHEk4mm78q3JlIg=="
+ },
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
@@ -1072,6 +1185,11 @@
"is-obj": "^1.0.0"
}
},
+ "dottie": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.1.tgz",
+ "integrity": "sha512-ch5OQgvGDK2u8pSZeSYAQaV/lczImd7pMJ7BcEPXmnFVjy4yJIzP6CsODJUTH8mg1tyH1Z2abOiuJO3DjZ/GBw=="
+ },
"duplexer": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz",
@@ -1095,6 +1213,14 @@
"safer-buffer": "^2.1.0"
}
},
+ "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.0.1"
+ }
+ },
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
@@ -1294,8 +1420,7 @@
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
- "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
- "dev": true
+ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"esquery": {
"version": "1.0.1",
@@ -1630,6 +1755,24 @@
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz",
"integrity": "sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg=="
},
+ "feathers-sequelize": {
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/feathers-sequelize/-/feathers-sequelize-3.1.2.tgz",
+ "integrity": "sha512-K7Bp7jdOUTUy3srtCWbYuIieW2QXNBdbJ8D2ipQOi1a44oSSDPorLB3+IRQtb+t51ylNijqiV/tPqd9jnZeEFQ==",
+ "requires": {
+ "@feathersjs/commons": "^1.3.0",
+ "@feathersjs/errors": "^3.2.0",
+ "lodash.omit": "^4.3.0",
+ "uberproto": "^2.0.0"
+ },
+ "dependencies": {
+ "@feathersjs/commons": {
+ "version": "1.4.4",
+ "resolved": "https://registry.npmjs.org/@feathersjs/commons/-/commons-1.4.4.tgz",
+ "integrity": "sha512-ZPpzyZA3CPfoa9AuFv3BJUI/ubzaaXixp8T/pqeMFPT6DOaU/6oF7lz1RxwimzfJNna4gy/HByt0EoLSI3BKWg=="
+ }
+ }
+ },
"feature-policy": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/feature-policy/-/feature-policy-0.1.0.tgz",
@@ -2317,6 +2460,19 @@
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"dev": true
},
+ "generate-function": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
+ "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
+ "requires": {
+ "is-property": "^1.0.2"
+ }
+ },
+ "generic-pool": {
+ "version": "3.4.2",
+ "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.4.2.tgz",
+ "integrity": "sha512-H7cUpwCQSiJmAHM4c/aFu6fUfrhWXW1ncyh8ftxEPMu6AiYkHw9K8br720TGPZJbk5eOH2bynjZD1yPvdDAmag=="
+ },
"get-stream": {
"version": "3.0.0",
"resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
@@ -2648,6 +2804,11 @@
"resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz",
"integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10="
},
+ "inflection": {
+ "version": "1.12.0",
+ "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.12.0.tgz",
+ "integrity": "sha1-ogCTVlbW9fa8TcdQLhrstwMihBY="
+ },
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
@@ -2729,6 +2890,11 @@
"binary-extensions": "^1.0.0"
}
},
+ "is-bluebird": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/is-bluebird/-/is-bluebird-1.0.2.tgz",
+ "integrity": "sha1-CWQ5Bg9KpBGr7hkUOoTWpVNG1uI="
+ },
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
@@ -2891,6 +3057,11 @@
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
"dev": true
},
+ "is-property": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
+ "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ="
+ },
"is-redirect": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz",
@@ -3004,6 +3175,22 @@
"minimist": "^1.2.0"
}
},
+ "jsonwebtoken": {
+ "version": "8.3.0",
+ "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.3.0.tgz",
+ "integrity": "sha512-oge/hvlmeJCH+iIz1DwcO7vKPkNGJHhgkspk8OH3VKlw+mbi42WtD4ig1+VXRln765vxptAv+xT26Fd3cteqag==",
+ "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.0.0",
+ "ms": "^2.1.1"
+ }
+ },
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@@ -3016,6 +3203,25 @@
"verror": "1.10.0"
}
},
+ "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.0.1"
+ }
+ },
+ "jws": {
+ "version": "3.1.5",
+ "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.5.tgz",
+ "integrity": "sha512-GsCSexFADNQUr8T5HPJvayTjvPIfoyJPtLQBwn5a4WZQchcrPMPMAWcC1AzJVRDKyD6ZPROPAxgv6rfHViO4uQ==",
+ "requires": {
+ "jwa": "^1.1.5",
+ "safe-buffer": "^5.0.1"
+ }
+ },
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
@@ -3054,12 +3260,67 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
+ "lodash.clone": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz",
+ "integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y="
+ },
"lodash.debounce": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
"integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=",
"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.merge": {
+ "version": "4.6.1",
+ "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz",
+ "integrity": "sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ=="
+ },
+ "lodash.omit": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz",
+ "integrity": "sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA="
+ },
+ "lodash.once": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
+ "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
+ },
+ "lodash.pick": {
+ "version": "4.4.0",
+ "resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz",
+ "integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM="
+ },
"logform": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/logform/-/logform-1.10.0.tgz",
@@ -3072,6 +3333,16 @@
"triple-beam": "^1.2.0"
}
},
+ "long": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
+ "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
+ },
+ "long-timeout": {
+ "version": "0.1.1",
+ "resolved": "https://registry.npmjs.org/long-timeout/-/long-timeout-0.1.1.tgz",
+ "integrity": "sha1-lyHXiLR+C8taJMLivuGg2lXatRQ="
+ },
"lowercase-keys": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz",
@@ -3297,6 +3568,19 @@
}
}
},
+ "moment": {
+ "version": "2.22.2",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
+ "integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
+ },
+ "moment-timezone": {
+ "version": "0.5.21",
+ "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.21.tgz",
+ "integrity": "sha512-j96bAh4otsgj3lKydm3K7kdtA3iKf2m6MY2iSYCzCm5a1zmHo1g+aK3068dDEeocLZQIS9kU8bsdQHLqEvgW0A==",
+ "requires": {
+ "moment": ">= 2.9.0"
+ }
+ },
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
@@ -3308,6 +3592,49 @@
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
"dev": true
},
+ "mysql2": {
+ "version": "1.6.1",
+ "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-1.6.1.tgz",
+ "integrity": "sha512-BNrJH5HavPqskXEy8oVz7ucRbkhegKQ7VD8rNGFwvTuk0WiUSi1wXFOg67NjCGquZnim8nKgHdDiih6LqG5knA==",
+ "requires": {
+ "cardinal": "2.1.1",
+ "denque": "1.3.0",
+ "generate-function": "^2.0.0",
+ "iconv-lite": "^0.4.18",
+ "long": "^4.0.0",
+ "lru-cache": "4.1.1",
+ "named-placeholders": "1.1.1",
+ "object-assign": "^4.1.1",
+ "seq-queue": "0.0.5",
+ "sqlstring": "2.3.1"
+ },
+ "dependencies": {
+ "lru-cache": {
+ "version": "4.1.1",
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz",
+ "integrity": "sha512-q4spe4KTfsAS1SUHLO0wz8Qiyf1+vMIAgpRYioFYDMNqKfHQbg+AVDH3i4fvpl71/P1L0dBl+fQi+P37UYf0ew==",
+ "requires": {
+ "pseudomap": "^1.0.2",
+ "yallist": "^2.1.2"
+ }
+ }
+ }
+ },
+ "named-placeholders": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.1.tgz",
+ "integrity": "sha1-O3oNJiA910s6nfTJz7gnsvuQfmQ=",
+ "requires": {
+ "lru-cache": "2.5.0"
+ },
+ "dependencies": {
+ "lru-cache": {
+ "version": "2.5.0",
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz",
+ "integrity": "sha1-2COIrpyWC+y+oMc7uet5tsbOmus="
+ }
+ }
+ },
"nan": {
"version": "2.10.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
@@ -3578,6 +3905,37 @@
"integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=",
"dev": true
},
+ "passport": {
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/passport/-/passport-0.4.0.tgz",
+ "integrity": "sha1-xQlWkTR71a07XhgCOMORTRbwWBE=",
+ "requires": {
+ "passport-strategy": "1.x.x",
+ "pause": "0.0.1"
+ }
+ },
+ "passport-jwt": {
+ "version": "4.0.0",
+ "resolved": "http://registry.npmjs.org/passport-jwt/-/passport-jwt-4.0.0.tgz",
+ "integrity": "sha512-BwC0n2GP/1hMVjR4QpnvqA61TxenUMlmfNjYNgK0ZAs0HK4SOQkHcSv4L328blNTLtHq7DbmvyNJiH+bn6C5Mg==",
+ "requires": {
+ "jsonwebtoken": "^8.2.0",
+ "passport-strategy": "^1.0.0"
+ }
+ },
+ "passport-local": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/passport-local/-/passport-local-1.0.0.tgz",
+ "integrity": "sha1-H+YyaMkudWBmJkN+O5BmYsFbpu4=",
+ "requires": {
+ "passport-strategy": "1.x.x"
+ }
+ },
+ "passport-strategy": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
+ "integrity": "sha1-tVOaqPwiWj0a0XlHbd8ja0QPUuQ="
+ },
"path-dirname": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz",
@@ -3607,6 +3965,11 @@
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
+ "pause": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz",
+ "integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10="
+ },
"pause-stream": {
"version": "0.0.11",
"resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz",
@@ -3704,8 +4067,7 @@
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
- "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=",
- "dev": true
+ "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM="
},
"psl": {
"version": "1.1.29",
@@ -3799,6 +4161,14 @@
"set-immediate-shim": "^1.0.1"
}
},
+ "redeyed": {
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/redeyed/-/redeyed-2.1.1.tgz",
+ "integrity": "sha1-iYS1gV2ZyyIEacme7v/jiRPmzAs=",
+ "requires": {
+ "esprima": "~4.0.0"
+ }
+ },
"referrer-policy": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/referrer-policy/-/referrer-policy-1.1.0.tgz",
@@ -3944,6 +4314,30 @@
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==",
"dev": true
},
+ "retry-as-promised": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-2.3.2.tgz",
+ "integrity": "sha1-zZdO5P2bX+A8vzGHHuSCIcB3N7c=",
+ "requires": {
+ "bluebird": "^3.4.6",
+ "debug": "^2.6.9"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
+ }
+ }
+ },
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
@@ -3993,8 +4387,7 @@
"semver": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
- "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==",
- "dev": true
+ "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg=="
},
"semver-diff": {
"version": "2.1.0",
@@ -4040,6 +4433,45 @@
}
}
},
+ "seq-queue": {
+ "version": "0.0.5",
+ "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz",
+ "integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4="
+ },
+ "sequelize": {
+ "version": "4.41.0",
+ "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-4.41.0.tgz",
+ "integrity": "sha512-6zCYxjPriUBgLQ5dN4ZxC5eadUtRu2tHFoBiSU9vNGb6G3f4bZM6vFpJu0DhxeeyhodTAXqY1GaBpZzT3PXB/Q==",
+ "requires": {
+ "bluebird": "^3.5.0",
+ "cls-bluebird": "^2.1.0",
+ "debug": "^3.1.0",
+ "depd": "^1.1.0",
+ "dottie": "^2.0.0",
+ "generic-pool": "^3.4.0",
+ "inflection": "1.12.0",
+ "lodash": "^4.17.1",
+ "moment": "^2.20.0",
+ "moment-timezone": "^0.5.14",
+ "retry-as-promised": "^2.3.2",
+ "semver": "^5.5.0",
+ "terraformer-wkt-parser": "^1.1.2",
+ "toposort-class": "^1.0.1",
+ "uuid": "^3.2.1",
+ "validator": "^10.4.0",
+ "wkx": "^0.4.1"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.2.6",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
+ "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
+ "requires": {
+ "ms": "^2.1.1"
+ }
+ }
+ }
+ },
"serve-favicon": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/serve-favicon/-/serve-favicon-2.5.0.tgz",
@@ -4119,6 +4551,11 @@
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"dev": true
},
+ "shimmer": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/shimmer/-/shimmer-1.2.0.tgz",
+ "integrity": "sha512-xTCx2vohXC2EWWDqY/zb4+5Mu28D+HYNSOuFzsyRDRvI/e1ICb69afwaUwfjr+25ZXldbOLyp+iDUZHq8UnTag=="
+ },
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
@@ -4407,6 +4844,11 @@
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
+ "sqlstring": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
+ "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A="
+ },
"sshpk": {
"version": "1.14.2",
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.2.tgz",
@@ -4541,6 +4983,23 @@
"execa": "^0.7.0"
}
},
+ "terraformer": {
+ "version": "1.0.9",
+ "resolved": "https://registry.npmjs.org/terraformer/-/terraformer-1.0.9.tgz",
+ "integrity": "sha512-YlmQ1fsMWTkKGDGibCRWgmLzrpDRUr63Q025LJ/taYQ6j1Yb8q9McKF7NBi6ACAyUXO6F/bl9w6v4MY307y5Ag==",
+ "requires": {
+ "@types/geojson": "^1.0.0"
+ }
+ },
+ "terraformer-wkt-parser": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/terraformer-wkt-parser/-/terraformer-wkt-parser-1.2.0.tgz",
+ "integrity": "sha512-QU3iA54St5lF8Za1jg1oj4NYc8sn5tCZ08aNSWDeGzrsaV48eZk1iAVWasxhNspYBoCqdHuoot1pUTUrE1AJ4w==",
+ "requires": {
+ "@types/geojson": "^1.0.0",
+ "terraformer": "~1.0.5"
+ }
+ },
"text-hex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz",
@@ -4620,6 +5079,11 @@
"repeat-string": "^1.6.1"
}
},
+ "toposort-class": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz",
+ "integrity": "sha1-f/0feMi+KMO6Rc1OGj9e4ZO9mYg="
+ },
"touch": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
@@ -4877,6 +5341,11 @@
"prepend-http": "^1.0.1"
}
},
+ "url-pattern": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/url-pattern/-/url-pattern-1.0.3.tgz",
+ "integrity": "sha1-BAkpJHGyTyPFDWWkeTF5PStaz8E="
+ },
"use": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",
@@ -4896,8 +5365,12 @@
"uuid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
- "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==",
- "dev": true
+ "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
+ },
+ "validator": {
+ "version": "10.8.0",
+ "resolved": "https://registry.npmjs.org/validator/-/validator-10.8.0.tgz",
+ "integrity": "sha512-mXqMxfCh5NLsVgYVKl9WvnHNDPCcbNppHSPPowu0VjtSsGWVY+z8hJF44edLR1nbLNzi3jYoYsIl8KZpioIk6g=="
},
"vary": {
"version": "1.1.2",
@@ -4958,6 +5431,14 @@
"triple-beam": "^1.2.0"
}
},
+ "wkx": {
+ "version": "0.4.5",
+ "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.4.5.tgz",
+ "integrity": "sha512-01dloEcJZAJabLO5XdcRgqdKpmnxS0zIT02LhkdWOZX2Zs2tPM6hlZ4XG9tWaWur1Qd1OO4kJxUbe2+5BofvnA==",
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"wordwrap": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
@@ -5019,8 +5500,7 @@
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
- "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
- "dev": true
+ "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI="
},
"yeast": {
"version": "0.1.2",
diff --git a/package.json b/package.json
index 4f910ef..e565949 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,9 @@
"mocha": "mocha test/ --recursive --exit"
},
"dependencies": {
+ "@feathersjs/authentication": "^2.1.11",
+ "@feathersjs/authentication-jwt": "^2.0.5",
+ "@feathersjs/authentication-local": "^1.2.5",
"@feathersjs/configuration": "^2.0.4",
"@feathersjs/errors": "^3.3.4",
"@feathersjs/express": "^1.2.7",
@@ -36,7 +39,10 @@
"@feathersjs/socketio": "^3.2.6",
"compression": "^1.7.3",
"cors": "^2.8.4",
+ "feathers-sequelize": "^3.1.2",
"helmet": "^3.14.0",
+ "mysql2": "^1.6.1",
+ "sequelize": "^4.41.0",
"serve-favicon": "^2.5.0",
"winston": "^3.1.0"
},
diff --git a/src/app.js b/src/app.js
index 2a8636f..38dc6dc 100644
--- a/src/app.js
+++ b/src/app.js
@@ -16,6 +16,10 @@ const services = require('./services');
const appHooks = require('./app.hooks');
const channels = require('./channels');
+const sequelize = require('./sequelize');
+
+const authentication = require('./authentication');
+
const app = express(feathers());
// Load app configuration
@@ -34,8 +38,11 @@ app.use('/', express.static(app.get('public')));
app.configure(express.rest());
app.configure(socketio());
+app.configure(sequelize);
+
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware);
+app.configure(authentication);
// Set up our services (see `services/index.js`)
app.configure(services);
// Set up event channels (see channels.js)
diff --git a/src/authentication.js b/src/authentication.js
new file mode 100644
index 0000000..3312a46
--- /dev/null
+++ b/src/authentication.js
@@ -0,0 +1,27 @@
+const authentication = require('@feathersjs/authentication');
+const jwt = require('@feathersjs/authentication-jwt');
+const local = require('@feathersjs/authentication-local');
+
+
+module.exports = function (app) {
+ const config = app.get('authentication');
+
+ // Set up authentication with the secret
+ app.configure(authentication(config));
+ app.configure(jwt());
+ app.configure(local());
+
+ // The `authentication` service is used to create a JWT.
+ // The before `create` hook registers strategies that can be used
+ // to create a new valid JWT (e.g. local or oauth2)
+ app.service('authentication').hooks({
+ before: {
+ create: [
+ authentication.hooks.authenticate(config.strategies)
+ ],
+ remove: [
+ authentication.hooks.authenticate('jwt')
+ ]
+ }
+ });
+};
diff --git a/src/models/posts.model.js b/src/models/posts.model.js
new file mode 100644
index 0000000..e46117c
--- /dev/null
+++ b/src/models/posts.model.js
@@ -0,0 +1,28 @@
+// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
+// for more of what you can do here.
+const Sequelize = require('sequelize');
+const DataTypes = Sequelize.DataTypes;
+
+module.exports = function (app) {
+ const sequelizeClient = app.get('sequelizeClient');
+ const posts = sequelizeClient.define('posts', {
+ text: {
+ type: DataTypes.STRING,
+ allowNull: false
+ }
+ }, {
+ hooks: {
+ beforeCount(options) {
+ options.raw = true;
+ }
+ }
+ });
+
+ // eslint-disable-next-line no-unused-vars
+ posts.associate = function (models) {
+ // Define associations here
+ // See http://docs.sequelizejs.com/en/latest/docs/associations/
+ };
+
+ return posts;
+};
diff --git a/src/models/users.model.js b/src/models/users.model.js
new file mode 100644
index 0000000..407e712
--- /dev/null
+++ b/src/models/users.model.js
@@ -0,0 +1,36 @@
+// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
+// for more of what you can do here.
+const Sequelize = require('sequelize');
+const DataTypes = Sequelize.DataTypes;
+
+module.exports = function (app) {
+ const sequelizeClient = app.get('sequelizeClient');
+ const users = sequelizeClient.define('users', {
+
+ email: {
+ type: DataTypes.STRING(126),
+ allowNull: false,
+ unique: true
+ },
+ password: {
+ type: DataTypes.STRING(126),
+ allowNull: false
+ },
+
+
+ }, {
+ hooks: {
+ beforeCount(options) {
+ options.raw = true;
+ }
+ }
+ });
+
+ // eslint-disable-next-line no-unused-vars
+ users.associate = function (models) {
+ // Define associations here
+ // See http://docs.sequelizejs.com/en/latest/docs/associations/
+ };
+
+ return users;
+};
diff --git a/src/sequelize.js b/src/sequelize.js
new file mode 100644
index 0000000..5afa78a
--- /dev/null
+++ b/src/sequelize.js
@@ -0,0 +1,70 @@
+const Sequelize = require('sequelize');
+const { Op } = Sequelize;
+const operatorsAliases = {
+ $eq: Op.eq,
+ $ne: Op.ne,
+ $gte: Op.gte,
+ $gt: Op.gt,
+ $lte: Op.lte,
+ $lt: Op.lt,
+ $not: Op.not,
+ $in: Op.in,
+ $notIn: Op.notIn,
+ $is: Op.is,
+ $like: Op.like,
+ $notLike: Op.notLike,
+ $iLike: Op.iLike,
+ $notILike: Op.notILike,
+ $regexp: Op.regexp,
+ $notRegexp: Op.notRegexp,
+ $iRegexp: Op.iRegexp,
+ $notIRegexp: Op.notIRegexp,
+ $between: Op.between,
+ $notBetween: Op.notBetween,
+ $overlap: Op.overlap,
+ $contains: Op.contains,
+ $contained: Op.contained,
+ $adjacent: Op.adjacent,
+ $strictLeft: Op.strictLeft,
+ $strictRight: Op.strictRight,
+ $noExtendRight: Op.noExtendRight,
+ $noExtendLeft: Op.noExtendLeft,
+ $and: Op.and,
+ $or: Op.or,
+ $any: Op.any,
+ $all: Op.all,
+ $values: Op.values,
+ $col: Op.col
+};
+
+module.exports = function (app) {
+ const connectionString = app.get('mysql');
+ const sequelize = new Sequelize(connectionString, {
+ dialect: 'mysql',
+ logging: false,
+ operatorsAliases,
+ define: {
+ freezeTableName: true
+ }
+ });
+ const oldSetup = app.setup;
+
+ app.set('sequelizeClient', sequelize);
+
+ app.setup = function (...args) {
+ const result = oldSetup.apply(this, args);
+
+ // Set up data relationships
+ const models = sequelize.models;
+ Object.keys(models).forEach(name => {
+ if ('associate' in models[name]) {
+ models[name].associate(models);
+ }
+ });
+
+ // Sync to the database
+ sequelize.sync();
+
+ return result;
+ };
+};
diff --git a/src/services/index.js b/src/services/index.js
index 791edad..ccbb889 100644
--- a/src/services/index.js
+++ b/src/services/index.js
@@ -1,3 +1,7 @@
+const posts = require('./posts/posts.service.js');
+const users = require('./users/users.service.js');
// eslint-disable-next-line no-unused-vars
module.exports = function (app) {
+ app.configure(posts);
+ app.configure(users);
};
diff --git a/src/services/posts/posts.hooks.js b/src/services/posts/posts.hooks.js
new file mode 100644
index 0000000..39ac996
--- /dev/null
+++ b/src/services/posts/posts.hooks.js
@@ -0,0 +1,33 @@
+const {authenticate} = require('@feathersjs/authentication').hooks;
+
+module.exports = {
+ before: {
+ all: [authenticate('jwt')],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ },
+
+ after: {
+ all: [],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ },
+
+ error: {
+ all: [],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ }
+};
diff --git a/src/services/posts/posts.service.js b/src/services/posts/posts.service.js
new file mode 100644
index 0000000..cacde6e
--- /dev/null
+++ b/src/services/posts/posts.service.js
@@ -0,0 +1,22 @@
+// Initializes the `posts` service on path `/posts`
+const createService = require('feathers-sequelize');
+const createModel = require('../../models/posts.model');
+const hooks = require('./posts.hooks');
+
+module.exports = function (app) {
+ const Model = createModel(app);
+ const paginate = app.get('paginate');
+
+ const options = {
+ Model,
+ paginate
+ };
+
+ // Initialize our service with any options it requires
+ app.use('/posts', createService(options));
+
+ // Get our initialized service so that we can register hooks
+ const service = app.service('posts');
+
+ service.hooks(hooks);
+};
diff --git a/src/services/users/users.hooks.js b/src/services/users/users.hooks.js
new file mode 100644
index 0000000..613676b
--- /dev/null
+++ b/src/services/users/users.hooks.js
@@ -0,0 +1,41 @@
+const { authenticate } = require('@feathersjs/authentication').hooks;
+
+const {
+ hashPassword, protect
+} = require('@feathersjs/authentication-local').hooks;
+
+module.exports = {
+ before: {
+ all: [],
+ find: [ authenticate('jwt') ],
+ get: [ authenticate('jwt') ],
+ create: [ hashPassword() ],
+ update: [ hashPassword(), authenticate('jwt') ],
+ patch: [ hashPassword(), authenticate('jwt') ],
+ remove: [ authenticate('jwt') ]
+ },
+
+ after: {
+ all: [
+ // Make sure the password field is never sent to the client
+ // Always must be the last hook
+ protect('password')
+ ],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ },
+
+ error: {
+ all: [],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ }
+};
diff --git a/src/services/users/users.service.js b/src/services/users/users.service.js
new file mode 100644
index 0000000..3cb0535
--- /dev/null
+++ b/src/services/users/users.service.js
@@ -0,0 +1,22 @@
+// Initializes the `users` service on path `/users`
+const createService = require('feathers-sequelize');
+const createModel = require('../../models/users.model');
+const hooks = require('./users.hooks');
+
+module.exports = function (app) {
+ const Model = createModel(app);
+ const paginate = app.get('paginate');
+
+ const options = {
+ Model,
+ paginate
+ };
+
+ // Initialize our service with any options it requires
+ app.use('/users', createService(options));
+
+ // Get our initialized service so that we can register hooks
+ const service = app.service('users');
+
+ service.hooks(hooks);
+};
diff --git a/test/services/posts.test.js b/test/services/posts.test.js
new file mode 100644
index 0000000..a4bdd63
--- /dev/null
+++ b/test/services/posts.test.js
@@ -0,0 +1,10 @@
+const assert = require('assert');
+const app = require('../../src/app');
+
+describe('\'posts\' service', () => {
+ it('registered the service', () => {
+ const service = app.service('posts');
+
+ assert.ok(service, 'Registered the service');
+ });
+});
diff --git a/test/services/users.test.js b/test/services/users.test.js
new file mode 100644
index 0000000..cc555e5
--- /dev/null
+++ b/test/services/users.test.js
@@ -0,0 +1,10 @@
+const assert = require('assert');
+const app = require('../../src/app');
+
+describe('\'users\' service', () => {
+ it('registered the service', () => {
+ const service = app.service('users');
+
+ assert.ok(service, 'Registered the service');
+ });
+});