gina 0.0.9-p91b → 0.1.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +46 -0
- package/{core/asset/html/static.html → Icon/r} +0 -0
- package/LICENSE +1 -1
- package/README-4Contributors.md +96 -0
- package/README.md +296 -104
- package/bin/cli +287 -0
- package/bin/cli-debug +60 -0
- package/bin/cmd +184 -0
- package/bin/gina +180 -0
- package/config/logger.json +17 -0
- package/doc/framework/cli/doc.json +9 -0
- package/doc/framework/index.md +60 -0
- package/framework/v0.1.1-alpha.2/AUTHORS +7 -0
- package/{core/utils/lib/inherits → framework/v0.1.1-alpha.2}/LICENSE +1 -1
- package/framework/v0.1.1-alpha.2/VERSION +1 -0
- package/{core/locales/dist/language/en.json → framework/v0.1.1-alpha.2/core/asset/html/nolayout.html} +0 -0
- package/{core/locales/dist/language/fr.json → framework/v0.1.1-alpha.2/core/asset/html/static.html} +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/android-chrome-192x192.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/android-chrome-512x512.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/apple-touch-icon.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon-16x16.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon-32x32.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.js +20904 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.js.map +56 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.css +1 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.css.map +1 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.js +736 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.js.map +56 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.onload.min.js +5 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.onload.min.js.map +8 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/readme.md +192 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/uuid.json +23 -0
- package/framework/v0.1.1-alpha.2/core/config.js +2308 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/index.js +757 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.js +20 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.v2.js +429 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.v3.js +432 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/n1ql.js +14 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.js +21 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.v2.js +258 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.v3.js +341 -0
- package/{core → framework/v0.1.1-alpha.2/core}/controller/controller.framework.js +3 -2
- package/framework/v0.1.1-alpha.2/core/controller/controller.js +3990 -0
- package/{core → framework/v0.1.1-alpha.2/core}/controller/index.js +5 -5
- package/framework/v0.1.1-alpha.2/core/deps/busboy/.travis.yml +17 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/LICENSE +19 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/README.md +225 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/deps/encoding/encoding-indexes.js +73 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/deps/encoding/encoding.js +2391 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/main.js +89 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/types/multipart.js +328 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/types/urlencoded.js +214 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/utils.js +191 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/package.json +69 -0
- package/framework/v0.1.1-alpha.2/core/deps/swig-client/swig-2.0.0.min.js +5 -0
- package/{core → framework/v0.1.1-alpha.2/core}/dev/index.js +5 -5
- package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/class.js +1 -1
- package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/factory.js +1 -1
- package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/tools.js +0 -0
- package/framework/v0.1.1-alpha.2/core/gna.js +1070 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/README.md +41 -2
- package/{core → framework/v0.1.1-alpha.2/core}/locales/currency.json +0 -0
- package/{core/plugins/README.md → framework/v0.1.1-alpha.2/core/locales/dist/language/en.json} +0 -0
- package/{core/plugins/lib/intl/README.md → framework/v0.1.1-alpha.2/core/locales/dist/language/fr.json} +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/dist/region/en.json +0 -0
- package/framework/v0.1.1-alpha.2/core/locales/dist/region/fr.json +9492 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/index.js +5 -4
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/make.js +15 -12
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/currency.csv +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/region.csv +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/region.mapping.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/mime.types +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/model/entity.js +156 -196
- package/{core → framework/v0.1.1-alpha.2/core}/model/index.js +67 -48
- package/{core → framework/v0.1.1-alpha.2/core}/model/template/entityFactory.js +2 -2
- package/{core → framework/v0.1.1-alpha.2/core}/model/template/index.js +8 -10
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.2/core/plugins}/README.md +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/index.js +3 -3
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.2/core/plugins/lib/file}/README.md +0 -0
- package/{core/plugins/lib/intl → framework/v0.1.1-alpha.2/core/plugins/lib/file}/build.json +0 -0
- package/framework/v0.1.1-alpha.2/core/plugins/lib/file/package.json +25 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.2/core/plugins/lib/intl}/README.md +0 -0
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.2/core/plugins/lib/intl}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/intl/package.json +3 -3
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/intl/src/main.js +17 -1
- package/{core/utils/lib/routing → framework/v0.1.1-alpha.2/core/plugins/lib/storage}/README.md +0 -0
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.2/core/plugins/lib/storage}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/storage/package.json +2 -2
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/storage/src/main.js +91 -85
- package/{core/utils/lib/url → framework/v0.1.1-alpha.2/core/plugins/lib/validator}/README.md +0 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.2/core/plugins/lib/validator}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/validator/package.json +3 -3
- package/framework/v0.1.1-alpha.2/core/plugins/lib/validator/src/form-validator.js +1762 -0
- package/framework/v0.1.1-alpha.2/core/plugins/lib/validator/src/main.js +6917 -0
- package/framework/v0.1.1-alpha.2/core/router.js +664 -0
- package/framework/v0.1.1-alpha.2/core/server.express.js +213 -0
- package/framework/v0.1.1-alpha.2/core/server.isaac.js +386 -0
- package/framework/v0.1.1-alpha.2/core/server.js +3010 -0
- package/{core → framework/v0.1.1-alpha.2/core}/status.codes +8 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/app.json +6 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/routing.json +11 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/settings.json +9 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/settings.server.json +30 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/templates.json +42 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/controller.content.js +39 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/controller.js +30 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/setup.js +111 -0
- package/{core/template/samples → framework/v0.1.1-alpha.2/core/template/boilerplate}/bundle/index.js +0 -0
- package/{core/template/samples/bundle → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_namespace}/controllers/controller.js +9 -7
- package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/css/default.css +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/css/vendor/readme.md +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public/js/vendor/readme.md +1 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public/readme.md +1 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/handlers/main.js +24 -0
- package/{core/template/views/html/default.html → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/html/homepage.html} +0 -0
- package/{core/template/views/html/layout.html → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/html/layout/main.html} +2 -2
- package/{core → framework/v0.1.1-alpha.2/core}/template/command/gina.bat.tpl +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/command/gina.tpl +1 -1
- package/framework/v0.1.1-alpha.2/core/template/conf/env.json +76 -0
- package/{core/template/conf/project.json → framework/v0.1.1-alpha.2/core/template/conf/manifest.json} +1 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/conf/package.json +2 -2
- package/framework/v0.1.1-alpha.2/core/template/conf/settings.json +92 -0
- package/framework/v0.1.1-alpha.2/core/template/conf/statics.json +10 -0
- package/framework/v0.1.1-alpha.2/core/template/conf/templates.json +37 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/401.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/403.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/404.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/html/50x.html +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/json/500.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/json/503.json +0 -0
- package/{core/utils/lib/routing/build.json → framework/v0.1.1-alpha.2/core/template/extensions/logger/config.json} +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/console.js +3 -3
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/context.js +240 -49
- package/framework/v0.1.1-alpha.2/helpers/dateFormat.js +528 -0
- package/framework/v0.1.1-alpha.2/helpers/index.js +79 -0
- package/framework/v0.1.1-alpha.2/helpers/json/README.md +0 -0
- package/framework/v0.1.1-alpha.2/helpers/json/package.json +20 -0
- package/framework/v0.1.1-alpha.2/helpers/json/src/main.js +97 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/path.js +342 -140
- package/framework/v0.1.1-alpha.2/helpers/plugins/README.md +4 -0
- package/framework/v0.1.1-alpha.2/helpers/plugins/package.json +20 -0
- package/framework/v0.1.1-alpha.2/helpers/plugins/src/api-error.js +160 -0
- package/framework/v0.1.1-alpha.2/helpers/plugins/src/main.js +32 -0
- package/framework/v0.1.1-alpha.2/helpers/prototypes.js +218 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/task.js +49 -29
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/text.js +7 -7
- package/framework/v0.1.1-alpha.2/lib/archiver/README.md +0 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/build.json +0 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/src/dep/jszip.min.js +15 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/src/main.js +499 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/aliases.json +13 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/add.js +507 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/arguments.json +4 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/copy.js +15 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/cp.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/help.txt +67 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/list.js +129 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/remove.js +229 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/rename.js +4 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/restart.js +235 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/start.js +394 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/status.js +3 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/stop.js +232 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/add.js +436 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/get.js +62 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/help.txt +33 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/link-dev.js +80 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/list.js +111 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/remove.js +150 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/set.js +57 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/unset.js +44 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/use.js +79 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/dot.js +70 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/get.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/help.js +39 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/help.txt +31 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/init.js +514 -0
- package/{core/utils/lib/cmd → framework/v0.1.1-alpha.2/lib/cmd/framework}/msg.json +3 -3
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/open.js +50 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/restart.js +124 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/set.js +161 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/start.js +96 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/status.js +72 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/stop.js +159 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/tail.js +183 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/update.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/version.js +44 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/gina-dev.1.md +66 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/gina-framework.1.md +100 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/gina.1.md +79 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/helper.js +1147 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/index.js +170 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/msg.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/help.txt +31 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/inc/scan.js +108 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/list.js +176 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/set.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/add.js +528 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/arguments.json +9 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/build.js +115 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/help.txt +76 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/import.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/list.js +55 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/move.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/remove.js +144 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/rename.js +162 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/restart.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/start.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/status.js +3 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/stop.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/help.js +27 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/help.txt +57 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/list.js +239 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/set.js +631 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/help.txt +33 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/link-local.js +80 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/list.js +116 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/remove.js +150 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/set.js +57 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/unset.js +44 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/use.js +79 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/view/add.js +311 -0
- package/framework/v0.1.1-alpha.2/lib/collection/README.md +5 -0
- package/framework/v0.1.1-alpha.2/lib/collection/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/collection/package.json +2 -2
- package/framework/v0.1.1-alpha.2/lib/collection/src/main.js +1459 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/config.js +49 -34
- package/framework/v0.1.1-alpha.2/lib/cron/README.md +7 -0
- package/framework/v0.1.1-alpha.2/lib/cron/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/cron/src/main.js +176 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/generator/index.js +8 -4
- package/framework/v0.1.1-alpha.2/lib/index.js +116 -0
- package/framework/v0.1.1-alpha.2/lib/inherits/LICENSE +19 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/inheriting_eventemitter.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/protected_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/simple_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/super_attribute_overridden_by_child_on_init.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/package.json +2 -2
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/src/main.js +18 -19
- package/framework/v0.1.1-alpha.2/lib/logger/README.md +7 -0
- package/framework/v0.1.1-alpha.2/lib/logger/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/default/index.js +55 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/index.js +251 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/lib/logrotator/README.md +100 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/lib/logrotator/index.js +274 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/index.js +52 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/listener.js +302 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/speaker.js +118 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/helper.js +131 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/main.js +734 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/math/index.js +58 -35
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/README.md +5 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge.js +1 -1
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge_2_literal objects.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge_and_preserve_first.js +2 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/package.json +2 -2
- package/framework/v0.1.1-alpha.2/lib/merge/src/main.js +531 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/model.js +42 -19
- package/framework/v0.1.1-alpha.2/lib/proc.js +518 -0
- package/framework/v0.1.1-alpha.2/lib/routing/README.md +0 -0
- package/framework/v0.1.1-alpha.2/lib/routing/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/routing/package.json +2 -2
- package/framework/v0.1.1-alpha.2/lib/routing/src/main.js +1492 -0
- package/framework/v0.1.1-alpha.2/lib/session-store.js +33 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/shell.js +43 -30
- package/framework/v0.1.1-alpha.2/lib/swig-filters/README.md +0 -0
- package/framework/v0.1.1-alpha.2/lib/swig-filters/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/swig-filters/src/main.js +322 -0
- package/framework/v0.1.1-alpha.2/lib/url/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/index.js +2 -1
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/mocks.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/routing.json +9 -9
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/test.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/validator.js +7 -7
- package/framework/v0.1.1-alpha.2/package.json +14 -0
- package/package.json +35 -33
- package/resources/etc/init.d/debian/gina +117 -0
- package/resources/home/framework/env.json +34 -0
- package/resources/home/framework/locals.json +14 -0
- package/resources/home/framework/project.json +48 -0
- package/resources/home/framework/projects.json +6 -0
- package/resources/home/main.json +47 -0
- package/resources/home/settings.json +22 -0
- package/resources/home/user/extensions/logger/default/config.json +77 -0
- package/resources/home/user/extensions/logger/file/config.json +11 -0
- package/resources/img/android-chrome-192x192.png +0 -0
- package/resources/img/android-chrome-512x512.png +0 -0
- package/resources/img/apple-touch-icon.png +0 -0
- package/resources/img/favicon-16x16.png +0 -0
- package/resources/img/favicon-32x32.png +0 -0
- package/resources/img/favicon.ico +0 -0
- package/resources/package.json.template +50 -0
- package/script/lib.js +24 -0
- package/script/post_install.js +449 -157
- package/script/pre_install.js +277 -36
- package/script/prepare_version.js +425 -0
- package/utils/helper.js +438 -0
- package/utils/prototypes.js +239 -0
- package/utils/prototypes.json_clone.js +175 -0
- package/.npmignore +0 -6
- package/MIDDLEWARE +0 -1
- package/SUCCESS +0 -1
- package/VERSION +0 -1
- package/core/asset/html/nolayout.html +0 -1
- package/core/asset/js/plugin/build.dev.json +0 -28
- package/core/asset/js/plugin/build.json +0 -31
- package/core/asset/js/plugin/dist/gina.min.css +0 -1
- package/core/asset/js/plugin/dist/gina.min.css.map +0 -1
- package/core/asset/js/plugin/dist/gina.min.js +0 -13731
- package/core/asset/js/plugin/dist/gina.min.js.map +0 -42
- package/core/asset/js/plugin/dist/gina.onload.min.js +0 -3
- package/core/asset/js/plugin/dist/gina.onload.min.js.map +0 -8
- package/core/asset/js/plugin/readme.md +0 -152
- package/core/asset/js/plugin/src/gina/main.js +0 -132
- package/core/asset/js/plugin/src/gina/popin/css/design.css +0 -23
- package/core/asset/js/plugin/src/gina/popin/css/main.css +0 -1112
- package/core/asset/js/plugin/src/gina/popin/css/popin.css +0 -3
- package/core/asset/js/plugin/src/gina/popin/css/popin.css.map +0 -1
- package/core/asset/js/plugin/src/gina/popin/doc/TOC.md +0 -29
- package/core/asset/js/plugin/src/gina/popin/doc/css.md +0 -162
- package/core/asset/js/plugin/src/gina/popin/doc/extend.md +0 -663
- package/core/asset/js/plugin/src/gina/popin/doc/faq.md +0 -46
- package/core/asset/js/plugin/src/gina/popin/doc/html.md +0 -227
- package/core/asset/js/plugin/src/gina/popin/doc/js.md +0 -37
- package/core/asset/js/plugin/src/gina/popin/doc/misc.md +0 -178
- package/core/asset/js/plugin/src/gina/popin/doc/usage.md +0 -130
- package/core/asset/js/plugin/src/gina/popin/main.js +0 -783
- package/core/asset/js/plugin/src/gina/popin/sass/config.sass +0 -37
- package/core/asset/js/plugin/src/gina/popin/sass/gina-design.sass +0 -622
- package/core/asset/js/plugin/src/gina/popin/sass/gina-popin.sass +0 -54
- package/core/asset/js/plugin/src/gina/popin/sass/helper.scss +0 -73
- package/core/asset/js/plugin/src/gina/toolbar/.npmignore +0 -19
- package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css +0 -433
- package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css.map +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/index.html +0 -285
- package/core/asset/js/plugin/src/gina/toolbar/index.kit +0 -120
- package/core/asset/js/plugin/src/gina/toolbar/jquery-3.1.0.min.js +0 -4
- package/core/asset/js/plugin/src/gina/toolbar/main.js +0 -693
- package/core/asset/js/plugin/src/gina/toolbar/mock.gina.json +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/mock.user.json +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/readme.md +0 -7
- package/core/asset/js/plugin/src/gina/toolbar/sass/toolbar.sass +0 -563
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/info-optim.svg +0 -13
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/logo-gina.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings-big.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.afdesign +0 -0
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/test.jpg +0 -0
- package/core/asset/js/plugin/src/gina/toolbar/toolbar.html +0 -104
- package/core/asset/js/plugin/src/gina/utils/dom.js +0 -24
- package/core/asset/js/plugin/src/gina/utils/events.js +0 -201
- package/core/asset/js/plugin/src/gina/utils/loader.js +0 -57
- package/core/asset/js/plugin/src/main.js +0 -235
- package/core/asset/js/plugin/src/vendor/jquery/1.11.1-css-event_alias.min.js +0 -5
- package/core/asset/js/plugin/src/vendor/jquery/1.12.4.min.js +0 -5
- package/core/asset/js/plugin/src/vendor/jquery/2.1.1-css-event_alias-sizzle.min.js +0 -4
- package/core/asset/js/plugin/src/vendor/jquery/README.md +0 -14
- package/core/asset/js/plugin/src/vendor/jquery/slim-3.1.1.min.js +0 -4
- package/core/config.js +0 -1225
- package/core/controller/controller.js +0 -1860
- package/core/gna.js +0 -908
- package/core/plugins/lib/validator/src/form-validator.js +0 -788
- package/core/plugins/lib/validator/src/main.js +0 -2056
- package/core/router.js +0 -717
- package/core/server.js +0 -1363
- package/core/template/conf/env.json +0 -70
- package/core/template/conf/settings.json +0 -48
- package/core/template/conf/statics.json +0 -6
- package/core/template/conf/views.json +0 -16
- package/core/template/samples/bundle/config/app.json +0 -4
- package/core/template/samples/bundle/config/routing.json +0 -9
- package/core/template/samples/bundle/controllers/setup.js +0 -33
- package/core/template/views/js/vendor/readme.md +0 -1
- package/core/template/views/readme.md +0 -1
- package/core/utils/helpers/dateFormat.js +0 -264
- package/core/utils/helpers/index.js +0 -202
- package/core/utils/index.js +0 -75
- package/core/utils/lib/cmd/app.js +0 -686
- package/core/utils/lib/cmd/basic.help.txt +0 -40
- package/core/utils/lib/cmd/basic.js +0 -141
- package/core/utils/lib/cmd/gina-add-bundle.js +0 -328
- package/core/utils/lib/cmd/gina-add-views.js +0 -99
- package/core/utils/lib/cmd/gina-build.js +0 -218
- package/core/utils/lib/cmd/gina-clean.js +0 -26
- package/core/utils/lib/cmd/gina-connect.js +0 -176
- package/core/utils/lib/cmd/gina-delete-bundle.js +0 -176
- package/core/utils/lib/cmd/gina-deploy.js +0 -452
- package/core/utils/lib/cmd/gina-init-project.js +0 -83
- package/core/utils/lib/cmd/gina-start-bundle.js +0 -3
- package/core/utils/lib/cmd/gina-start.js +0 -3
- package/core/utils/lib/cmd/index.js +0 -157
- package/core/utils/lib/cmd/project.js +0 -14
- package/core/utils/lib/collection/src/main.js +0 -650
- package/core/utils/lib/logger/containers/file.js +0 -11
- package/core/utils/lib/logger/index.js +0 -260
- package/core/utils/lib/merge/src/main.js +0 -344
- package/core/utils/lib/proc.js +0 -416
- package/core/utils/lib/routing/src/main.js +0 -165
- package/documentation/css/default.css +0 -3
- package/documentation/html/home.html +0 -6
- package/documentation/html/inc/_footer.html +0 -5
- package/documentation/html/layout.html +0 -21
- package/documentation/img/debug-conf1.png +0 -0
- package/documentation/img/debug-conf2.png +0 -0
- package/documentation/img/debug-conf3.png +0 -0
- package/documentation/img/debug-conf4.png +0 -0
- package/documentation/img/debug-conf5.png +0 -0
- package/documentation/img/debug-conf6.png +0 -0
- package/documentation/img/debug-conf7.png +0 -0
- package/documentation/img/debug-new1.png +0 -0
- package/documentation/img/debug-new2.png +0 -0
- package/documentation/img/debug-start.png +0 -0
- package/documentation/md/api/controller/main.md +0 -74
- package/migration_note.md +0 -7
- package/package-lock.json +0 -611
- package/script/pre_publish.js +0 -207
- package/tutorial/Commands/README.md +0 -56
- package/tutorial/Commands/add-bundle-result.png +0 -0
- package/tutorial/Commands/add-bundle.png +0 -0
- package/tutorial/Commands/delete-bundle.png +0 -0
- package/tutorial/Commands/help.png +0 -0
- package/tutorial/Commands/init-project.png +0 -0
- package/tutorial/Commands/start-bundle-result.png +0 -0
- package/tutorial/Commands/start-bundle-stop.png +0 -0
- package/tutorial/Commands/start-bundle.png +0 -0
- package/tutorial/Commands/version.png +0 -0
- package/tutorial/ETC/README.md +0 -74
- package/tutorial/ETC/add-bundle-result.png +0 -0
- package/tutorial/ETC/add-bundle.png +0 -0
- package/tutorial/ETC/init-project.png +0 -0
- package/tutorial/Install/README.md +0 -54
- package/tutorial/Install/git-get.png +0 -0
- package/tutorial/Install/git-install-end.png +0 -0
- package/tutorial/Install/git-install-result.png +0 -0
- package/tutorial/Install/git-install-start.png +0 -0
- package/tutorial/Install/install-end.png +0 -0
- package/tutorial/Install/install-result.png +0 -0
- package/tutorial/Install/install-start.png +0 -0
- package/tutorial/WebStorm/README.md +0 -30
- package/tutorial/WebStorm/closure-compiler.png +0 -0
- package/tutorial/WebStorm/sass.png +0 -0
|
@@ -0,0 +1,1492 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the gina package.
|
|
3
|
+
* Copyright (c) 2009-2022 Rhinostone <contact@gina.io>
|
|
4
|
+
*
|
|
5
|
+
* For the full copyright and license information, please view the LICENSE
|
|
6
|
+
* file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Routing
|
|
11
|
+
*
|
|
12
|
+
* @package Gina.Lib
|
|
13
|
+
* @namespace Gina.Lib.Routing
|
|
14
|
+
* @author Rhinostone <contact@gina.io>
|
|
15
|
+
* */
|
|
16
|
+
|
|
17
|
+
function Routing() {
|
|
18
|
+
|
|
19
|
+
var isGFFCtx = ((typeof (module) !== 'undefined') && module.exports) ? false : true;
|
|
20
|
+
var self = {
|
|
21
|
+
allowedMethods: ['get', 'post', 'put', 'delete'],
|
|
22
|
+
reservedParams: ['controle', 'file','title', 'namespace', 'path'],
|
|
23
|
+
notFound: {}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
self.allowedMethodsString = self.allowedMethods.join(',');
|
|
27
|
+
|
|
28
|
+
// loading utils & plugins
|
|
29
|
+
var plugins = null, inherits = null, merge = null, Validator = null, fs = null, promisify = null;
|
|
30
|
+
if (!isGFFCtx) {
|
|
31
|
+
fs = require('fs');
|
|
32
|
+
promisify = require('util').promisify;
|
|
33
|
+
inherits = require('../../inherits');
|
|
34
|
+
merge = require('../../merge');
|
|
35
|
+
plugins = require(__dirname+'/../../../core/plugins') || getContext('gina').plugins;
|
|
36
|
+
Validator = plugins.Validator;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
// BO - In case of partial rendering whithout handler defined for the partial
|
|
40
|
+
else {
|
|
41
|
+
if ( !merge || typeof(merge) != 'function' ) {
|
|
42
|
+
var merge = require('utils/merge');
|
|
43
|
+
}
|
|
44
|
+
if ( !Validator || typeof(Validator) != 'function' ) {
|
|
45
|
+
var Validator = require('utils/form-validator');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// EO - In case of partial rendering whithout handler defined for the partial
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get url props
|
|
52
|
+
* Used to retrieve additional properties for routes with redirect flag for example
|
|
53
|
+
*
|
|
54
|
+
* @param {string} [bundle]
|
|
55
|
+
* @param {string} [env]
|
|
56
|
+
*
|
|
57
|
+
* @returns {object} urlProps - { .host, .hostname, .webroot }
|
|
58
|
+
*/
|
|
59
|
+
self.getUrlProps = function(bundle, env) {
|
|
60
|
+
var config = null, urlProps = {}, _route = null;
|
|
61
|
+
if (isGFFCtx) {
|
|
62
|
+
// TODO - add support to get from env
|
|
63
|
+
config = window.gina.config;
|
|
64
|
+
// by default
|
|
65
|
+
urlProps.hostname = config.hostname;
|
|
66
|
+
if ( typeof(bundle) != 'undefined' ) {
|
|
67
|
+
// get from webroot
|
|
68
|
+
_route = routing.getRoute('webroot@'+ bundle);
|
|
69
|
+
urlProps.hostname = _route.hostname;
|
|
70
|
+
urlProps.host = _route.host;
|
|
71
|
+
urlProps.webroot = _route.webroot;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
config = getContext('gina').config;
|
|
75
|
+
if ( typeof(getContext('argvFilename')) != 'undefined' ) {
|
|
76
|
+
config.getRouting = getContext('gina').Config.instance.getRouting
|
|
77
|
+
}
|
|
78
|
+
if ( typeof(bundle) == 'undefined' ) {
|
|
79
|
+
bundle = config.bundle;
|
|
80
|
+
}
|
|
81
|
+
if ( typeof(env) == 'undefined' ) {
|
|
82
|
+
env = config.env;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
urlProps.hostname = config.envConf[bundle][env].hostname;
|
|
86
|
+
urlProps.host = config.envConf[bundle][env].host;
|
|
87
|
+
urlProps.webroot = config.envConf[bundle][env].server.webroot;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return urlProps;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Load bundle routing configuration
|
|
95
|
+
*
|
|
96
|
+
* @param {object} options
|
|
97
|
+
* {
|
|
98
|
+
* isStadalone: false,
|
|
99
|
+
* bundle: 'default', // bundle's name
|
|
100
|
+
* wroot: '/', // by default
|
|
101
|
+
*
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
// self.loadBundleRoutingConfiguration = function(options, filename) {
|
|
106
|
+
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get routing
|
|
111
|
+
*
|
|
112
|
+
* @param {string} [bundle]
|
|
113
|
+
*/
|
|
114
|
+
// self.getRouting = function(bundle) {
|
|
115
|
+
|
|
116
|
+
// }
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get reversed routing
|
|
120
|
+
*
|
|
121
|
+
* @param {string} [bundle]
|
|
122
|
+
*/
|
|
123
|
+
// self.getReverseRouting = function(bundle) {
|
|
124
|
+
|
|
125
|
+
// }
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Compare urls
|
|
129
|
+
*
|
|
130
|
+
* @param {object} params - Route params containing the given url to be compared with
|
|
131
|
+
* @param {string|array} url - routing.json url
|
|
132
|
+
* @param {object} [request]
|
|
133
|
+
* @param {object} [response] - only used for query validation
|
|
134
|
+
* @param {object} [next] - only used for query validation
|
|
135
|
+
*
|
|
136
|
+
* @returns {object|false} foundRoute
|
|
137
|
+
* */
|
|
138
|
+
self.compareUrls = async function(params, url, request, response, next) {
|
|
139
|
+
|
|
140
|
+
if ( typeof(request) == 'undefined' ) {
|
|
141
|
+
request = { routing: {} };
|
|
142
|
+
}
|
|
143
|
+
// Sample debug break for specific rule
|
|
144
|
+
// if ( params.rule == 'my-specific-rule@bundle' ) {
|
|
145
|
+
// console.debug('passed '+ params.rule);
|
|
146
|
+
// }
|
|
147
|
+
if ( /\,/.test(url) ) {
|
|
148
|
+
var i = 0
|
|
149
|
+
, urls = url.split(/\,/g)
|
|
150
|
+
, len = urls.length
|
|
151
|
+
, foundRoute = {
|
|
152
|
+
past: false,
|
|
153
|
+
request: request
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
while (i < len && !foundRoute.past) {
|
|
158
|
+
foundRoute = await parseRouting(params, urls[i], request, response, next);
|
|
159
|
+
++i;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return foundRoute;
|
|
163
|
+
} else {
|
|
164
|
+
return await parseRouting(params, url, request, response, next);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Check if rule has params
|
|
170
|
+
*
|
|
171
|
+
* @param {string} pathname
|
|
172
|
+
* @returns {boolean} found
|
|
173
|
+
*
|
|
174
|
+
* @private
|
|
175
|
+
* */
|
|
176
|
+
var hasParams = function(pathname) {
|
|
177
|
+
return (/:/.test(pathname)) ? true : false;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Parse routing for mathcing url
|
|
182
|
+
*
|
|
183
|
+
* @param {object} params - `params` is the same `request.routing` that can be retried in controller with: req.routing
|
|
184
|
+
* @param {string} url
|
|
185
|
+
* @param {object} request
|
|
186
|
+
* @param {object} [response] - Only used for query validation
|
|
187
|
+
* @param {object} [next] - Only used for query validation
|
|
188
|
+
*
|
|
189
|
+
* @returns {object} foundRoute
|
|
190
|
+
*
|
|
191
|
+
* */
|
|
192
|
+
var parseRouting = async function(params, url, request, response, next) {
|
|
193
|
+
|
|
194
|
+
// Sample debug break for specific rule
|
|
195
|
+
// if ( params.rule == 'my-specific-rule@bundle' ) {
|
|
196
|
+
// console.debug('passed '+ params.rule);
|
|
197
|
+
// }
|
|
198
|
+
|
|
199
|
+
var uRe = params.url.split(/\//)
|
|
200
|
+
, uRo = url.split(/\//)
|
|
201
|
+
, uReCount = 0
|
|
202
|
+
, uRoCount = 0
|
|
203
|
+
, maxLen = uRo.length
|
|
204
|
+
, score = 0
|
|
205
|
+
, foundRoute = {}
|
|
206
|
+
, i = 0
|
|
207
|
+
, method = request.method.toLowerCase()
|
|
208
|
+
;
|
|
209
|
+
|
|
210
|
+
// TODO - remove comments
|
|
211
|
+
// when requirement is not listed but still validated
|
|
212
|
+
// if (
|
|
213
|
+
// typeof(params.requirements) != 'undefined'
|
|
214
|
+
// && method == params.method.toLowerCase()
|
|
215
|
+
// //&& /validator\:\:/.test(JSON.stringify(params.requirements))
|
|
216
|
+
// ) {
|
|
217
|
+
|
|
218
|
+
// var requiremements = Object.getOwnPropertyNames(params.requirements);
|
|
219
|
+
// var r = 0;
|
|
220
|
+
// // In order to filter variables
|
|
221
|
+
// var uRoVars = uRo.join(',').match(/\:[-_a-z0-9]+/g);
|
|
222
|
+
// // var uRoVarCount = (uRoVars) ? uRoVars.length : 0;
|
|
223
|
+
// while ( r < requiremements.length ) {
|
|
224
|
+
|
|
225
|
+
// // if not listed, but still needing validation
|
|
226
|
+
// if (
|
|
227
|
+
// typeof(params.param[ requiremements[r] ]) == 'undefined'
|
|
228
|
+
// && /^validator\:\:/i.test(params.requirements[ requiremements[r] ])
|
|
229
|
+
// && typeof(request[method][ requiremements[r] ])
|
|
230
|
+
// ) {
|
|
231
|
+
// if (uRo.length != uRe.length) {
|
|
232
|
+
// // r++;
|
|
233
|
+
// // continue;
|
|
234
|
+
// break;
|
|
235
|
+
// }
|
|
236
|
+
// // updating uRoVars
|
|
237
|
+
// uRoVars = uRo.join(',').match(/\:[-_a-z0-9]+/g);
|
|
238
|
+
// /**
|
|
239
|
+
// * "requirements" : {
|
|
240
|
+
// * "email": "validator::{ isEmail: true, isString: [7] }"
|
|
241
|
+
// * }
|
|
242
|
+
// *
|
|
243
|
+
// * e.g.: result = new Validator('routing', _data, null, {email: {isEmail: true, subject: \"Anything\"}} ).isEmail().valid;
|
|
244
|
+
// */
|
|
245
|
+
// let regex = params.requirements[ requiremements[r] ];
|
|
246
|
+
// let _data = {}, _ruleObj = {}, _rule = {};
|
|
247
|
+
|
|
248
|
+
// try {
|
|
249
|
+
// _ruleObj = JSON.parse(
|
|
250
|
+
// regex.split(/::/).splice(1)[0]
|
|
251
|
+
// .replace(/([^\:\"\s+](\w+))\:/g, '"$1":') // { query: { validIf: true }} => { "query": { "validIf": true }}
|
|
252
|
+
// .replace(/([^\:\"\s+](\w+))\s+\:/g, '"$1":') // note the space between `validIf` & `:` { query: { validIf : true }} => { "query": { "validIf": true }}
|
|
253
|
+
// );
|
|
254
|
+
// } catch (err) {
|
|
255
|
+
// throw err;
|
|
256
|
+
// }
|
|
257
|
+
|
|
258
|
+
// let key = requiremements[r];
|
|
259
|
+
// // validator.query case
|
|
260
|
+
// if (typeof(_ruleObj.query) != 'undefined' && typeof(_ruleObj.query.data) != 'undefined') {
|
|
261
|
+
// _data = _ruleObj.query.data;
|
|
262
|
+
// // filter _data vs uRoVars by removing from data those not present in uRoVars
|
|
263
|
+
// for (let k in _data) {
|
|
264
|
+
// if ( uRoVars.indexOf(_data[k]) < 0 ) {
|
|
265
|
+
// delete _data[k]
|
|
266
|
+
// }
|
|
267
|
+
// }
|
|
268
|
+
// for (let p = 0, pLen = uRo.length; p < pLen; p++) {
|
|
269
|
+
// // :variable only
|
|
270
|
+
// if (!/^\:/.test(uRo[p])) continue;
|
|
271
|
+
|
|
272
|
+
// let pName = uRo[p].replace(/^\:/, '');
|
|
273
|
+
// if ( pName != '' && typeof(uRe[p]) != 'undefined' ) {
|
|
274
|
+
// _data[ pName ] = uRe[p];
|
|
275
|
+
// // Updating params
|
|
276
|
+
// if ( typeof(request.params[pName]) == 'undefined' ) {
|
|
277
|
+
// // Set in case it is not found
|
|
278
|
+
// request.params[pName] = uRe[p];
|
|
279
|
+
// }
|
|
280
|
+
// }
|
|
281
|
+
// }
|
|
282
|
+
// }
|
|
283
|
+
// // normal case
|
|
284
|
+
// _data = merge(_data, request[method]);
|
|
285
|
+
|
|
286
|
+
// if ( typeof(_data[key]) == 'undefined' ) {
|
|
287
|
+
// // init default value for unlisted variable/param
|
|
288
|
+
// _data[key] = null;
|
|
289
|
+
// }
|
|
290
|
+
|
|
291
|
+
// _rule[key] = _ruleObj;
|
|
292
|
+
// _validator = new Validator('routing', _data, null, _rule );
|
|
293
|
+
|
|
294
|
+
// if (_ruleObj.count() == 0 ) {
|
|
295
|
+
// console.error('Route validation failed '+ params.rule);
|
|
296
|
+
// return false;
|
|
297
|
+
// }
|
|
298
|
+
|
|
299
|
+
// for (let rule in _ruleObj) {
|
|
300
|
+
// let _result = null;
|
|
301
|
+
// if (Array.isArray(_ruleObj[rule])) { // has args
|
|
302
|
+
// _result = await _validator[key][rule].apply(_validator[key], _ruleObj[rule]);
|
|
303
|
+
// } else {
|
|
304
|
+
// _result = await _validator[key][rule](_ruleObj[rule], request, response, next);
|
|
305
|
+
// }
|
|
306
|
+
// //let condition = _ruleObj[rule].validIf.replace(new RegExp('\\$isValid'), _result.isValid);
|
|
307
|
+
// // if ( eval(condition)) {
|
|
308
|
+
// if ( !_result.isValid ) {
|
|
309
|
+
// --score;
|
|
310
|
+
// }
|
|
311
|
+
// }
|
|
312
|
+
// }
|
|
313
|
+
// r++
|
|
314
|
+
// }
|
|
315
|
+
// }
|
|
316
|
+
|
|
317
|
+
// attaching routing description for this request
|
|
318
|
+
var paramMethod = params.method.toLowerCase();
|
|
319
|
+
|
|
320
|
+
var hasAlreadyBeenScored = false;
|
|
321
|
+
if (
|
|
322
|
+
typeof(params.requirements) != 'undefined'
|
|
323
|
+
&& /get|delete/i.test(method)
|
|
324
|
+
&& typeof(request[method]) != 'undefined'
|
|
325
|
+
||
|
|
326
|
+
// GET request is in fact in this case a DELETE request
|
|
327
|
+
typeof(params.requirements) != 'undefined'
|
|
328
|
+
&& /get/i.test(method)
|
|
329
|
+
&& /delete/i.test(paramMethod)
|
|
330
|
+
) {
|
|
331
|
+
if ( /get/i.test(method) && /delete/i.test(paramMethod) ) {
|
|
332
|
+
method = paramMethod;
|
|
333
|
+
}
|
|
334
|
+
// `delete` methods don't have a body
|
|
335
|
+
// So, request.delete is {} by default
|
|
336
|
+
if ( /^(delete)$/i.test(method) && uRe.length === uRo.length ) {
|
|
337
|
+
// just in case
|
|
338
|
+
if ( typeof(request[method]) == 'undefined' ) {
|
|
339
|
+
request[method] = {};
|
|
340
|
+
}
|
|
341
|
+
for (let p = 0, pLen = uRo.length; p < pLen; p++) {
|
|
342
|
+
if (uRe[p] === uRo[p]) {
|
|
343
|
+
++score;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
let _key = uRo[p].substr(1);
|
|
347
|
+
if ( typeof(params.requirements[_key]) == 'undefined' ) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
let condition = params.requirements[_key];
|
|
351
|
+
if ( /^\//.test(condition) ) {
|
|
352
|
+
condition = condition.substr(1, condition.lastIndexOf('/')-1);
|
|
353
|
+
} else if ( /^validator\:\:/.test(condition) && await fitsWithRequirements(uRo[p], uRe[p], params, request, response, next) ) {
|
|
354
|
+
++score;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (
|
|
358
|
+
/^:/.test(uRo[p])
|
|
359
|
+
&& typeof(condition) != 'undefined'
|
|
360
|
+
&& new RegExp(condition).test(uRe[p])
|
|
361
|
+
) {
|
|
362
|
+
++score;
|
|
363
|
+
request[method][uRo[p].substr(1)] = uRe[p];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
hasAlreadyBeenScored = true;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Sample debug break for specific rule
|
|
370
|
+
// if ( params.rule == 'my-specific-rule@bundle' ) {
|
|
371
|
+
// console.debug('passed '+ params.rule);
|
|
372
|
+
// }
|
|
373
|
+
for (let p in request[method]) {
|
|
374
|
+
if ( typeof(params.requirements[p]) != 'undefined' && uRo.indexOf(':' + p) < 0 ) {
|
|
375
|
+
uRo[uRoCount] = ':' + p;
|
|
376
|
+
++uRoCount;
|
|
377
|
+
|
|
378
|
+
uRe[uReCount] = request[method][p];
|
|
379
|
+
++uReCount;
|
|
380
|
+
if (!hasAlreadyBeenScored && uRe.length === uRo.length)
|
|
381
|
+
++maxLen;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
// Sample debug break for specific rule
|
|
388
|
+
// if ( params.rule == 'my-specific-rule@bundle' ) {
|
|
389
|
+
// console.debug('passed '+ params.rule);
|
|
390
|
+
// }
|
|
391
|
+
|
|
392
|
+
if (!hasAlreadyBeenScored && uRe.length === uRo.length) {
|
|
393
|
+
|
|
394
|
+
for (; i < maxLen; ++i) {
|
|
395
|
+
|
|
396
|
+
if (uRe[i] === uRo[i]) {
|
|
397
|
+
++score;
|
|
398
|
+
}
|
|
399
|
+
else if (score == i && hasParams(uRo[i]) && await fitsWithRequirements(uRo[i], uRe[i], params, request, response, next)) {
|
|
400
|
+
++score;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// This test is done to catch `validator::` rules under requirements
|
|
406
|
+
if (
|
|
407
|
+
typeof(params.requirements) != 'undefined'
|
|
408
|
+
&& method == params.method.toLowerCase()
|
|
409
|
+
&& !hasAlreadyBeenScored
|
|
410
|
+
&& score >= maxLen
|
|
411
|
+
) {
|
|
412
|
+
|
|
413
|
+
var requiremements = Object.getOwnPropertyNames(params.requirements);
|
|
414
|
+
var r = 0;
|
|
415
|
+
// In order to filter variables
|
|
416
|
+
var uRoVars = uRo.join(',').match(/\:[-_a-z0-9]+/g);
|
|
417
|
+
// var uRoVarCount = (uRoVars) ? uRoVars.length : 0;
|
|
418
|
+
while ( r < requiremements.length ) {
|
|
419
|
+
// requirement name as `key`
|
|
420
|
+
let key = requiremements[r];
|
|
421
|
+
// if not listed, but still needing validation
|
|
422
|
+
if (
|
|
423
|
+
typeof(params.param[ key ]) == 'undefined'
|
|
424
|
+
&& /^validator\:\:/i.test(params.requirements[ key ])
|
|
425
|
+
) {
|
|
426
|
+
if (uRo.length != uRe.length) {
|
|
427
|
+
// r++;
|
|
428
|
+
// continue;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
// updating uRoVars
|
|
432
|
+
uRoVars = uRo.join(',').match(/\:[-_a-z0-9]+/g);
|
|
433
|
+
/**
|
|
434
|
+
* "requirements" : {
|
|
435
|
+
* "email": "validator::{ isEmail: true, isString: [7] }"
|
|
436
|
+
* }
|
|
437
|
+
*
|
|
438
|
+
* e.g.: result = new Validator('routing', _data, null, {email: {isEmail: true, subject: \"Anything\"}} ).isEmail().valid;
|
|
439
|
+
*/
|
|
440
|
+
let regex = params.requirements[ key ];
|
|
441
|
+
let _data = {}, _ruleObj = {}, _rule = {};
|
|
442
|
+
|
|
443
|
+
try {
|
|
444
|
+
_ruleObj = JSON.parse(
|
|
445
|
+
regex.split(/::/).splice(1)[0]
|
|
446
|
+
.replace(/([^\:\"\s+](\w+))\:/g, '"$1":') // { query: { validIf: true }} => { "query": { "validIf": true }}
|
|
447
|
+
.replace(/([^\:\"\s+](\w+))\s+\:/g, '"$1":') // note the space between `validIf` & `:` { query: { validIf : true }} => { "query": { "validIf": true }}
|
|
448
|
+
);
|
|
449
|
+
} catch (err) {
|
|
450
|
+
throw err;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// validator.query case
|
|
454
|
+
if (typeof(_ruleObj.query) != 'undefined' && typeof(_ruleObj.query.data) != 'undefined') {
|
|
455
|
+
_data = _ruleObj.query.data;
|
|
456
|
+
// filter _data vs uRoVars by removing from data those not present in uRoVars
|
|
457
|
+
for (let k in _data) {
|
|
458
|
+
if ( uRoVars.indexOf(_data[k]) < 0 ) {
|
|
459
|
+
delete _data[k]
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
for (let p = 0, pLen = uRo.length; p < pLen; p++) {
|
|
463
|
+
// :variable only
|
|
464
|
+
if (!/^\:/.test(uRo[p])) continue;
|
|
465
|
+
|
|
466
|
+
let pName = uRo[p].replace(/^\:/, '');
|
|
467
|
+
if ( pName != '' && typeof(uRe[p]) != 'undefined' ) {
|
|
468
|
+
_data[ pName ] = uRe[p];
|
|
469
|
+
// Updating params
|
|
470
|
+
if ( typeof(request.params[pName]) == 'undefined' ) {
|
|
471
|
+
// Set in case if not found
|
|
472
|
+
request.params[pName] = uRe[p];
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// If validator.query has data, _data should inherit from request data
|
|
479
|
+
_data = merge(_data, JSON.clone(request[method]) || {} );
|
|
480
|
+
// This test is to initialize query.data[key] to null by default
|
|
481
|
+
if ( typeof(_data[key]) == 'undefined' ) {
|
|
482
|
+
// init default value for unlisted variable/param
|
|
483
|
+
_data[key] = null;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
_rule[key] = _ruleObj;
|
|
487
|
+
if (!isGFFCtx) {
|
|
488
|
+
_validator = new Validator('routing', _data, null, _rule );
|
|
489
|
+
} else {
|
|
490
|
+
_validator = new Validator(_data);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (_ruleObj.count() == 0 ) {
|
|
494
|
+
console.error('Route validation failed '+ params.rule);
|
|
495
|
+
--score;
|
|
496
|
+
r++;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
// for each validation rule
|
|
500
|
+
for (let rule in _ruleObj) {
|
|
501
|
+
// updating query.data
|
|
502
|
+
if (typeof(_ruleObj[rule].data) != 'undefined') {
|
|
503
|
+
_ruleObj[rule].data = _data;
|
|
504
|
+
}
|
|
505
|
+
let _result = null;
|
|
506
|
+
if (Array.isArray(_ruleObj[rule])) { // has args
|
|
507
|
+
_result = await _validator[key][rule].apply(_validator[key], _ruleObj[rule]);
|
|
508
|
+
} else {
|
|
509
|
+
_result = await _validator[key][rule](_ruleObj[rule], request, response, next);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//let condition = _ruleObj[rule].validIf.replace(new RegExp('\\$isValid'), _result.isValid);
|
|
513
|
+
// if ( eval(condition)) {
|
|
514
|
+
if ( !_result.isValid ) {
|
|
515
|
+
--score;
|
|
516
|
+
if ( typeof(_result.error) != 'undefined' ) {
|
|
517
|
+
throw _result.error;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
r++
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
foundRoute.past = (score === maxLen) ? true : false;
|
|
527
|
+
|
|
528
|
+
if (foundRoute.past) {
|
|
529
|
+
// attaching routing description for this request
|
|
530
|
+
//request.routing = params; // can be retried in controller with: req.routing
|
|
531
|
+
// && replacing placeholders
|
|
532
|
+
request.routing = checkRouteParams(params, request[method]);
|
|
533
|
+
foundRoute.request = request;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
return foundRoute;
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Fits with requiremements
|
|
542
|
+
* This is for server side use only
|
|
543
|
+
* http://en.wikipedia.org/wiki/Regular_expression
|
|
544
|
+
*
|
|
545
|
+
* @param {string} urlVar
|
|
546
|
+
* @param {string} urlVal
|
|
547
|
+
* @param {object} params
|
|
548
|
+
*
|
|
549
|
+
* @returns {boolean} true|false - `true` if it fits
|
|
550
|
+
*
|
|
551
|
+
* @private
|
|
552
|
+
* */
|
|
553
|
+
var fitsWithRequirements = async function(urlVar, urlVal, params, request, response, next) {
|
|
554
|
+
// Sample debug break for specific rule
|
|
555
|
+
// if ( params.rule == 'my-specific-rule@bundle' ) {
|
|
556
|
+
// console.debug('passed '+ params.rule);
|
|
557
|
+
// }
|
|
558
|
+
//var isValid = new Validator('routing', { email: "contact@gina.io"}, null, {email: {isEmail: true}} ).isEmail().valid;
|
|
559
|
+
var matched = -1
|
|
560
|
+
, _param = urlVar.match(/\:\w+/g)
|
|
561
|
+
, regex = new RegExp(urlVar, 'g')
|
|
562
|
+
, re = null
|
|
563
|
+
, flags = null
|
|
564
|
+
, key = null
|
|
565
|
+
, tested = false
|
|
566
|
+
|
|
567
|
+
, _validator = null
|
|
568
|
+
, _data = null
|
|
569
|
+
, _ruleObj = null
|
|
570
|
+
, _rule = null
|
|
571
|
+
, rule = null
|
|
572
|
+
, str = null
|
|
573
|
+
// request method
|
|
574
|
+
, requestMethod = request.method.toLowerCase()
|
|
575
|
+
;
|
|
576
|
+
|
|
577
|
+
if (!_param.length) return false;
|
|
578
|
+
|
|
579
|
+
// if custom path, path rewrite
|
|
580
|
+
if (params.param.path && regex.test(params.param.path)) {
|
|
581
|
+
params.param.path = params.param.path.replace(regex, urlVal);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// if custom namespace, namespace rewrite
|
|
585
|
+
if (params.param.namespace && regex.test(params.param.namespace)) {
|
|
586
|
+
params.param.namespace = params.param.namespace.replace(regex, urlVal);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// if custom file, file rewrite
|
|
590
|
+
// if (params.param.file && regex.test(params.param.file)) {
|
|
591
|
+
// params.param.file = params.param.file.replace(regex, urlVal);
|
|
592
|
+
// }
|
|
593
|
+
// file is handle like url replacement (path is like pathname)
|
|
594
|
+
if (typeof (params.param.file) != 'undefined' && /:/.test(params.param.file)) {
|
|
595
|
+
var _regex = new RegExp('(:'+urlVar+'/|:'+urlVar+'$)', 'g');
|
|
596
|
+
replacement.variable = urlVal;
|
|
597
|
+
params.param.file = params.param.file.replace( _regex, replacement );
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// if custom title, title rewrite
|
|
601
|
+
if (params.param.title && regex.test(params.param.title)) {
|
|
602
|
+
params.param.title = params.param.title.replace(regex, urlVal);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (_param.length == 1) { // fast one
|
|
606
|
+
|
|
607
|
+
re = new RegExp( _param[0]);
|
|
608
|
+
matched = (_param.indexOf(urlVar) > -1) ? _param.indexOf(urlVar) : false;
|
|
609
|
+
|
|
610
|
+
if (matched === false ) {
|
|
611
|
+
// In order to support rules defined like :
|
|
612
|
+
// { params.url } => `/section/:name/page:number`
|
|
613
|
+
// { request.url } => `/section/plante/page4`
|
|
614
|
+
//
|
|
615
|
+
// with keys = [ ":name", ":number" ]
|
|
616
|
+
|
|
617
|
+
if ( urlVar.match(re) ) {
|
|
618
|
+
matched = 0;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
if (matched === false) return matched;
|
|
624
|
+
// filter on method
|
|
625
|
+
if (params.method.toLowerCase() !== requestMethod) return false;
|
|
626
|
+
|
|
627
|
+
if ( typeof(request[requestMethod]) == 'undefined' ) {
|
|
628
|
+
request[requestMethod] = {}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
key = _param[matched].substr(1);
|
|
632
|
+
// escaping `\` characters
|
|
633
|
+
// TODO - remove comment : all regex requirement must start with `/`
|
|
634
|
+
//regex = ( /\\/.test(params.requirements[key]) ) ? params.requirements[key].replace(/\\/, '') : params.requirements[key];
|
|
635
|
+
regex = params.requirements[key];
|
|
636
|
+
if (/^\//.test(regex)) {
|
|
637
|
+
re = regex.match(/\/(.*)\//).pop();
|
|
638
|
+
flags = regex.replace('/' + re + '/', '');
|
|
639
|
+
|
|
640
|
+
tested = new RegExp(re, flags).test(urlVal)
|
|
641
|
+
} else if ( /^validator\:\:/.test(regex) && urlVal) {
|
|
642
|
+
/**
|
|
643
|
+
* "requirements" : {
|
|
644
|
+
* "id" : "/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i",
|
|
645
|
+
* "email": "validator::{ isEmail: true, isString: [7] }"
|
|
646
|
+
* }
|
|
647
|
+
*
|
|
648
|
+
* e.g.: tested = new Validator('routing', _data, null, {email: {isEmail: true, subject: \"Anything\"}} ).isEmail().valid;
|
|
649
|
+
*/
|
|
650
|
+
_data = {}; _ruleObj = {}; _rule = {}; str = '';
|
|
651
|
+
urlVar.replace( new RegExp('[^'+ key +']','g'), function(){ str += arguments[0] });
|
|
652
|
+
_data[key] = urlVal.replace( new RegExp(str, 'g'), '');
|
|
653
|
+
try {
|
|
654
|
+
//_ruleObj = JSON.parse(regex.split(/::/).splice(1)[0].replace(/([^\W+ true false])+(\w+)/g, '"$&"'));
|
|
655
|
+
_ruleObj = JSON.parse(
|
|
656
|
+
regex.split(/::/).splice(1)[0]
|
|
657
|
+
.replace(/([^\:\"\s+](\w+))\:/g, '"$1":') // { query: { validIf: true }} => { "query": { "validIf": true }}
|
|
658
|
+
.replace(/([^\:\"\s+](\w+))\s+\:/g, '"$1":') // note the space between `validIf` & `:` { query: { validIf : true }} => { "query": { "validIf": true }}
|
|
659
|
+
);
|
|
660
|
+
} catch (err) {
|
|
661
|
+
throw err;
|
|
662
|
+
}
|
|
663
|
+
//_ruleObj = JSON.parse(regex.split(/::/).splice(1)[0].replace(/([^\W+ true false])+(\w+)/g, '"$&"'));
|
|
664
|
+
if (typeof(_ruleObj.query) != 'undefined' && typeof(_ruleObj.query.data) != 'undefined') {
|
|
665
|
+
// since we only have one param
|
|
666
|
+
// :var1 == :var1
|
|
667
|
+
if ( urlVar == _ruleObj.query.data[ Object.keys(_ruleObj.query.data)[0] ] ) {
|
|
668
|
+
_ruleObj.query.data[ Object.keys(_ruleObj.query.data)[0] ] = _data[key];
|
|
669
|
+
// Set in case it is not found
|
|
670
|
+
request.params[key] = _data[key];
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
_rule[key] = _ruleObj;
|
|
674
|
+
_validator = new Validator('routing', _data, null, _rule );
|
|
675
|
+
if (_ruleObj.count() == 0 ) {
|
|
676
|
+
console.error('Route validation failed '+ params.rule);
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
for (let rule in _ruleObj) {
|
|
680
|
+
if (Array.isArray(_ruleObj[rule])) { // has args
|
|
681
|
+
await _validator[key][rule].apply(_validator[key], _ruleObj[rule]);
|
|
682
|
+
} else {
|
|
683
|
+
await _validator[key][rule](_ruleObj[rule], request, response, next);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
tested = _validator.isValid();
|
|
687
|
+
} else {
|
|
688
|
+
tested = new RegExp(params.requirements[key]).test(urlVal);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
if (
|
|
692
|
+
typeof(params.param[key]) != 'undefined' &&
|
|
693
|
+
typeof(params.requirements) != 'undefined' &&
|
|
694
|
+
typeof(params.requirements[key]) != 'undefined' &&
|
|
695
|
+
typeof(request.params) != 'undefined' &&
|
|
696
|
+
tested
|
|
697
|
+
) {
|
|
698
|
+
request.params[key] = urlVal;
|
|
699
|
+
if ( typeof(request[requestMethod][key]) == 'undefined' ) {
|
|
700
|
+
request[requestMethod][key] = urlVal;
|
|
701
|
+
}
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
} else { // slow one
|
|
706
|
+
|
|
707
|
+
// In order to support rules defined like :
|
|
708
|
+
// { params.url } => `/section/:name/page:number`
|
|
709
|
+
// { request.url } => `/section/plante/page4`
|
|
710
|
+
//
|
|
711
|
+
// with keys = [ ":name", ":number" ]
|
|
712
|
+
|
|
713
|
+
var keys = _param
|
|
714
|
+
, tplUrl = params.url
|
|
715
|
+
, url = request.url
|
|
716
|
+
, values = {}
|
|
717
|
+
, strVal = ''
|
|
718
|
+
, started = false
|
|
719
|
+
, i = 0
|
|
720
|
+
;
|
|
721
|
+
|
|
722
|
+
for (var c = 0, posLen = url.length; c < posLen; ++c) {
|
|
723
|
+
if (url.charAt(c) == tplUrl.charAt(i) && !started) {
|
|
724
|
+
++i
|
|
725
|
+
continue
|
|
726
|
+
} else if (strVal == '') { // start
|
|
727
|
+
|
|
728
|
+
started = true;
|
|
729
|
+
strVal += url.charAt(c);
|
|
730
|
+
} else if (c > (tplUrl.indexOf(keys[0]) + keys[0].length)) {
|
|
731
|
+
|
|
732
|
+
regex = params.requirements[keys[0]];
|
|
733
|
+
urlVal = strVal.substr(0, strVal.length);
|
|
734
|
+
|
|
735
|
+
if (/^\//.test(regex)) {
|
|
736
|
+
re = regex.match(/\/(.*)\//).pop();
|
|
737
|
+
flags = regex.replace('/' + re + '/', '');
|
|
738
|
+
|
|
739
|
+
tested = new RegExp(re, flags).test(urlVal)
|
|
740
|
+
|
|
741
|
+
} else if ( /^validator\:\:/.test(regex) ) {
|
|
742
|
+
/**
|
|
743
|
+
* "requirements" : {
|
|
744
|
+
* "id" : "/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i",
|
|
745
|
+
* "email": "validator::{ isEmail: true, isString: [7] }"
|
|
746
|
+
* }
|
|
747
|
+
*
|
|
748
|
+
* e.g.: tested = new Validator('routing', _data, null, {email: {isEmail: true}} ).isEmail().valid;
|
|
749
|
+
*/
|
|
750
|
+
_data = {}; _ruleObj = {}; _rule = {}; str = '';
|
|
751
|
+
urlVar.replace( new RegExp('[^'+ key[0] +']','g'), function(){ str += arguments[0] });
|
|
752
|
+
_data[key[0]] = urlVal.replace( new RegExp(str, 'g'), '');
|
|
753
|
+
_ruleObj = JSON.parse(regex.split(/::/).splice(1)[0].replace(/([^\W+ true false])+(\w+)/g, '"$&"'));
|
|
754
|
+
_rule[key[0]] = _ruleObj;
|
|
755
|
+
_validator = new Validator('routing', _data, null, _rule );
|
|
756
|
+
|
|
757
|
+
for (let rule in _ruleObj) {
|
|
758
|
+
if (Array.isArray(_ruleObj[rule])) { // has args
|
|
759
|
+
_validator[key[0]][rule].apply(_validator[key[0]], _ruleObj[rule])
|
|
760
|
+
} else {
|
|
761
|
+
_validator[key[0]][rule](_ruleObj[rule])
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
tested = _validator.isValid();
|
|
765
|
+
} else {
|
|
766
|
+
tested = new RegExp(params.requirements[key[0]]).test(urlVal)
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (tested) {
|
|
770
|
+
values[keys[0].substr(1)] = urlVal
|
|
771
|
+
} else {
|
|
772
|
+
return false
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
strVal = '';
|
|
776
|
+
started = false;
|
|
777
|
+
i = (tplUrl.indexOf(keys[0]) + keys[0].length);
|
|
778
|
+
c -= 1;
|
|
779
|
+
|
|
780
|
+
keys.splice(0, 1)
|
|
781
|
+
} else {
|
|
782
|
+
strVal += url.charAt(c);
|
|
783
|
+
++i
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
if (c == posLen - 1) {
|
|
787
|
+
|
|
788
|
+
regex = params.requirements[keys[0]];
|
|
789
|
+
urlVal = strVal.substr(0, strVal.length);
|
|
790
|
+
|
|
791
|
+
if (/^\//.test(regex)) {
|
|
792
|
+
re = regex.match(/\/(.*)\//).pop();
|
|
793
|
+
flags = regex.replace('/' + re + '/', '');
|
|
794
|
+
|
|
795
|
+
tested = new RegExp(re, flags).test(urlVal)
|
|
796
|
+
|
|
797
|
+
} else {
|
|
798
|
+
tested = new RegExp(params.requirements[key]).test(urlVal)
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (tested) {
|
|
802
|
+
values[keys[0].substr(1)] = urlVal
|
|
803
|
+
} else {
|
|
804
|
+
return false
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (values.count() == keys.length) {
|
|
810
|
+
key = null;
|
|
811
|
+
for (key in values) {
|
|
812
|
+
request.params[key] = values[key];
|
|
813
|
+
}
|
|
814
|
+
return true
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return false
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
var replacement = function(matched){
|
|
822
|
+
return ( /\/$/.test(matched) ? replacement.variable+ '/': replacement.variable )
|
|
823
|
+
};
|
|
824
|
+
var checkRouteParams = function(route, params) {
|
|
825
|
+
var variable = null
|
|
826
|
+
, regex = null
|
|
827
|
+
, urls = null
|
|
828
|
+
, i = null
|
|
829
|
+
, len = null
|
|
830
|
+
, rawRouteUrl = route.url
|
|
831
|
+
, p = null
|
|
832
|
+
, pLen = null
|
|
833
|
+
;
|
|
834
|
+
for (p in route.param) {
|
|
835
|
+
if ( typeof(params) != 'undefined' && typeof(params[p]) == 'undefined' ) continue;
|
|
836
|
+
|
|
837
|
+
if ( /^:/.test(route.param[p]) ) {
|
|
838
|
+
variable = route.param[p].substr(1);
|
|
839
|
+
|
|
840
|
+
if ( typeof(params) != 'undefined' && typeof(params[variable]) != 'undefined' ) {
|
|
841
|
+
|
|
842
|
+
regex = new RegExp('(:'+variable+'/|:'+variable+'$)', 'g');
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
if ( typeof(route.param.path) != 'undefined' && /:/.test(route.param.path) ) {
|
|
846
|
+
route.param.path = route.param.path.replace( regex, params[variable]);
|
|
847
|
+
}
|
|
848
|
+
if (typeof (route.param.title) != 'undefined' && /:/.test(route.param.title)) {
|
|
849
|
+
route.param.title = route.param.title.replace( regex, params[variable]);
|
|
850
|
+
}
|
|
851
|
+
if (typeof (route.param.namespace) != 'undefined' && /:/.test(route.param.namespace)) {
|
|
852
|
+
route.param.namespace = route.param.namespace.replace( regex, params[variable]);
|
|
853
|
+
}
|
|
854
|
+
// file is handle like url replacement (path is like pathname)
|
|
855
|
+
if (typeof (route.param.file) != 'undefined' && /:/.test(route.param.file)) {
|
|
856
|
+
replacement.variable = params[variable];
|
|
857
|
+
route.param.file = route.param.file.replace( regex, replacement );
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
if ( /\,/.test(route.url) ) {
|
|
861
|
+
urls = route.url.split(/\,/g);
|
|
862
|
+
i = 0; len = urls.length;
|
|
863
|
+
for (; i < len; ++i) {
|
|
864
|
+
replacement.variable = params[variable];
|
|
865
|
+
urls[i] = urls[i].replace( regex, replacement );
|
|
866
|
+
}
|
|
867
|
+
route.url = urls.join(',');
|
|
868
|
+
} else {
|
|
869
|
+
replacement.variable = params[variable];
|
|
870
|
+
route.url = route.url.replace( regex, replacement );
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Selecting url in case of multiple urls & optional requirmements
|
|
877
|
+
if ( urls ) {
|
|
878
|
+
i = 0; len = urls.length;
|
|
879
|
+
var rawUrlVars = null
|
|
880
|
+
, rawUrlScore = null
|
|
881
|
+
, rawUrls = rawRouteUrl.split(/\,/g)
|
|
882
|
+
, pKey = null
|
|
883
|
+
, lastScore = 0
|
|
884
|
+
;
|
|
885
|
+
route.urlIndex = 0; // by default
|
|
886
|
+
for (; i < len; ++i) {
|
|
887
|
+
rawUrlScore = 0;
|
|
888
|
+
rawUrlVars = rawUrls[0].match(/\:[-_a-z0-9]+/ig);
|
|
889
|
+
if ( !rawUrlVars ) continue;
|
|
890
|
+
p = 0;
|
|
891
|
+
pLen = rawUrlVars.length;
|
|
892
|
+
for (; p < pLen; p++) {
|
|
893
|
+
pKey = rawUrlVars[p].substr(1);
|
|
894
|
+
if ( typeof(params[ pKey ]) != 'undefined' && params[ pKey ] ) {
|
|
895
|
+
rawUrlScore++;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
// We just rely in params count for now
|
|
899
|
+
if (rawUrlScore > lastScore) {
|
|
900
|
+
lastScore = rawUrlScore;
|
|
901
|
+
route.urlIndex = i;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
return route;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* @function getRoute
|
|
911
|
+
*
|
|
912
|
+
* @param {string} rule e.g.: [ <scheme>:// ]<name>[ @<bundle> ][ /<environment> ]
|
|
913
|
+
* @param {object} params
|
|
914
|
+
* @param {number} [urlIndex] in case you have more than one url registered for the current route, you can select the one you want to use. Default is 0.
|
|
915
|
+
*
|
|
916
|
+
* @returns {object} route
|
|
917
|
+
* */
|
|
918
|
+
self.getRoute = function(rule, params, urlIndex) {
|
|
919
|
+
|
|
920
|
+
var config = null;
|
|
921
|
+
if (isGFFCtx) {
|
|
922
|
+
config = window.gina.config;
|
|
923
|
+
} else {
|
|
924
|
+
config = getContext('gina').config;
|
|
925
|
+
if ( typeof(getContext('argvFilename')) != 'undefined' ) {
|
|
926
|
+
config.getRouting = getContext('gina').Config.instance.getRouting;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
var env = config.env || GINA_ENV // by default, takes the current bundle
|
|
931
|
+
, envTmp = null
|
|
932
|
+
//, scheme = null
|
|
933
|
+
, bundle = config.bundle // by default, takes the current bundle
|
|
934
|
+
;
|
|
935
|
+
|
|
936
|
+
if ( !/\@/.test(rule) && typeof(bundle) != 'undefined' && bundle != null) {
|
|
937
|
+
rule = rule.toLowerCase()
|
|
938
|
+
rule += '@' + bundle
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
if ( /\@/.test(rule) ) {
|
|
942
|
+
|
|
943
|
+
var arr = ( rule.replace(/(.*)\:\/\//, '') ).split(/\@/);
|
|
944
|
+
|
|
945
|
+
bundle = arr[1];
|
|
946
|
+
|
|
947
|
+
// getting env
|
|
948
|
+
if ( /\/(.*)$/.test(rule) ) {
|
|
949
|
+
envTmp = ( rule.replace(/(.*)\:\/\//, '') ).split(/\/(.*)$/)[1];
|
|
950
|
+
bundle = bundle.replace(/\/(.*)$/, '');
|
|
951
|
+
env = envTmp || env;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
// getting scheme
|
|
956
|
+
//scheme = ( /\:\/\//.test(rule) ) ? rule.split(/\:\/\//)[0] : config.bundlesConfiguration.conf[bundle][env].server.scheme;
|
|
957
|
+
|
|
958
|
+
rule = arr[0].toLowerCase() +'@'+ bundle;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
var routing = config.getRouting(bundle, env);
|
|
963
|
+
|
|
964
|
+
if ( typeof(routing[rule]) == 'undefined' ) {
|
|
965
|
+
throw new Error('[ RoutingHelper::getRouting(rule, params) ] : `' +rule + '` not found !')
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
var route = JSON.clone(routing[rule]);
|
|
969
|
+
var variable = null
|
|
970
|
+
, regex = null
|
|
971
|
+
, urls = null
|
|
972
|
+
, i = null
|
|
973
|
+
, len = null
|
|
974
|
+
, msg = null
|
|
975
|
+
;
|
|
976
|
+
route = checkRouteParams(route, params);
|
|
977
|
+
|
|
978
|
+
if ( /\,/.test(route.url) ) {
|
|
979
|
+
if ( typeof(route.urlIndex) != 'undefined' ) {
|
|
980
|
+
urlIndex = route.urlIndex; // set by checkRouteParams(route, params)
|
|
981
|
+
delete route.urlIndex;
|
|
982
|
+
}
|
|
983
|
+
urlIndex = ( typeof(urlIndex) != 'undefined' ) ? urlIndex : 0;
|
|
984
|
+
route.url = route.url.split(/,/g)[urlIndex];
|
|
985
|
+
}
|
|
986
|
+
// fix url in case of empty param value allowed by the routing rule
|
|
987
|
+
// to prevent having a folder.
|
|
988
|
+
// eg.: {..., id: '/^\\s*$/'} => {..., id: ''} => /path/to/ becoming /path/to
|
|
989
|
+
if ( /\/$/.test(route.url) && route.url != '/' )
|
|
990
|
+
route.url = route.url.substr(0, route.url.length-1);
|
|
991
|
+
|
|
992
|
+
// Completeting url with extra params e.g.: ?param1=val1¶m2=val2
|
|
993
|
+
if ( /GET/i.test(route.method) && typeof(params) != 'undefined' ) {
|
|
994
|
+
var queryParams = '?', maskedUrl = routing[rule].url;
|
|
995
|
+
//self.reservedParams;
|
|
996
|
+
for (let r in route.param) {
|
|
997
|
+
if ( self.reservedParams.indexOf(r) > -1 || new RegExp(route.param[r]).test(maskedUrl) )
|
|
998
|
+
continue;
|
|
999
|
+
if (typeof(params[r]) != 'undefined' )
|
|
1000
|
+
queryParams += r +'='+ encodeURIComponent(params[r])+ '&';
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (queryParams.length > 1) {
|
|
1004
|
+
queryParams = queryParams.substring(0, queryParams.length-1);
|
|
1005
|
+
route.url += queryParams;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// recommanded for x-bundle coms
|
|
1010
|
+
// leave `ignoreWebRoot` empty or set it to false for x-bundle coms
|
|
1011
|
+
route.toUrl = function (ignoreWebRoot) {
|
|
1012
|
+
|
|
1013
|
+
var urlProps = null;
|
|
1014
|
+
if ( /^redirect$/i.test(this.param.control) ) {
|
|
1015
|
+
urlProps = self.getUrlProps(this.bundle, (env||GINA_ENV));
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
var wroot = this.webroot || urlProps.webroot
|
|
1019
|
+
, hostname = this.hostname || urlProps.hostname
|
|
1020
|
+
, path = this.url
|
|
1021
|
+
;
|
|
1022
|
+
|
|
1023
|
+
this.url = ( typeof(ignoreWebRoot) != 'undefined' && ignoreWebRoot == true ) ? path.replace(wroot, '/') : path;
|
|
1024
|
+
|
|
1025
|
+
return hostname + this.url
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* request current url
|
|
1030
|
+
*
|
|
1031
|
+
*
|
|
1032
|
+
*
|
|
1033
|
+
* @param {boolean} [ignoreWebRoot]
|
|
1034
|
+
* @param {object} [options] - see: https://nodejs.org/api/https.html#https_new_agent_options
|
|
1035
|
+
* @param {object} [_this] - current context: only used when `promisify`is used
|
|
1036
|
+
*
|
|
1037
|
+
* @callback {callback} [cb] - see: https://nodejs.org/api/https.html#https_new_agent_options
|
|
1038
|
+
* @param {object} res
|
|
1039
|
+
*/
|
|
1040
|
+
route.request = function(ignoreWebRoot, options) {
|
|
1041
|
+
|
|
1042
|
+
var cb = null, _this = null;
|
|
1043
|
+
if ( typeof(arguments[arguments.length-1]) == 'function' ) {
|
|
1044
|
+
cb = arguments[arguments.length-1];
|
|
1045
|
+
}
|
|
1046
|
+
if ( typeof(arguments[2]) == 'object' ) {
|
|
1047
|
+
_this = arguments[2];
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
var wroot = this.webroot || _this.webroot
|
|
1051
|
+
, hostname = this.hostname || _this.hostname
|
|
1052
|
+
, url = ( typeof(ignoreWebRoot) != 'undefined' && ignoreWebRoot == true ) ? path.replace(wroot, '/') : this.url || _this.url
|
|
1053
|
+
;
|
|
1054
|
+
|
|
1055
|
+
var scheme = ( /^https/.test(hostname) ) ? 'https' : 'http';
|
|
1056
|
+
|
|
1057
|
+
if (isGFFCtx) {
|
|
1058
|
+
var target = ( typeof(options) != 'undefined' && typeof(options.target) != 'undefined' ) ? options.target : "_self";
|
|
1059
|
+
window.open(url, target)
|
|
1060
|
+
} else {
|
|
1061
|
+
if ( typeof(options.agent) == 'undefined' ) {
|
|
1062
|
+
// See.: https://nodejs.org/api/http.html#http_class_http_agent
|
|
1063
|
+
// create an agent just for this request
|
|
1064
|
+
options.agent = false;
|
|
1065
|
+
}
|
|
1066
|
+
var agent = require(''+scheme);
|
|
1067
|
+
var onAgentResponse = function(res) {
|
|
1068
|
+
|
|
1069
|
+
var data = '', err = false;
|
|
1070
|
+
|
|
1071
|
+
res.on('data', function (chunk) {
|
|
1072
|
+
data += chunk;
|
|
1073
|
+
});
|
|
1074
|
+
res.on('error', function (error) {
|
|
1075
|
+
err = 'Failed to get mail content';
|
|
1076
|
+
if (error && typeof(error.stack) != 'undefined' ) {
|
|
1077
|
+
err += error.stack;
|
|
1078
|
+
} else if ( typeof(error) == 'string' ) {
|
|
1079
|
+
err += '\n' + error;
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
res.on('end', function () {
|
|
1083
|
+
if (/^\{/.test(data) ) {
|
|
1084
|
+
try {
|
|
1085
|
+
data = JSON.parse(data);
|
|
1086
|
+
if (typeof(data.error) != 'undefined') {
|
|
1087
|
+
err = JSON.clone(data);
|
|
1088
|
+
data = null;
|
|
1089
|
+
}
|
|
1090
|
+
} catch(parseError) {
|
|
1091
|
+
err = parseError
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
if (err) {
|
|
1095
|
+
cb(err);
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
cb(false, data);
|
|
1100
|
+
return;
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
if (cb) {
|
|
1104
|
+
agent.get(url, options, onAgentResponse);
|
|
1105
|
+
} else {
|
|
1106
|
+
// just throw the request without waiting/handling response
|
|
1107
|
+
agent.get(url, options);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return;
|
|
1111
|
+
|
|
1112
|
+
} // EO route.request()
|
|
1113
|
+
|
|
1114
|
+
if ( /\:/.test(route.url) ) {
|
|
1115
|
+
var paramList = route.url
|
|
1116
|
+
.match(/(\:(.*)\/|\:(.*)$)/g)
|
|
1117
|
+
.map(function(el){ return el.replace(/\//g, ''); }).join(', ');
|
|
1118
|
+
msg = '[ RoutingHelper::getRoute(rule[, bundle, method]) ] : route [ %r ] param placeholder not defined: `' + route.url + '` !\n Check your route description to compare requirements against param variables [ '+ paramList +']';
|
|
1119
|
+
msg = msg.replace(/\%r/, rule);
|
|
1120
|
+
var err = new Error(msg);
|
|
1121
|
+
console.warn( err );
|
|
1122
|
+
// Do not throw error nor return here !!!
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
return route
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
var getFormatedRoute = function(route, url, hash) {
|
|
1129
|
+
// fix url in case of empty param value allowed by the routing rule
|
|
1130
|
+
// to prevent having a folder.
|
|
1131
|
+
// eg.: {..., id: '/^\\s*$/'} => {..., id: ''} => /path/to/ becoming /path/to
|
|
1132
|
+
if ( /\/$/.test(url) && url != '/' )
|
|
1133
|
+
url = url.substr(0, url.length-1);
|
|
1134
|
+
// adding hash if found
|
|
1135
|
+
if (hash)
|
|
1136
|
+
url += hash;
|
|
1137
|
+
|
|
1138
|
+
route.url = url;
|
|
1139
|
+
// recommanded for x-bundle coms
|
|
1140
|
+
// leave `ignoreWebRoot` empty or set it to false for x-bundle coms
|
|
1141
|
+
route.toUrl = function (ignoreWebRoot) {
|
|
1142
|
+
var wroot = this.webroot
|
|
1143
|
+
, hostname = this.hostname
|
|
1144
|
+
, path = this.url
|
|
1145
|
+
;
|
|
1146
|
+
|
|
1147
|
+
this.url = ( typeof(ignoreWebRoot) != 'undefined' && ignoreWebRoot == true ) ? path.replace(wroot, '/') : path;
|
|
1148
|
+
|
|
1149
|
+
return hostname + this.url
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
return route
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Get route by url
|
|
1157
|
+
* N.B.: this will only work with rules declared with `GET` method property
|
|
1158
|
+
*
|
|
1159
|
+
* @function getRouteByUrl
|
|
1160
|
+
*
|
|
1161
|
+
* @param {string} url e.g.: /webroot/some/url/path or http
|
|
1162
|
+
* @param {string} [bundle] targeted bundle
|
|
1163
|
+
* @param {string} [method] request method (GET|PUT|PUT|DELETE) - GET is set by default
|
|
1164
|
+
* @param {object} [request]
|
|
1165
|
+
* @param {boolean} [isOverridinMethod] // will replace request.method by the provided method - Used for redirections
|
|
1166
|
+
*
|
|
1167
|
+
* @returns {object|boolean} route - when route is found; `false` when not found
|
|
1168
|
+
* */
|
|
1169
|
+
|
|
1170
|
+
self.getRouteByUrl = function (url, bundle, method, request, isOverridinMethod) {
|
|
1171
|
+
|
|
1172
|
+
if (
|
|
1173
|
+
arguments.length == 2
|
|
1174
|
+
&& typeof(arguments[1]) != 'undefined'
|
|
1175
|
+
&& self.allowedMethods.indexOf(arguments[1].toLowerCase()) > -1
|
|
1176
|
+
) {
|
|
1177
|
+
method = arguments[1];
|
|
1178
|
+
bundle = undefined;
|
|
1179
|
+
}
|
|
1180
|
+
var webroot = null
|
|
1181
|
+
, route = null
|
|
1182
|
+
, routing = null
|
|
1183
|
+
, reverseRouting = null
|
|
1184
|
+
, hash = null // #section nav
|
|
1185
|
+
, hostname = null
|
|
1186
|
+
, host = null
|
|
1187
|
+
;
|
|
1188
|
+
|
|
1189
|
+
if ( /\#/.test(url) && url.length > 1 ) {
|
|
1190
|
+
var urlPart = url.split(/\#/);
|
|
1191
|
+
url = urlPart[0];
|
|
1192
|
+
hash = '#' + urlPart[1];
|
|
1193
|
+
|
|
1194
|
+
urlPart = null;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
// fast method
|
|
1198
|
+
if (
|
|
1199
|
+
arguments.length == 1
|
|
1200
|
+
&& typeof(arguments[0]) != 'undefined'
|
|
1201
|
+
) {
|
|
1202
|
+
if ( !/^(https|http)/i.test(url) && !/^\//.test(url)) {
|
|
1203
|
+
url = '/'+ url;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
webroot = '/' + url.split(/\//g)[1];
|
|
1207
|
+
if (isGFFCtx) {
|
|
1208
|
+
reverseRouting = gina.config.reverseRouting;
|
|
1209
|
+
routing = gina.config.routing
|
|
1210
|
+
}
|
|
1211
|
+
// get bundle
|
|
1212
|
+
if ( typeof(reverseRouting[webroot]) != 'undefined' ) {
|
|
1213
|
+
var infos = routing[ reverseRouting[webroot] ];
|
|
1214
|
+
bundle = infos.bundle;
|
|
1215
|
+
webroot = infos.webroot;
|
|
1216
|
+
host = infos.host;
|
|
1217
|
+
hostname = infos.hostname;
|
|
1218
|
+
infos = null;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
isOverridinMethod = ( typeof(arguments[arguments.length-1]) != 'boolean') ? false : arguments[arguments.length-1];
|
|
1223
|
+
|
|
1224
|
+
var matched = false
|
|
1225
|
+
, config = null
|
|
1226
|
+
, env = null
|
|
1227
|
+
, prefix = null
|
|
1228
|
+
, pathname = null
|
|
1229
|
+
, params = null
|
|
1230
|
+
, isRoute = null
|
|
1231
|
+
, foundRoute = null
|
|
1232
|
+
, routeObj = null
|
|
1233
|
+
;
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
var isMethodProvidedByDefault = ( typeof(method) != 'undefined' ) ? true : false;
|
|
1238
|
+
|
|
1239
|
+
if (isGFFCtx) {
|
|
1240
|
+
config = window.gina.config;
|
|
1241
|
+
bundle = (typeof (bundle) != 'undefined') ? bundle : config.bundle;
|
|
1242
|
+
env = config.env;
|
|
1243
|
+
routing = routing || config.getRouting(bundle);
|
|
1244
|
+
reverseRouting = reverseRouting || config.reverseRouting;
|
|
1245
|
+
isXMLRequest = ( typeof(isXMLRequest) != 'undefined' ) ? isXMLRequest : false; // TODO - retrieve the right value
|
|
1246
|
+
|
|
1247
|
+
hostname = hostname || config.hostname;
|
|
1248
|
+
webroot = webroot || config.webroot;
|
|
1249
|
+
prefix = hostname + webroot;
|
|
1250
|
+
|
|
1251
|
+
request = {
|
|
1252
|
+
routing: {},
|
|
1253
|
+
method: method,
|
|
1254
|
+
params: {},
|
|
1255
|
+
url: url
|
|
1256
|
+
};
|
|
1257
|
+
} else {
|
|
1258
|
+
|
|
1259
|
+
var gnaCtx = getContext('gina');
|
|
1260
|
+
|
|
1261
|
+
config = gnaCtx.config;
|
|
1262
|
+
bundle = (typeof (bundle) != 'undefined') ? bundle : config.bundle;
|
|
1263
|
+
env = config.env;
|
|
1264
|
+
routing = config.getRouting(bundle);
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
hostname = config.envConf[bundle][env].hostname;
|
|
1269
|
+
webroot = config.envConf[bundle][env].server.webroot;
|
|
1270
|
+
prefix = hostname + webroot;
|
|
1271
|
+
|
|
1272
|
+
if ( !request ) {
|
|
1273
|
+
request = {
|
|
1274
|
+
routing: {},
|
|
1275
|
+
isXMLRequest: false,
|
|
1276
|
+
method : ( typeof(method) != 'undefined' ) ? method.toLowerCase() : 'get',
|
|
1277
|
+
params: {},
|
|
1278
|
+
url: url
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
if (isOverridinMethod) {
|
|
1282
|
+
request.method = method;
|
|
1283
|
+
}
|
|
1284
|
+
isXMLRequest = request.isXMLRequest || false;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
pathname = url.replace( new RegExp('^('+ hostname +'|'+hostname.replace(/\:\d+/, '') +')' ), '');
|
|
1288
|
+
if ( typeof(request.routing.path) == 'undefined' )
|
|
1289
|
+
request.routing.path = unescape(pathname);
|
|
1290
|
+
method = ( typeof(method) != 'undefined' ) ? method.toLowerCase() : 'get';
|
|
1291
|
+
|
|
1292
|
+
if (isMethodProvidedByDefault) {
|
|
1293
|
+
// to handle 303 redirect like PUT -> GET
|
|
1294
|
+
request.originalMethod = request.method;
|
|
1295
|
+
|
|
1296
|
+
request.method = method;
|
|
1297
|
+
request.routing.path = unescape(pathname)
|
|
1298
|
+
}
|
|
1299
|
+
// last method check
|
|
1300
|
+
if ( !request.method)
|
|
1301
|
+
request.method = method;
|
|
1302
|
+
|
|
1303
|
+
// getting params
|
|
1304
|
+
params = {};
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
var paramsList = null;
|
|
1309
|
+
var re = new RegExp(method, 'i');
|
|
1310
|
+
var localMethod = null;
|
|
1311
|
+
// N.B.: this part of the code must remain identical to the one used in `server.js`
|
|
1312
|
+
out:
|
|
1313
|
+
for (var name in routing) {
|
|
1314
|
+
if (typeof (routing[name]['param']) == 'undefined')
|
|
1315
|
+
break;
|
|
1316
|
+
|
|
1317
|
+
// bundle filter
|
|
1318
|
+
if (routing[name].bundle != bundle) continue;
|
|
1319
|
+
|
|
1320
|
+
// method filter
|
|
1321
|
+
localMethod = routing[name].method;
|
|
1322
|
+
if ( /\,/.test( localMethod ) && re.test(localMethod) ) {
|
|
1323
|
+
localMethod = request.method
|
|
1324
|
+
}
|
|
1325
|
+
if (typeof (routing[name].method) != 'undefined' && !re.test(localMethod)) continue;
|
|
1326
|
+
|
|
1327
|
+
//Preparing params to relay to the core/router.
|
|
1328
|
+
params = {
|
|
1329
|
+
method : localMethod,
|
|
1330
|
+
requirements : routing[name].requirements,
|
|
1331
|
+
namespace : routing[name].namespace || undefined,
|
|
1332
|
+
url : unescape(pathname), /// avoid %20
|
|
1333
|
+
rule : routing[name].originalRule || name,
|
|
1334
|
+
param : routing[name].param,
|
|
1335
|
+
//middleware: routing[name].middleware,
|
|
1336
|
+
middleware : JSON.clone(routing[name].middleware),
|
|
1337
|
+
bundle : routing[name].bundle,
|
|
1338
|
+
isXMLRequest : isXMLRequest
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
// normal case
|
|
1342
|
+
//Parsing for the right url.
|
|
1343
|
+
try {
|
|
1344
|
+
|
|
1345
|
+
isRoute = self.compareUrls(params, routing[name].url, request);
|
|
1346
|
+
|
|
1347
|
+
if (isRoute.past) {
|
|
1348
|
+
|
|
1349
|
+
route = JSON.clone(routing[name]);
|
|
1350
|
+
route.name = name;
|
|
1351
|
+
|
|
1352
|
+
matched = true;
|
|
1353
|
+
isRoute = {};
|
|
1354
|
+
|
|
1355
|
+
break;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
} catch (err) {
|
|
1359
|
+
throw new Error('Route [ ' + name + ' ] needs your attention.\n' + err.stack);
|
|
1360
|
+
}
|
|
1361
|
+
} //EO for break out
|
|
1362
|
+
|
|
1363
|
+
if (!matched) {
|
|
1364
|
+
if (isGFFCtx) {
|
|
1365
|
+
var urlHasChanged = false;
|
|
1366
|
+
if (
|
|
1367
|
+
url == '#'
|
|
1368
|
+
&& /GET/i.test(method)
|
|
1369
|
+
&& isMethodProvidedByDefault
|
|
1370
|
+
|| /^404\:/.test(url)
|
|
1371
|
+
) {
|
|
1372
|
+
url = location.pathname;
|
|
1373
|
+
urlHasChanged = true;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
if ( typeof(self.notFound) == 'undefined' ) {
|
|
1377
|
+
self.notFound = {}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
var notFound = null, msg = '[ RoutingHelper::getRouteByUrl(rule[, bundle, method]) ] : route [ %r ] is called but not found inside your view: `' + url + '` !';
|
|
1381
|
+
if ( gina.hasPopinHandler && gina.popinIsBinded ) {
|
|
1382
|
+
notFound = gina.popin.getActivePopin().target.innerHTML.match(/404\:\[\w+\][a-z 0-9-_@]+/);
|
|
1383
|
+
} else {
|
|
1384
|
+
notFound = document.body.innerHTML.match(/404\:\[\w+\][a-z 0-9-_@]+/);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
notFound = (notFound && notFound.length > 0) ? notFound[0] : null;
|
|
1388
|
+
|
|
1389
|
+
if ( notFound && isMethodProvidedByDefault && urlHasChanged ) {
|
|
1390
|
+
|
|
1391
|
+
var m = notFound.match(/\[\w+\]/)[0];
|
|
1392
|
+
|
|
1393
|
+
notFound = notFound.replace('404:'+m, m.replace(/\[|\]/g, '')+'::' );
|
|
1394
|
+
|
|
1395
|
+
msg = msg.replace(/\%r/, notFound.replace(/404\:\s+/, ''));
|
|
1396
|
+
|
|
1397
|
+
if (typeof(self.notFound[notFound]) == 'undefined') {
|
|
1398
|
+
self.notFound[notFound] = {
|
|
1399
|
+
count: 1,
|
|
1400
|
+
message: msg
|
|
1401
|
+
};
|
|
1402
|
+
} else if ( isMethodProvidedByDefault && typeof(self.notFound[notFound]) != 'undefined' ) {
|
|
1403
|
+
++self.notFound[notFound].count;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
return false
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
notFound = null;
|
|
1410
|
+
|
|
1411
|
+
var altRule = gina.config.reverseRouting[url] || null;
|
|
1412
|
+
if (
|
|
1413
|
+
!notFound
|
|
1414
|
+
&& altRule
|
|
1415
|
+
&& typeof(altRule) != 'undefined'
|
|
1416
|
+
&& altRule.split(/\@(.+)$/)[1] == bundle
|
|
1417
|
+
) {
|
|
1418
|
+
|
|
1419
|
+
notFound = altRule;
|
|
1420
|
+
if ( typeof(self.notFound[notFound]) == 'undefined' ) {
|
|
1421
|
+
|
|
1422
|
+
msg = msg.replace(/\%r/, method.toUpperCase() +'::'+ altRule);
|
|
1423
|
+
|
|
1424
|
+
self.notFound[notFound] = {
|
|
1425
|
+
count: 1,
|
|
1426
|
+
message: msg
|
|
1427
|
+
};
|
|
1428
|
+
//console.warn(msg);
|
|
1429
|
+
} else if ( isMethodProvidedByDefault && typeof(self.notFound[notFound]) != 'undefined' ) {
|
|
1430
|
+
++self.notFound[notFound].count;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
return false
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// forms
|
|
1437
|
+
var altRoute = self.compareUrls(params, url, request) || null;
|
|
1438
|
+
if(altRoute.past && isMethodProvidedByDefault) {
|
|
1439
|
+
notFound = method.toUpperCase() +'::'+ altRoute.request.routing.rule;
|
|
1440
|
+
if ( typeof(self.notFound[notFound]) == 'undefined' ) {
|
|
1441
|
+
msg = msg.replace(/\%r/, notFound);
|
|
1442
|
+
//console.warn(msg);
|
|
1443
|
+
} else {
|
|
1444
|
+
++self.notFound[notFound].count;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
return false
|
|
1448
|
+
}
|
|
1449
|
+
return false
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
console.warn( new Error('[ RoutingHelper::getRouteByUrl(rule[, bundle, method, request]) ] : route not found for url: `' + url + '` !').stack );
|
|
1454
|
+
return false;
|
|
1455
|
+
} else {
|
|
1456
|
+
// fix url in case of empty param value allowed by the routing rule
|
|
1457
|
+
// to prevent having a folder.
|
|
1458
|
+
// eg.: {..., id: '/^\\s*$/'} => {..., id: ''} => /path/to/ becoming /path/to
|
|
1459
|
+
if ( /\/$/.test(url) && url != '/' )
|
|
1460
|
+
url = url.substr(0, url.length-1);
|
|
1461
|
+
// adding hash if found
|
|
1462
|
+
if (hash)
|
|
1463
|
+
url += hash;
|
|
1464
|
+
|
|
1465
|
+
route.url = url;
|
|
1466
|
+
// recommanded for x-bundle coms
|
|
1467
|
+
// leave `ignoreWebRoot` empty or set it to false for x-bundle coms
|
|
1468
|
+
route.toUrl = function (ignoreWebRoot) {
|
|
1469
|
+
var wroot = this.webroot
|
|
1470
|
+
, hostname = this.hostname
|
|
1471
|
+
, path = this.url
|
|
1472
|
+
;
|
|
1473
|
+
|
|
1474
|
+
this.url = ( typeof(ignoreWebRoot) != 'undefined' && ignoreWebRoot == true ) ? path.replace(wroot, '/') : path;
|
|
1475
|
+
|
|
1476
|
+
return hostname + this.url
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
return route
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
return self
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
if ((typeof (module) !== 'undefined') && module.exports) {
|
|
1487
|
+
// Publish as node.js module
|
|
1488
|
+
module.exports = Routing()
|
|
1489
|
+
} else if (typeof (define) === 'function' && define.amd) {
|
|
1490
|
+
// Publish as AMD module
|
|
1491
|
+
define('utils/routing', ['require', 'utils/form-validator', 'utils/merge'], function() { return Routing() })
|
|
1492
|
+
}
|