gina 0.0.9-p91c → 0.1.1-alpha.3
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.3/AUTHORS +7 -0
- package/{core/utils/lib/inherits → framework/v0.1.1-alpha.3}/LICENSE +1 -1
- package/framework/v0.1.1-alpha.3/VERSION +1 -0
- package/{core/locales/dist/language/en.json → framework/v0.1.1-alpha.3/core/asset/html/nolayout.html} +0 -0
- package/{core/locales/dist/language/fr.json → framework/v0.1.1-alpha.3/core/asset/html/static.html} +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/android-chrome-192x192.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/android-chrome-512x512.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/apple-touch-icon.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/favicon-16x16.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/favicon-32x32.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.js +20904 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.js.map +56 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.css +1 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.css.map +1 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.js +736 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.js.map +56 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.onload.min.js +5 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.onload.min.js.map +8 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/readme.md +192 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/uuid.json +23 -0
- package/framework/v0.1.1-alpha.3/core/config.js +2308 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/index.js +757 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/connector.js +20 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/connector.v2.js +429 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/connector.v3.js +432 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/n1ql.js +14 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/session-store.js +21 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/session-store.v2.js +258 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/session-store.v3.js +341 -0
- package/{core → framework/v0.1.1-alpha.3/core}/controller/controller.framework.js +3 -2
- package/framework/v0.1.1-alpha.3/core/controller/controller.js +3990 -0
- package/{core → framework/v0.1.1-alpha.3/core}/controller/index.js +5 -5
- package/framework/v0.1.1-alpha.3/core/deps/busboy/.travis.yml +17 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/LICENSE +19 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/README.md +225 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/deps/encoding/encoding-indexes.js +73 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/deps/encoding/encoding.js +2391 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/main.js +89 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/types/multipart.js +328 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/types/urlencoded.js +214 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/utils.js +191 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/package.json +69 -0
- package/framework/v0.1.1-alpha.3/core/deps/swig-client/swig-2.0.0.min.js +5 -0
- package/{core → framework/v0.1.1-alpha.3/core}/dev/index.js +5 -5
- package/{core → framework/v0.1.1-alpha.3/core}/dev/lib/class.js +1 -1
- package/{core → framework/v0.1.1-alpha.3/core}/dev/lib/factory.js +1 -1
- package/{core → framework/v0.1.1-alpha.3/core}/dev/lib/tools.js +0 -0
- package/framework/v0.1.1-alpha.3/core/gna.js +1070 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/README.md +41 -2
- package/{core → framework/v0.1.1-alpha.3/core}/locales/currency.json +0 -0
- package/{core/plugins/README.md → framework/v0.1.1-alpha.3/core/locales/dist/language/en.json} +0 -0
- package/{core/plugins/lib/intl/README.md → framework/v0.1.1-alpha.3/core/locales/dist/language/fr.json} +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/dist/region/en.json +0 -0
- package/framework/v0.1.1-alpha.3/core/locales/dist/region/fr.json +9492 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/index.js +5 -4
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/make.js +15 -12
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/resources/currency.csv +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/resources/region.csv +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/resources/region.mapping.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/mime.types +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/model/entity.js +156 -196
- package/{core → framework/v0.1.1-alpha.3/core}/model/index.js +67 -48
- package/{core → framework/v0.1.1-alpha.3/core}/model/template/entityFactory.js +2 -2
- package/{core → framework/v0.1.1-alpha.3/core}/model/template/index.js +8 -10
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.3/core/plugins}/README.md +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/index.js +3 -3
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.3/core/plugins/lib/file}/README.md +0 -0
- package/{core/plugins/lib/intl → framework/v0.1.1-alpha.3/core/plugins/lib/file}/build.json +0 -0
- package/framework/v0.1.1-alpha.3/core/plugins/lib/file/package.json +25 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.3/core/plugins/lib/intl}/README.md +0 -0
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.3/core/plugins/lib/intl}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/intl/package.json +3 -3
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/intl/src/main.js +17 -1
- package/{core/utils/lib/routing → framework/v0.1.1-alpha.3/core/plugins/lib/storage}/README.md +0 -0
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.3/core/plugins/lib/storage}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/storage/package.json +2 -2
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/storage/src/main.js +91 -85
- package/{core/utils/lib/url → framework/v0.1.1-alpha.3/core/plugins/lib/validator}/README.md +0 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.3/core/plugins/lib/validator}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/validator/package.json +3 -3
- package/framework/v0.1.1-alpha.3/core/plugins/lib/validator/src/form-validator.js +1762 -0
- package/framework/v0.1.1-alpha.3/core/plugins/lib/validator/src/main.js +6917 -0
- package/framework/v0.1.1-alpha.3/core/router.js +664 -0
- package/framework/v0.1.1-alpha.3/core/server.express.js +213 -0
- package/framework/v0.1.1-alpha.3/core/server.isaac.js +386 -0
- package/framework/v0.1.1-alpha.3/core/server.js +3010 -0
- package/{core → framework/v0.1.1-alpha.3/core}/status.codes +8 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/app.json +6 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/routing.json +11 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/settings.json +9 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/settings.server.json +30 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/templates.json +42 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/controllers/controller.content.js +39 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/controllers/controller.js +30 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/controllers/setup.js +111 -0
- package/{core/template/samples → framework/v0.1.1-alpha.3/core/template/boilerplate}/bundle/index.js +0 -0
- package/{core/template/samples/bundle → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_namespace}/controllers/controller.js +9 -7
- package/{core/template/views → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public}/css/default.css +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public}/css/vendor/readme.md +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public}/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public/js/vendor/readme.md +1 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public/readme.md +1 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_templates/handlers/main.js +24 -0
- package/{core/template/views/html/default.html → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_templates/html/homepage.html} +0 -0
- package/{core/template/views/html/layout.html → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_templates/html/layout/main.html} +2 -2
- package/{core → framework/v0.1.1-alpha.3/core}/template/command/gina.bat.tpl +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/command/gina.tpl +1 -1
- package/framework/v0.1.1-alpha.3/core/template/conf/env.json +76 -0
- package/{core/template/conf/project.json → framework/v0.1.1-alpha.3/core/template/conf/manifest.json} +1 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/conf/package.json +2 -2
- package/framework/v0.1.1-alpha.3/core/template/conf/settings.json +92 -0
- package/framework/v0.1.1-alpha.3/core/template/conf/statics.json +10 -0
- package/framework/v0.1.1-alpha.3/core/template/conf/templates.json +37 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/client/json/401.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/client/json/403.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/client/json/404.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/server/html/50x.html +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/server/json/500.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/server/json/503.json +0 -0
- package/{core/utils/lib/routing/build.json → framework/v0.1.1-alpha.3/core/template/extensions/logger/config.json} +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/console.js +3 -3
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/context.js +240 -49
- package/framework/v0.1.1-alpha.3/helpers/dateFormat.js +528 -0
- package/framework/v0.1.1-alpha.3/helpers/index.js +79 -0
- package/framework/v0.1.1-alpha.3/helpers/json/README.md +0 -0
- package/framework/v0.1.1-alpha.3/helpers/json/package.json +20 -0
- package/framework/v0.1.1-alpha.3/helpers/json/src/main.js +97 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/path.js +342 -140
- package/framework/v0.1.1-alpha.3/helpers/plugins/README.md +4 -0
- package/framework/v0.1.1-alpha.3/helpers/plugins/package.json +20 -0
- package/framework/v0.1.1-alpha.3/helpers/plugins/src/api-error.js +160 -0
- package/framework/v0.1.1-alpha.3/helpers/plugins/src/main.js +32 -0
- package/framework/v0.1.1-alpha.3/helpers/prototypes.js +218 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/task.js +49 -29
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/text.js +7 -7
- package/framework/v0.1.1-alpha.3/lib/archiver/README.md +0 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/build.json +0 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/src/dep/jszip.min.js +15 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/src/main.js +499 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/aliases.json +13 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/add.js +507 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/arguments.json +4 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/copy.js +15 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/cp.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/help.txt +67 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/list.js +129 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/remove.js +229 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/rename.js +4 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/restart.js +235 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/start.js +394 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/status.js +3 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/stop.js +232 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/add.js +436 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/get.js +62 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/help.txt +33 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/link-dev.js +80 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/list.js +111 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/remove.js +150 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/set.js +57 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/unset.js +44 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/use.js +79 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/dot.js +70 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/get.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/help.js +39 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/help.txt +31 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/init.js +514 -0
- package/{core/utils/lib/cmd → framework/v0.1.1-alpha.3/lib/cmd/framework}/msg.json +3 -3
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/open.js +50 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/restart.js +124 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/set.js +161 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/start.js +96 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/status.js +72 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/stop.js +159 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/tail.js +183 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/update.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/version.js +44 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/gina-dev.1.md +66 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/gina-framework.1.md +100 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/gina.1.md +79 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/helper.js +1147 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/index.js +170 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/msg.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/help.txt +31 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/inc/scan.js +108 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/list.js +176 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/set.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/add.js +528 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/arguments.json +9 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/build.js +115 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/help.txt +76 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/import.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/list.js +55 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/move.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/remove.js +144 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/rename.js +162 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/restart.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/start.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/status.js +3 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/stop.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/help.js +27 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/help.txt +57 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/list.js +239 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/set.js +631 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/help.txt +33 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/link-local.js +80 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/list.js +116 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/remove.js +150 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/set.js +57 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/unset.js +44 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/use.js +79 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/view/add.js +311 -0
- package/framework/v0.1.1-alpha.3/lib/collection/README.md +5 -0
- package/framework/v0.1.1-alpha.3/lib/collection/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/collection/package.json +2 -2
- package/framework/v0.1.1-alpha.3/lib/collection/src/main.js +1459 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/config.js +49 -34
- package/framework/v0.1.1-alpha.3/lib/cron/README.md +7 -0
- package/framework/v0.1.1-alpha.3/lib/cron/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/cron/src/main.js +176 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/generator/index.js +8 -4
- package/framework/v0.1.1-alpha.3/lib/index.js +116 -0
- package/framework/v0.1.1-alpha.3/lib/inherits/LICENSE +19 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/inheriting_eventemitter.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/protected_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/simple_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/super_attribute_overridden_by_child_on_init.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/package.json +2 -2
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/src/main.js +18 -19
- package/framework/v0.1.1-alpha.3/lib/logger/README.md +7 -0
- package/framework/v0.1.1-alpha.3/lib/logger/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/default/index.js +55 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/file/index.js +251 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/file/lib/logrotator/README.md +100 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/file/lib/logrotator/index.js +274 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/mq/index.js +52 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/mq/listener.js +302 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/mq/speaker.js +118 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/helper.js +131 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/main.js +739 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/math/index.js +58 -35
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/README.md +5 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/example/merge.js +1 -1
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/example/merge_2_literal objects.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/example/merge_and_preserve_first.js +2 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/package.json +2 -2
- package/framework/v0.1.1-alpha.3/lib/merge/src/main.js +531 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/model.js +42 -19
- package/framework/v0.1.1-alpha.3/lib/proc.js +518 -0
- package/framework/v0.1.1-alpha.3/lib/routing/README.md +0 -0
- package/framework/v0.1.1-alpha.3/lib/routing/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/routing/package.json +2 -2
- package/framework/v0.1.1-alpha.3/lib/routing/src/main.js +1492 -0
- package/framework/v0.1.1-alpha.3/lib/session-store.js +33 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/shell.js +43 -30
- package/framework/v0.1.1-alpha.3/lib/swig-filters/README.md +0 -0
- package/framework/v0.1.1-alpha.3/lib/swig-filters/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/swig-filters/src/main.js +322 -0
- package/framework/v0.1.1-alpha.3/lib/url/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/index.js +2 -1
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/mocks.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/routing.json +9 -9
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/test.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/validator.js +7 -7
- package/framework/v0.1.1-alpha.3/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 -13732
- 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 -789
- 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
|
@@ -1,1860 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file is part of the gina package.
|
|
3
|
-
* Copyright (c) 2016 Rhinostone <gina@rhinostone.com>
|
|
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
|
-
//Imports.
|
|
10
|
-
var fs = require('fs');
|
|
11
|
-
var EventEmitter = require('events').EventEmitter;
|
|
12
|
-
var http = require('http');
|
|
13
|
-
var https = require('https');
|
|
14
|
-
var utils = require('./../utils') || require.cache[require.resolve('./../utils')];
|
|
15
|
-
var merge = utils.merge;
|
|
16
|
-
var inherits = utils.inherits;
|
|
17
|
-
var console = utils.logger;
|
|
18
|
-
var Collection = utils.Collection;
|
|
19
|
-
var swig = require('swig');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @class SuperController
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @package Gina
|
|
27
|
-
* @namespace
|
|
28
|
-
* @author Rhinostone <gina@rhinostone.com>
|
|
29
|
-
*
|
|
30
|
-
* @api Public
|
|
31
|
-
*/
|
|
32
|
-
function SuperController(options) {
|
|
33
|
-
this.name = 'SuperController';
|
|
34
|
-
|
|
35
|
-
//private
|
|
36
|
-
var self = this;
|
|
37
|
-
var local = {
|
|
38
|
-
req : null,
|
|
39
|
-
res : null,
|
|
40
|
-
next : null,
|
|
41
|
-
options : options || null,
|
|
42
|
-
query : {},
|
|
43
|
-
_data : {}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
var ports = {
|
|
47
|
-
'http': 80,
|
|
48
|
-
'https': 443
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* SuperController Constructor
|
|
54
|
-
* @constructor
|
|
55
|
-
* */
|
|
56
|
-
var init = function() {
|
|
57
|
-
|
|
58
|
-
if ( typeof(SuperController.initialized) != 'undefined' ) {
|
|
59
|
-
return getInstance()
|
|
60
|
-
} else {
|
|
61
|
-
SuperController.initialized = true;
|
|
62
|
-
SuperController.instance = self;
|
|
63
|
-
if (local.options) {
|
|
64
|
-
SuperController.instance._options = local.options
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var getInstance = function() {
|
|
70
|
-
local.options = SuperController.instance._options = options;
|
|
71
|
-
return SuperController.instance
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
var hasViews = function() {
|
|
75
|
-
return ( typeof(local.options.views) != 'undefined' ) ? true : false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Check if env is running cacheless
|
|
80
|
-
* */
|
|
81
|
-
this.isCacheless = function() {
|
|
82
|
-
return local.options.cacheless
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.setOptions = function(req, res, next, options) {
|
|
86
|
-
local.options = SuperController.instance._options = options;
|
|
87
|
-
|
|
88
|
-
// N.B.: Avoid setting `page` properties as much as possible from the routing.json
|
|
89
|
-
// It will be easier for the framework if set from the controller.
|
|
90
|
-
//
|
|
91
|
-
// Here is a sample if you choose to set `page.title` from the rule
|
|
92
|
-
// ------rouging rule sample -----
|
|
93
|
-
// {
|
|
94
|
-
// "default": {
|
|
95
|
-
// "url": ["", "/"],
|
|
96
|
-
// "param": {
|
|
97
|
-
// "action": "home",
|
|
98
|
-
// "title": "My Title"
|
|
99
|
-
// }
|
|
100
|
-
// }
|
|
101
|
-
//
|
|
102
|
-
// ------controller action sample -----
|
|
103
|
-
// Here is a sample if you decide to set `page.title` from your controller
|
|
104
|
-
//
|
|
105
|
-
// this.home = function(req, res, next) {
|
|
106
|
-
// var data = { page: { title: "My Title"}};
|
|
107
|
-
// self.render(data)
|
|
108
|
-
// }
|
|
109
|
-
if ( typeof(options.conf.content.routing[options.rule].param) != 'undefined' ) {
|
|
110
|
-
var str = 'page.', p = options.conf.content.routing[options.rule].param;
|
|
111
|
-
for (var key in p) {
|
|
112
|
-
if (p.hasOwnProperty(key)) {
|
|
113
|
-
str += key + '.';
|
|
114
|
-
var obj = p[key], value = '';
|
|
115
|
-
for (var prop in obj) {
|
|
116
|
-
if (obj.hasOwnProperty(prop)) {
|
|
117
|
-
value += obj[prop]
|
|
118
|
-
} else {
|
|
119
|
-
|
|
120
|
-
if ( /^:/.test(value) ) {
|
|
121
|
-
set(str.substr(0, str.length-1), req.params[value.substr(1)])
|
|
122
|
-
} else {
|
|
123
|
-
set(str.substr(0, str.length-1), value)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
str = 'page.'
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
local.req = req;
|
|
135
|
-
local.res = res;
|
|
136
|
-
local.next = next;
|
|
137
|
-
|
|
138
|
-
getParams(req);
|
|
139
|
-
if ( typeof(local.options.views) != 'undefined' && typeof(local.options.action) != 'undefined' ) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var action = local.options.action
|
|
143
|
-
, rule = local.options.rule
|
|
144
|
-
, ext = 'html'
|
|
145
|
-
, namespace = local.options.namespace || '';
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if ( typeof(local.options.views.default) != 'undefined' ) {
|
|
149
|
-
ext = local.options.views.default.ext || ext;
|
|
150
|
-
}
|
|
151
|
-
if( !/\./.test(ext) ) {
|
|
152
|
-
ext = '.' + ext;
|
|
153
|
-
local.options.views.default.ext = ext
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// new declaration && overrides
|
|
157
|
-
var version = {
|
|
158
|
-
"number" : getContext('gina').version,
|
|
159
|
-
"platform" : process.platform,
|
|
160
|
-
"arch" : process.arch,
|
|
161
|
-
"nodejs" : process.versions.node,
|
|
162
|
-
"middleware" : getContext('gina').middleware
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
set('page.environment.gina', version.number);
|
|
166
|
-
set('page.environment.nodejs', version.nodejs +' '+ version.platform +' '+ version.arch);
|
|
167
|
-
set('page.environment.middleware', version.middleware);
|
|
168
|
-
set('page.environment.env', options.conf.env);
|
|
169
|
-
set('page.environment.webroot', options.conf.server.webroot);
|
|
170
|
-
set('page.environment.bundle', options.conf.bundle);
|
|
171
|
-
|
|
172
|
-
set('page.ext', ext);
|
|
173
|
-
set('page.content', action);
|
|
174
|
-
set('page.namespace', namespace);
|
|
175
|
-
set('page.title', rule.replace(new RegExp('@'+options.conf.bundle), ''));
|
|
176
|
-
set('page.forms', options.conf.content.forms);
|
|
177
|
-
|
|
178
|
-
var acceptLanguage = 'en-US'; // by default
|
|
179
|
-
if ( typeof(req.headers['accept-language']) != 'undefined' ) {
|
|
180
|
-
acceptLanguage = req.headers['accept-language']
|
|
181
|
-
} else if ( typeof(local.options.conf.server.response.header['accept-language']) != 'undefined' ) {
|
|
182
|
-
acceptLanguage = local.options.conf.server.response.header['accept-language']
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// set user locale
|
|
186
|
-
var userCulture = acceptLanguage.split(',')[0];
|
|
187
|
-
var userCultureCode = userCulture.split(/\-/);
|
|
188
|
-
var userLangCode = userCultureCode[0];
|
|
189
|
-
var userCountryCode = userCultureCode[1];
|
|
190
|
-
|
|
191
|
-
var locales = new Collection( getContext('gina').locales );
|
|
192
|
-
var userLocales = null;
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
userLocales = locales.findOne({ lang: userLangCode }).content
|
|
196
|
-
} catch (err) {
|
|
197
|
-
console.warn('language code `'+ userLangCode +'` not handled to setup locales: replacing by `en`');
|
|
198
|
-
userLocales = locales.findOne({ lang: 'en' }).content // by default
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// user locales list
|
|
202
|
-
local.options.conf.locales = userLocales;
|
|
203
|
-
|
|
204
|
-
// user locale
|
|
205
|
-
options.conf.locale = new Collection(userLocales).findOne({ short: userCountryCode });
|
|
206
|
-
|
|
207
|
-
set('page.locale', options.conf.locale);
|
|
208
|
-
set('page.lang', userCulture);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if ( hasViews() ) {
|
|
212
|
-
|
|
213
|
-
if ( typeof(local.options.file) == 'undefined') {
|
|
214
|
-
local.options.file = 'index'
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if ( typeof(local.options.isWithoutLayout) == 'undefined' ) {
|
|
218
|
-
local.options.isWithoutLayout = false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
var rule = local.options.rule
|
|
222
|
-
, namespace = local.options.namespace || rule;
|
|
223
|
-
|
|
224
|
-
set('file', local.options.file);
|
|
225
|
-
set('page.title', local.options.file);
|
|
226
|
-
set('page.namespace', namespace);
|
|
227
|
-
|
|
228
|
-
//TODO - detect when to use swig
|
|
229
|
-
var dir = self.views || local.options.views.default.views;
|
|
230
|
-
var swigOptions = {
|
|
231
|
-
autoescape: ( typeof(local.options.autoescape) != 'undefined') ? local.options.autoescape: false,
|
|
232
|
-
loader: swig.loaders.fs(dir),
|
|
233
|
-
cache: (local.options.cacheless) ? false : 'memory'
|
|
234
|
-
};
|
|
235
|
-
swig.setDefaults(swigOptions);
|
|
236
|
-
self.engine = swig;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
this.renderWithoutLayout = function (data, displayToolbar) {
|
|
243
|
-
local.options.isWithoutLayout = true;
|
|
244
|
-
local.options.debugMode = true; // only active for dev env
|
|
245
|
-
self.render(data)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Render HTML templates : Swig is the default template engine
|
|
250
|
-
*
|
|
251
|
-
* Extend default filters
|
|
252
|
-
* - length
|
|
253
|
-
*
|
|
254
|
-
* Avilable filters:
|
|
255
|
-
* - getWebroot()
|
|
256
|
-
* - getUrl()
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* @param {object} _data
|
|
260
|
-
*
|
|
261
|
-
* @return {void}
|
|
262
|
-
* */
|
|
263
|
-
this.render = function(_data) {
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
var data = getData(), path = '', plugin = null;
|
|
267
|
-
if (!_data) {
|
|
268
|
-
_data = { page: {}}
|
|
269
|
-
} else if ( _data && !_data['page']) {
|
|
270
|
-
data['page'] = {
|
|
271
|
-
data: _data
|
|
272
|
-
}
|
|
273
|
-
} else {
|
|
274
|
-
data = merge(_data, data)
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
data.view = local.options.rule.replace('\@'+ local.options.bundle, '');
|
|
279
|
-
setResources(local.options.views, data.view);
|
|
280
|
-
|
|
281
|
-
var file = data.file;
|
|
282
|
-
|
|
283
|
-
// pre-compiling variables
|
|
284
|
-
data = merge(data, getData()); // needed !!
|
|
285
|
-
|
|
286
|
-
if (typeof(data.page.data) == 'undefined' ) {
|
|
287
|
-
data.page.data = {}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if ( typeof(data.page.data.status) != 'undefined' && !/^2/.test(data.page.data.status) && typeof(data.page.data.error) != 'undefined' ) {
|
|
291
|
-
self.throwError(data.page.data.status, data.page.data.error)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// making path thru [namespace &] file
|
|
295
|
-
if ( typeof(local.options.namespace) != 'undefined' ) {
|
|
296
|
-
file = ''+ file.replace(local.options.namespace+'-', '');
|
|
297
|
-
// means that rule name === namespace -> pointing to root namespace dir
|
|
298
|
-
if (!file || file === local.options.namespace) {
|
|
299
|
-
file = 'index'
|
|
300
|
-
}
|
|
301
|
-
path = _(local.options.views[data.view].html +'/'+ local.options.namespace + '/' + file)
|
|
302
|
-
} else {
|
|
303
|
-
if (local.options.path) {
|
|
304
|
-
path = _(local.options.path);
|
|
305
|
-
var re = new RegExp( data.page.ext+'$');
|
|
306
|
-
if ( data.page.ext && re.test(data.page.file) ) {
|
|
307
|
-
data.page.path = path.replace('/'+ data.page.file, '');
|
|
308
|
-
|
|
309
|
-
path = path.replace(re, '');
|
|
310
|
-
data.page.file = data.page.file.replace(re, '');
|
|
311
|
-
|
|
312
|
-
} else {
|
|
313
|
-
data.page.path = path.replace('/'+ data.page.file, '');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
} else {
|
|
317
|
-
path = _(local.options.views[data.view].html +'/'+ file)
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (data.page.ext) {
|
|
322
|
-
path += data.page.ext
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
var dic = {}, msg = '';
|
|
326
|
-
for (var d in data.page) {
|
|
327
|
-
dic['page.'+d] = data.page[d]
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// please, do not put any slashes when including...
|
|
332
|
-
// ex.:
|
|
333
|
-
// /html/inc/_partial.html (BAD)
|
|
334
|
-
// html/inc/_partial.html (GOOD)
|
|
335
|
-
// ./html/namespace/page.html (GOOD)
|
|
336
|
-
fs.readFile(path, function (err, content) {
|
|
337
|
-
if (err) {
|
|
338
|
-
msg = 'could not open "'+ path +'"' +
|
|
339
|
-
'\n1) The requested file does not exists in your views/html (check your template directory). Can you find: '+path +
|
|
340
|
-
'\n2) Check the following rule in your `'+local.options.conf.bundlePath+'/config/routing.json` and look around `param` to make sure that nothing is wrong with your declaration: '+
|
|
341
|
-
'\n' + options.rule +':'+ JSON.stringify(options.conf.content.routing[options.rule], null, 4) +
|
|
342
|
-
'\n3) At this point, if you still have problems trying to run this portion of code, you can contact us telling us how to reproduce the bug.' +
|
|
343
|
-
'\n\r[ stack trace ] '+ err.stack;
|
|
344
|
-
|
|
345
|
-
console.error(err);
|
|
346
|
-
self.throwError(local.res, 500, new Error(msg));
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
try {
|
|
350
|
-
// Extends default `length` filter
|
|
351
|
-
swig.setFilter('length', function (input, obj) {
|
|
352
|
-
|
|
353
|
-
if ( typeof(input.count) != 'undefined' ) {
|
|
354
|
-
return input.count()
|
|
355
|
-
} else {
|
|
356
|
-
return input.length
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
// Allows you to get a bundle web root
|
|
362
|
-
swig.setFilter('getWebroot', function (input, obj) {
|
|
363
|
-
var prop = options.envObj.getConf(obj, options.conf.env),
|
|
364
|
-
url = prop.protocol + '://'+ prop.host +':'+ prop.port[prop.protocol];
|
|
365
|
-
if ( typeof(prop.server['webroot']) != 'undefined') {
|
|
366
|
-
url += prop.server['webroot']
|
|
367
|
-
}
|
|
368
|
-
return url
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* getUrl filter
|
|
373
|
-
*
|
|
374
|
-
* Usage:
|
|
375
|
-
* <a href="{{ '/homepage' | getUrl() }}">Homepage</a>
|
|
376
|
-
* <a href="{{ 'users-add' | getUrl({ id: user.id }) }}">Add User</a>
|
|
377
|
-
* <a href="{{ 'users-edit' | getUrl({ id: user.id }) }}">Edit user</a>
|
|
378
|
-
* <a href="{{ 'users-list' | getUrl(null, 'http://domain.com') }}">Display all users</a>
|
|
379
|
-
* <a href="{{ '/dashboard' | getUrl(null, 'admin') }}">Go to admin bundle's dashboard page</a>
|
|
380
|
-
*
|
|
381
|
-
* // can also be used with standalone mode: will add webroot if current bundle is not master
|
|
382
|
-
* <script src="{{ '/js/vendor/modernizr-2.8.3.min.js' | getUrl() }}"></script>
|
|
383
|
-
* compiled as => <script src="/my-bundle/js/vendor/modernizr-2.8.3.min.js"></script>
|
|
384
|
-
*
|
|
385
|
-
* @param {string} route
|
|
386
|
-
* @param {object} params - can't be left blank if base is required -> null if not defined
|
|
387
|
-
* @param {string} [base] - can be a CDN, the http://domain.com or a bundle name
|
|
388
|
-
*
|
|
389
|
-
* @return {string} relativeUrl|absoluteUrl - /sample/url.html or http://domain.com/sample/url.html
|
|
390
|
-
* */
|
|
391
|
-
var config = null
|
|
392
|
-
, hostname = null
|
|
393
|
-
, wroot = null
|
|
394
|
-
, isStandalone = null
|
|
395
|
-
, isMaster = null
|
|
396
|
-
, routing = null
|
|
397
|
-
, isWithoutLayout = null
|
|
398
|
-
, rule = ''
|
|
399
|
-
, url = NaN
|
|
400
|
-
, urlStr = null
|
|
401
|
-
;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
swig.setFilter('getUrl', function (route, params, base) {
|
|
405
|
-
// if no route, returns current route
|
|
406
|
-
if ( typeof(route) == 'undefined') {
|
|
407
|
-
var route = local.options.rule
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// setting default config
|
|
411
|
-
config = local.options.conf;
|
|
412
|
-
hostname = '';
|
|
413
|
-
wroot = config.server.webroot;
|
|
414
|
-
|
|
415
|
-
isStandalone = (config.bundles.length > 1) ? true : false;
|
|
416
|
-
isMaster = (config.bundles[0] === config.bundle) ? true : false;
|
|
417
|
-
routing = config.content.routing;
|
|
418
|
-
isWithoutLayout = (local.options.isWithoutLayout) ? true : false;
|
|
419
|
-
|
|
420
|
-
if ( typeof(base) != 'undefined' ) {
|
|
421
|
-
|
|
422
|
-
// if base is not an URL, must be a bundle
|
|
423
|
-
if ( !/^http\:/.test(base) ) {
|
|
424
|
-
var mainConf = getContext('gina').Config.instance;
|
|
425
|
-
// is real bundle ?
|
|
426
|
-
if ( mainConf.allBundles.indexOf(base) > -1 ) {
|
|
427
|
-
// config override
|
|
428
|
-
config = mainConf.Env.getConf(base, mainConf.env);
|
|
429
|
-
|
|
430
|
-
// retrieve hostname, webroot & routing
|
|
431
|
-
hostname = config.hostname;
|
|
432
|
-
routing = config.content.routing;
|
|
433
|
-
wroot = config.server.webroot;
|
|
434
|
-
|
|
435
|
-
config.bundle = base;
|
|
436
|
-
isStandalone = (mainConf.bundles.length > 1) ? true : false;
|
|
437
|
-
isMaster = (mainConf.bundles[0] === config.bundle) ? true : false;
|
|
438
|
-
|
|
439
|
-
} else {
|
|
440
|
-
self.throwError(local.res, 500, new Error('bundle `'+ base +'` not found: Swig.getUrl() filter encountered a problem while trying to compile base `'+base+'` and route `'+route+'`').stack)
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// is path ?
|
|
446
|
-
if (/\//.test(route)) {
|
|
447
|
-
|
|
448
|
-
if (route.substr(0,1) == '/')
|
|
449
|
-
route = route.substr(1);
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
if (wroot.length == 1)
|
|
453
|
-
wroot = '';
|
|
454
|
-
|
|
455
|
-
return hostname + wroot +'/'+ route;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// rules are now unique per bundle : rule@bundle
|
|
459
|
-
rule = route + '@' + config.bundle;
|
|
460
|
-
|
|
461
|
-
if ( typeof(routing[rule]) != 'undefined' ) { //found
|
|
462
|
-
url = routing[rule].url;
|
|
463
|
-
if ( typeof(routing[rule].requirements) != 'undefined' ) {
|
|
464
|
-
|
|
465
|
-
for (var p in routing[rule].requirements) {
|
|
466
|
-
if ( Array.isArray(url) ) {
|
|
467
|
-
for (var i= 0, len = url.length; i< len; ++i) {
|
|
468
|
-
if ( params && /:/.test(url[i]) ) {
|
|
469
|
-
urlStr = url[i].replace(new RegExp(':'+p+'(\\W|$)', 'g'), params[p]+'$1');
|
|
470
|
-
break
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
if (urlStr != null) {
|
|
475
|
-
url = urlStr
|
|
476
|
-
} else { // just take the first one by default
|
|
477
|
-
url = url[0]
|
|
478
|
-
}
|
|
479
|
-
} else {
|
|
480
|
-
try {
|
|
481
|
-
url = url.replace(new RegExp(':'+p+'(\\W|$)', 'g'), params[p]+'$1')
|
|
482
|
-
} catch (err) {
|
|
483
|
-
self.throwError(local.res, 500, 'template compilation exception encoutered: [ '+path+' ]\nsounds like you are having troubles with the following call `{{ "'+route+'" | getUrl() }}` where `'+p+'` parameter is expected according to your `routing.json`' +'\n'+(err.stack||err.message));
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
} else {
|
|
489
|
-
if ( Array.isArray(url) ) {
|
|
490
|
-
url = url[0] || url[1] // just taking the default one: using the first element unless it is empty.
|
|
491
|
-
if (!url) {
|
|
492
|
-
self.throwError(local.res, 500, new Error('please check your `routing.json` at the defined rule `'+rule+'` : `url` attribute cannot be empty').stack)
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
if ( /^\//.test(url) )
|
|
498
|
-
url = hostname + url;
|
|
499
|
-
else
|
|
500
|
-
url = hostname +'/'+ url;
|
|
501
|
-
|
|
502
|
-
} else {
|
|
503
|
-
if ( typeof(routing['404']) != 'undefined' && typeof(routing['404'].url) != 'undefined' ) {
|
|
504
|
-
if (routing["404"].url.substr(0,1) == '/')
|
|
505
|
-
routing["404"].url = routing["404"].url.substr(1);
|
|
506
|
-
|
|
507
|
-
url = hostname + wroot +'/'+ routing["404"].url
|
|
508
|
-
} else {
|
|
509
|
-
url = hostname + wroot +'/404.html'
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
return url
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
} catch (err) {
|
|
517
|
-
// [ martin ]
|
|
518
|
-
// i sent an email to [ paul@paularmstrongdesigns.com ] on 2014/08 to see if there is
|
|
519
|
-
// a way of retrieving swig compilation stack traces
|
|
520
|
-
//var stack = __stack.splice(1).toString().split(',').join('\n');
|
|
521
|
-
self.throwError(local.res, 500, 'template compilation exception encoutered: [ '+path+' ]\n'+(err.stack||err.message));
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
dic['page.content'] = content;
|
|
525
|
-
|
|
526
|
-
var layoutPath = (local.options.isWithoutLayout) ? local.options.views[data.view].noLayout : local.options.views[data.view].layout;
|
|
527
|
-
|
|
528
|
-
fs.readFile(layoutPath, function(err, layout) {
|
|
529
|
-
if (err) {
|
|
530
|
-
self.throwError(local.res, 500, err.stack);
|
|
531
|
-
} else {
|
|
532
|
-
layout = layout.toString();
|
|
533
|
-
// adding plugins
|
|
534
|
-
if ( hasViews() && local.options.conf.env == 'dev' && (!local.options.isWithoutLayout || local.options.isWithoutLayout && local.options.debugMode) ) {
|
|
535
|
-
|
|
536
|
-
layout = ''
|
|
537
|
-
+ '{%- set ginaDataInspector = JSON.parse(JSON.stringify(page)) -%}'
|
|
538
|
-
+ '{%- set ginaDataInspector.scripts = "ignored-by-toolbar" -%}'
|
|
539
|
-
+ '{%- set ginaDataInspector.stylesheets = "ignored-by-toolbar" -%}'
|
|
540
|
-
+ layout.replace('{{ page.scripts }}', '')
|
|
541
|
-
;
|
|
542
|
-
|
|
543
|
-
plugin = '\t'
|
|
544
|
-
+ '{# Gina Toolbar #}'
|
|
545
|
-
+ '{%- set userDataInspector = page -%}'
|
|
546
|
-
+ '{%- set userDataInspector.scripts = "ignored-by-toolbar" -%}'
|
|
547
|
-
+ '{%- set userDataInspector.stylesheets = "ignored-by-toolbar" -%}'
|
|
548
|
-
+ '{%- include "'+getPath('gina').core+'/asset/js/plugin/src/gina/toolbar/toolbar.html" with { gina: ginaDataInspector, user: userDataInspector} -%}'
|
|
549
|
-
+ '{# END Gina Toolbar #}'
|
|
550
|
-
|
|
551
|
-
+ '\n<script type="text/javascript">'
|
|
552
|
-
+ ' \n<!--'
|
|
553
|
-
+ '\n' + local.options.views.default.pluginLoader.toString()
|
|
554
|
-
+ '//-->'
|
|
555
|
-
+ '\n</script>'
|
|
556
|
-
|
|
557
|
-
+ '\n<script type="text/javascript" src="{{ \'/js/vendor/gina/gina.min.js\' | getUrl() }}"></script>'
|
|
558
|
-
|
|
559
|
-
+ '{{ page.scripts }}'
|
|
560
|
-
;
|
|
561
|
-
|
|
562
|
-
if (local.options.isWithoutLayout && local.options.debugMode) {
|
|
563
|
-
var XHRData = '\t<input type="hidden" id="gina-without-layout-xhr-data" value="'+ encodeURIComponent(JSON.stringify(data.page.data)) +'">\n\r';
|
|
564
|
-
layout = XHRData + layout;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
layout = layout.replace(/<\/body>/i, plugin + '\n\t</body>');
|
|
568
|
-
|
|
569
|
-
} else if ( hasViews() && local.options.conf.env == 'dev' && self.isXMLRequest() ) {
|
|
570
|
-
// means that we don't want GFF context or we already have it loaded
|
|
571
|
-
var XHRData = '\n<input type="hidden" id="gina-without-layout-xhr-data" value="'+ encodeURIComponent(JSON.stringify(data.page.data)) +'">';
|
|
572
|
-
|
|
573
|
-
layout += XHRData;
|
|
574
|
-
|
|
575
|
-
} else { // production env
|
|
576
|
-
|
|
577
|
-
plugin = '\t'
|
|
578
|
-
+ '\n<script type="text/javascript">'
|
|
579
|
-
+ ' \n<!--'
|
|
580
|
-
+ '\n' + local.options.views.default.pluginLoader.toString()
|
|
581
|
-
+ '//-->'
|
|
582
|
-
+ '\n</script>'
|
|
583
|
-
|
|
584
|
-
+ '\n<script type="text/javascript" src="{{ \'/js/vendor/gina/gina.min.js\' | getUrl() }}"></script>'
|
|
585
|
-
;
|
|
586
|
-
|
|
587
|
-
if ( !/page\.scripts/.test(layout) ) {
|
|
588
|
-
layout = layout.replace(/<\/body>/i, plugin + '\t{{ page.scripts }}\n\t</body>');
|
|
589
|
-
} else {
|
|
590
|
-
layout = layout.replace(/{{ page.scripts }}/i, plugin + '\t{{ page.scripts }}');
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
layout = whisper(dic, layout, /\{{ ([a-zA-Z.]+) \}}/g );
|
|
596
|
-
|
|
597
|
-
try {
|
|
598
|
-
|
|
599
|
-
layout = swig.compile(layout)(data);
|
|
600
|
-
// special case for template without layout in debug mode - dev only
|
|
601
|
-
if ( hasViews() && local.options.isWithoutLayout && local.options.debugMode ) {
|
|
602
|
-
layout = layout.replace(/<\/body>/i, plugin + '\n\t</body>');
|
|
603
|
-
layout = whisper(dic, layout, /\{{ ([a-zA-Z.]+) \}}/g );
|
|
604
|
-
layout = swig.compile(layout)(data);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
} catch (err) {
|
|
608
|
-
var filename = local.options.views[data.view].html;
|
|
609
|
-
filename += ( typeof(data.page.namespace) != 'undefined' && data.page.namespace != '' && new RegExp('^' + data.page.namespace +'-').test(data.file) ) ? '/' + data.page.namespace + data.file.split(data.page.namespace +'-').join('/') + ( (data.page.ext != '') ? data.page.ext: '' ) : '/' + data.file+ ( (data.page.ext != '') ? data.page.ext: '' );
|
|
610
|
-
self.throwError(local.res, 500, 'Compilation error encountered while trying to process template `'+ filename + '`\n'+(err.stack||err.message))
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
if ( !local.res.headersSent ) {
|
|
614
|
-
local.res.statusCode = ( typeof(local.options.conf.server.coreConfiguration.statusCodes[data.page.data.status]) != 'undefined' ) ? data.page.data.status : 200; // by default
|
|
615
|
-
//catching errors
|
|
616
|
-
if (
|
|
617
|
-
typeof(data.page.data.errno) != 'undefined' && /^2/.test(data.page.data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.page.data.status]) != 'undefined'
|
|
618
|
-
|| typeof(data.page.data.status) != 'undefined' && !/^2/.test(data.page.data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.page.data.status]) != 'undefined'
|
|
619
|
-
) {
|
|
620
|
-
|
|
621
|
-
try {
|
|
622
|
-
//local.res.statusCode = data.page.data.status;
|
|
623
|
-
local.res.statusMessage = local.options.conf.server.coreConfiguration.statusCodes[data.page.data.status];
|
|
624
|
-
} catch (err){
|
|
625
|
-
local.res.statusCode = 500;
|
|
626
|
-
local.res.statusMessage = err.stack||err.message||local.options.conf.server.coreConfiguration.statusCodes[local.res.statusCode];
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
local.res.setHeader("Content-Type", local.options.conf.server.coreConfiguration.mime['html']);
|
|
631
|
-
|
|
632
|
-
console.info(local.req.method +' ['+local.res.statusCode +'] '+ local.req.url);
|
|
633
|
-
|
|
634
|
-
local.res.end(layout);
|
|
635
|
-
local.res.headersSent = true
|
|
636
|
-
} else {
|
|
637
|
-
local.next()
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
})
|
|
641
|
-
})
|
|
642
|
-
} catch (err) {
|
|
643
|
-
self.throwError(local.res, 500, err.stack||err.message)
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
this.isXMLRequest = function() {
|
|
648
|
-
return local.options.isXMLRequest;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
this.isWithCredentials = function() {
|
|
652
|
-
return ( /true/.test(local.options.withCredentials) ) ? true : false;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Render JSON
|
|
657
|
-
*
|
|
658
|
-
* @param {object|string} jsonObj
|
|
659
|
-
* @param {object} [req]
|
|
660
|
-
* @param {object} [res]
|
|
661
|
-
*
|
|
662
|
-
* @callback {function} [next]
|
|
663
|
-
*
|
|
664
|
-
* */
|
|
665
|
-
this.renderJSON = function(jsonObj) {
|
|
666
|
-
|
|
667
|
-
var request = local.req;
|
|
668
|
-
var response = local.res;
|
|
669
|
-
var next = local.next;
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
if (!jsonObj) {
|
|
673
|
-
var jsonObj = {}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
try {
|
|
677
|
-
// just in case
|
|
678
|
-
if ( typeof(jsonObj) == 'string') {
|
|
679
|
-
jsonObj = JSON.parse(jsonObj)
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
if( typeof(local.options) != "undefined" && typeof(local.options.charset) != "undefined" ){
|
|
683
|
-
response.setHeader("charset", local.options.charset);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
//catching errors
|
|
688
|
-
if (
|
|
689
|
-
typeof(jsonObj.errno) != 'undefined' && response.statusCode == 200
|
|
690
|
-
|| typeof(jsonObj.status) != 'undefined' && jsonObj.status != 200 && typeof(local.options.conf.server.coreConfiguration.statusCodes[jsonObj.status]) != 'undefined'
|
|
691
|
-
) {
|
|
692
|
-
|
|
693
|
-
try {
|
|
694
|
-
response.statusCode = jsonObj.status;
|
|
695
|
-
response.statusMessage = local.options.conf.server.coreConfiguration.statusCodes[jsonObj.status];
|
|
696
|
-
} catch (err){
|
|
697
|
-
response.statusCode = 500;
|
|
698
|
-
response.statusMessage = err.stack;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
// Internet Explorer override
|
|
704
|
-
if ( /msie/i.test(request.headers['user-agent']) ) {
|
|
705
|
-
response.setHeader("Content-Type", "text/plain")
|
|
706
|
-
} else {
|
|
707
|
-
response.setHeader("Content-Type", local.options.conf.server.coreConfiguration.mime['json'])
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
if ( !response.headersSent ) {
|
|
711
|
-
console.info(request.method +' ['+ response.statusCode +'] '+ request.url);
|
|
712
|
-
|
|
713
|
-
if ( local.options.isXMLRequest && self.isWithCredentials() ) {
|
|
714
|
-
|
|
715
|
-
var data = JSON.stringify(jsonObj);
|
|
716
|
-
var len = 0;
|
|
717
|
-
// content length must be the right size !
|
|
718
|
-
if ( typeof(data) === 'string') {
|
|
719
|
-
len = Buffer.byteLength(data, 'utf8')
|
|
720
|
-
} else {
|
|
721
|
-
len = data.length
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
response.setHeader("Content-Length", len);
|
|
725
|
-
|
|
726
|
-
response.write(data);
|
|
727
|
-
response.headersSent = true;
|
|
728
|
-
|
|
729
|
-
// required to close connection
|
|
730
|
-
setTimeout(function () {
|
|
731
|
-
response.end()
|
|
732
|
-
}, 200);
|
|
733
|
-
|
|
734
|
-
return // force completion
|
|
735
|
-
|
|
736
|
-
} else { // normal case
|
|
737
|
-
response.end(JSON.stringify(jsonObj));
|
|
738
|
-
response.headersSent = true
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
} catch (err) {
|
|
742
|
-
self.throwError(response, 500, err.stack||err.message)
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
this.renderTEXT = function(content) {
|
|
749
|
-
if ( typeof(content) != "string" ) {
|
|
750
|
-
var content = content.toString();
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
if(typeof(options) != "undefined" && typeof(options.charset) !="undefined") {
|
|
754
|
-
local.res.setHeader("charset", options.charset);
|
|
755
|
-
}
|
|
756
|
-
if ( !local.res.get('Content-Type') ) {
|
|
757
|
-
local.res.setHeader("Content-Type", "text/plain");
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
if ( !local.res.headersSent ) {
|
|
761
|
-
console.info(local.req.method +' ['+local.res.statusCode +'] '+ local.req.url);
|
|
762
|
-
local.res.end(content);
|
|
763
|
-
local.res.headersSent = true
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
var parseDataObject = function (o, obj) {
|
|
768
|
-
|
|
769
|
-
for (var i in o) {
|
|
770
|
-
if (o[i] !== null && typeof(o[i]) == 'object') {
|
|
771
|
-
parseDataObject(o[i], obj);
|
|
772
|
-
} else if (o[i] == '_content_'){
|
|
773
|
-
o[i] = obj
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
return o
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* Set data
|
|
782
|
-
*
|
|
783
|
-
* @param {string} nave - variable name to set
|
|
784
|
-
* @param {string|object} value - value to set
|
|
785
|
-
*
|
|
786
|
-
* @return {void}
|
|
787
|
-
* */
|
|
788
|
-
// var set = function(variable, value) {
|
|
789
|
-
// if ( typeof(local._data[variable]) == 'undefined' )
|
|
790
|
-
// local._data[variable] = value
|
|
791
|
-
// }
|
|
792
|
-
|
|
793
|
-
var set = function(name, value) {
|
|
794
|
-
|
|
795
|
-
if ( typeof(name) == 'string' && /\./.test(name) ) {
|
|
796
|
-
var keys = name.split(/\./g)
|
|
797
|
-
, newObj = {}
|
|
798
|
-
, str = '{'
|
|
799
|
-
, _count = 0;
|
|
800
|
-
|
|
801
|
-
for (var k = 0, len = keys.length; k<len; ++k) {
|
|
802
|
-
str += "\""+ keys.splice(0,1)[0] + "\":{";
|
|
803
|
-
|
|
804
|
-
++_count;
|
|
805
|
-
if (k == len-1) {
|
|
806
|
-
str = str.substr(0, str.length-1);
|
|
807
|
-
str += "\"_content_\"";
|
|
808
|
-
for (var c = 0; c<_count; ++c) {
|
|
809
|
-
str += "}"
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
newObj = parseDataObject(JSON.parse(str), value);
|
|
815
|
-
local._data = merge(local._data, newObj);
|
|
816
|
-
|
|
817
|
-
} else if ( typeof(local._data[name]) == 'undefined' ) {
|
|
818
|
-
local._data[name] = value
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* Get data
|
|
824
|
-
*
|
|
825
|
-
* @param {String} variable Data name to set
|
|
826
|
-
* @return {Object | String} data Data object or String
|
|
827
|
-
* */
|
|
828
|
-
var get = function(variable) {
|
|
829
|
-
return local._data[variable]
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
* Set resources
|
|
834
|
-
*
|
|
835
|
-
* @param {object} viewConf - template configuration
|
|
836
|
-
* @param {string} localRessouces - rule name
|
|
837
|
-
* */
|
|
838
|
-
var setResources = function(viewConf, localRessource) {
|
|
839
|
-
if (!viewConf) {
|
|
840
|
-
self.throwError(500, 'No views configuration found. Did you try to add views before using Controller::render(...) ? Try to run: ./gina.sh -av '+options.conf.bundle)
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
var res = '',
|
|
844
|
-
tmpRes = {},
|
|
845
|
-
css = {
|
|
846
|
-
media : "screen",
|
|
847
|
-
rel : "stylesheet",
|
|
848
|
-
type : "text/css",
|
|
849
|
-
content : []
|
|
850
|
-
},
|
|
851
|
-
cssStr = ' ',
|
|
852
|
-
js = {
|
|
853
|
-
type : "text/javascript",
|
|
854
|
-
content : []
|
|
855
|
-
},
|
|
856
|
-
jsStr = ' ',
|
|
857
|
-
exclude = null;
|
|
858
|
-
|
|
859
|
-
//intercept errors in case of malformed config
|
|
860
|
-
if ( typeof(viewConf) != "object" ) {
|
|
861
|
-
cssStr = viewConf;
|
|
862
|
-
jsStr = viewConf
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
//cascading merging
|
|
867
|
-
if (localRessource !== 'default') {
|
|
868
|
-
if ( typeof(viewConf[localRessource]) != 'undefined') {
|
|
869
|
-
|
|
870
|
-
var noneDefaultJs = (viewConf[localRessource]['javascripts']) ? JSON.parse(JSON.stringify(viewConf[localRessource]['javascripts'])) : [] ;
|
|
871
|
-
var noneDefaultCss = (viewConf[localRessource]['stylesheets']) ? JSON.parse(JSON.stringify(viewConf[localRessource]['stylesheets'])) : [] ;
|
|
872
|
-
|
|
873
|
-
viewConf[localRessource] = merge(viewConf.default, viewConf[localRessource]);
|
|
874
|
-
|
|
875
|
-
if ( viewConf[localRessource]["javascriptsExclude"] ) {
|
|
876
|
-
|
|
877
|
-
if ( Array.isArray(viewConf[localRessource]["javascriptsExclude"]) && !/(all|\*)/.test(viewConf[localRessource]["javascriptsExclude"][0]) || typeof(viewConf[localRessource]["javascriptsExclude"]) == 'string' && !/(all|\*)/.test(viewConf[localRessource]["javascriptsExclude"]) ) {
|
|
878
|
-
|
|
879
|
-
for (var i = 0, len = viewConf.default['javascripts'].length; i<len; ++i) {
|
|
880
|
-
if ( viewConf.default['javascripts'] && viewConf[localRessource]['javascripts'].indexOf(viewConf.default['javascripts'][i]) ) {
|
|
881
|
-
viewConf[localRessource]['javascripts'].splice(viewConf[localRessource]['javascripts'].indexOf(viewConf.default['javascripts'][i]), 1)
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
} else {// else means that we exclude all default
|
|
885
|
-
viewConf[localRessource]['javascripts'] = noneDefaultJs;
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
if ( viewConf[localRessource]["stylesheetsExclude"] ) {
|
|
890
|
-
|
|
891
|
-
if ( Array.isArray(viewConf[localRessource]["stylesheetsExclude"]) && !/(all|\*)/.test(viewConf[localRessource]["stylesheetsExclude"][0]) || typeof(viewConf[localRessource]["stylesheetsExclude"]) == 'string' && !/(all|\*)/.test(viewConf[localRessource]["stylesheetsExclude"]) ) {
|
|
892
|
-
|
|
893
|
-
for (var i = 0, len = viewConf.default['stylesheets'].length; i<len; ++i) {
|
|
894
|
-
if ( viewConf.default['stylesheets'] && viewConf[localRessource]['javascripts'].indexOf(viewConf.default['javascripts'][i]) ) {
|
|
895
|
-
viewConf[localRessource]['stylesheets'].splice(viewConf[localRessource]['javascripts'].indexOf(viewConf.default['javascripts'][i]), 1)
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
} else {// else means that we exclude all default
|
|
899
|
-
viewConf[localRessource]['stylesheets'] = noneDefaultJs;
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
} else {
|
|
905
|
-
viewConf[localRessource] = viewConf.default
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
//Get css
|
|
910
|
-
if( viewConf[localRessource]["stylesheets"] ) {
|
|
911
|
-
tmpRes = getNodeRes('css', cssStr, viewConf[localRessource]["stylesheets"], css);
|
|
912
|
-
|
|
913
|
-
cssStr = tmpRes.cssStr;
|
|
914
|
-
css = tmpRes.css;
|
|
915
|
-
tmpRes = null
|
|
916
|
-
}
|
|
917
|
-
//Get js
|
|
918
|
-
if( viewConf[localRessource]["javascripts"] ) {
|
|
919
|
-
tmpRes = getNodeRes('js', jsStr, viewConf[localRessource]["javascripts"], js);
|
|
920
|
-
|
|
921
|
-
jsStr = tmpRes.jsStr;
|
|
922
|
-
js = tmpRes.js;
|
|
923
|
-
tmpRes = null
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
set('page.stylesheets', cssStr);
|
|
927
|
-
set('page.scripts', jsStr)
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
/**
|
|
931
|
-
* Get node resources
|
|
932
|
-
*
|
|
933
|
-
* @param {string} type
|
|
934
|
-
* @param {string} resStr
|
|
935
|
-
* @param {array} resArr
|
|
936
|
-
* @param {object} resObj
|
|
937
|
-
*
|
|
938
|
-
* @return {object} content
|
|
939
|
-
*
|
|
940
|
-
* @private
|
|
941
|
-
* */
|
|
942
|
-
var getNodeRes = function(type, resStr, resArr, resObj) {
|
|
943
|
-
switch(type){
|
|
944
|
-
case 'css':
|
|
945
|
-
var css = resObj;
|
|
946
|
-
for (var res in resArr) {
|
|
947
|
-
//means that you will find options.
|
|
948
|
-
if (typeof(resArr[res]) == "object") {
|
|
949
|
-
//console.info('found object ', resArr[res]);
|
|
950
|
-
css.media = (resArr[res].options.media) ? resArr[res].options.media : css.media;
|
|
951
|
-
css.rel = (resArr[res].options.rel) ? resArr[res].options.rel : css.rel;
|
|
952
|
-
css.type = (resArr[res].options.type) ? resArr[res].options.type : css.type;
|
|
953
|
-
if (!css.content[resArr[res]._]) {
|
|
954
|
-
css.content[resArr[res]._] = '<link href="'+ resArr[res]._ +'" media="'+ css.media +'" rel="'+ css.rel +'" type="'+ css.type +'">';
|
|
955
|
-
resStr += '\n\t' + css.content[resArr[res]._]
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
} else {
|
|
959
|
-
css.content[resArr[res]] = '<link href="'+ resArr[res] +'" media="screen" rel="'+ css.rel +'" type="'+ css.type +'">';
|
|
960
|
-
resStr += '\n\t' + css.content[resArr[res]]
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
965
|
-
return { css : css, cssStr : resStr }
|
|
966
|
-
break;
|
|
967
|
-
|
|
968
|
-
case 'js':
|
|
969
|
-
var js = resObj;
|
|
970
|
-
for (var res in resArr) {
|
|
971
|
-
//means that you will find options
|
|
972
|
-
if ( typeof(resArr[res]) == "object" ) {
|
|
973
|
-
js.type = (resArr[res].options.type) ? resArr[res].options.type : js.type;
|
|
974
|
-
if (!js.content[resArr[res]._]) {
|
|
975
|
-
js.content[resArr[res]._] = '<script type="'+ js.type +'" src="'+ resArr[res]._ +'"></script>';
|
|
976
|
-
resStr += '\n' + js.content[resArr[res]._];
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
} else {
|
|
980
|
-
js.content[resArr[res]] = '<script type="'+ js.type +'" src="'+ resArr[res] +'"></script>';
|
|
981
|
-
resStr += '\n' + js.content[resArr[res]]
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
}
|
|
986
|
-
return { js : js, jsStr : resStr }
|
|
987
|
-
break;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* TODO - SuperController.setMeta()
|
|
993
|
-
* */
|
|
994
|
-
// this.setMeta = function(metaName, metacontent) {
|
|
995
|
-
//
|
|
996
|
-
// }
|
|
997
|
-
|
|
998
|
-
var getData = function() {
|
|
999
|
-
return refToObj( local._data )
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
var isValidURL = function(url){
|
|
1003
|
-
var re = /(http|ftp|https|sftp):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
|
|
1004
|
-
return (re.test(url)) ? true : false
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
/**
|
|
1008
|
-
* redirect
|
|
1009
|
-
*
|
|
1010
|
-
* TODO - improve redirect based on `utils.routing`
|
|
1011
|
-
* e.g.: self.redirect('project-get', { companyId: companyId, clientId: clientId, id: projectId }, true)
|
|
1012
|
-
*
|
|
1013
|
-
* You have to ways of using this method
|
|
1014
|
-
*
|
|
1015
|
-
* 1) Through routing.json
|
|
1016
|
-
* ---------------------
|
|
1017
|
-
* Allows you to redirect to an internal [ route ], an internal [ path ], or an external [ url ]
|
|
1018
|
-
*
|
|
1019
|
-
* For this to work you have to set in your routing.json a new route using "param":
|
|
1020
|
-
* { "action": "redirect", "route": "one-valid-route" }
|
|
1021
|
-
* OR
|
|
1022
|
-
* { "action": "redirect", "url": "http://www.somedomain.com/page.html" }
|
|
1023
|
-
*
|
|
1024
|
-
* OR
|
|
1025
|
-
* { "action": "redirect", "path": "/", "ignoreWebRoot": true }
|
|
1026
|
-
*
|
|
1027
|
-
* if you are free to use the redirection [ code ] of your choice, we've set it to 301 by default
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
* 2) By calling this.redirect(rule, [ignoreWebRoot]):
|
|
1031
|
-
* ------------------------------------------------
|
|
1032
|
-
* where `this` is :
|
|
1033
|
-
* - a Controller instance
|
|
1034
|
-
* - a Middleware instance
|
|
1035
|
-
*
|
|
1036
|
-
* Where `rule` is either a string defining
|
|
1037
|
-
* - the rule/route name => home
|
|
1038
|
-
* - an URI => /home
|
|
1039
|
-
* - a URL => http://www.google.com/
|
|
1040
|
-
*
|
|
1041
|
-
* And Where `ignoreWebRoot` is an optional parameter used to ignore web root settings (Standalone mode or user set web root)
|
|
1042
|
-
* `ignoreWebRoot` behaves the like set to `false` by default
|
|
1043
|
-
*
|
|
1044
|
-
* N.B.: Gina will tell browsers not to cache redirections if you are using `dev` environement
|
|
1045
|
-
*
|
|
1046
|
-
* @param {object|string} req|rule - Request Object or Rule/Route name
|
|
1047
|
-
* @param {object|boolean} res|ignoreWebRoot - Response Object or Ignore WebRoot & start from domain root: /
|
|
1048
|
-
* @param {object} [params] TODO
|
|
1049
|
-
*
|
|
1050
|
-
* @callback [ next ]
|
|
1051
|
-
* */
|
|
1052
|
-
this.redirect = function(req, res, next) {
|
|
1053
|
-
var conf = self.getConfig();
|
|
1054
|
-
var wroot = conf.server.webroot;
|
|
1055
|
-
var routing = conf.content.routing;
|
|
1056
|
-
var route = '', rte = '';
|
|
1057
|
-
var ignoreWebRoot = null;
|
|
1058
|
-
|
|
1059
|
-
if ( typeof(req) === 'string' ) {
|
|
1060
|
-
|
|
1061
|
-
if ( typeof(res) == 'undefined') {
|
|
1062
|
-
// nothing to do
|
|
1063
|
-
} else if (typeof(res) === 'string' || typeof(res) === 'number' || typeof(res) === 'boolean') {
|
|
1064
|
-
if ( /true|1/.test(res) ) {
|
|
1065
|
-
ignoreWebRoot = true
|
|
1066
|
-
} else if ( /false|0/.test(res) ) {
|
|
1067
|
-
ignoreWebRoot = false
|
|
1068
|
-
} else {
|
|
1069
|
-
res = local.res;
|
|
1070
|
-
var stack = __stack.splice(1).toString().split(',').join('\n');
|
|
1071
|
-
self.throwError(res, 500, 'Internal Server Error\n@param `ignoreWebRoot` must be a boolean\n' + stack);
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
if ( req.substr(0,1) === '/') { // is relative (not checking if the URI is defined in the routing.json)
|
|
1076
|
-
if (wroot.substr(wroot.length-1,1) == '/') {
|
|
1077
|
-
wroot = wroot.substr(wroot.length-1,1).replace('/', '')
|
|
1078
|
-
}
|
|
1079
|
-
rte = ( ignoreWebRoot != null && ignoreWebRoot) ? req : wroot + req;
|
|
1080
|
-
req = local.req;
|
|
1081
|
-
res = local.res;
|
|
1082
|
-
next = local.next;
|
|
1083
|
-
var isRelative = true;
|
|
1084
|
-
req.routing.param.path = rte
|
|
1085
|
-
} else if ( isValidURL(req) ) { // might be an URL
|
|
1086
|
-
rte = req;
|
|
1087
|
-
req = local.req;
|
|
1088
|
-
res = local.res;
|
|
1089
|
-
next = local.next;
|
|
1090
|
-
req.routing.param.url = rte
|
|
1091
|
-
} else { // is by default a route name
|
|
1092
|
-
rte = route = ( new RegExp('^/'+conf.bundle+'-$').test(req) ) ? req : wroot.match(/[^/]/g).join('') +'-'+ req;
|
|
1093
|
-
req = local.req;
|
|
1094
|
-
res = local.res;
|
|
1095
|
-
next = local.next;
|
|
1096
|
-
req.routing.param.route = routing[rte]
|
|
1097
|
-
}
|
|
1098
|
-
} else {
|
|
1099
|
-
route = req.routing.param.route;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
var path = req.routing.param.path || '';
|
|
1103
|
-
var url = req.routing.param.url;
|
|
1104
|
-
var code = req.routing.param.code || 301;
|
|
1105
|
-
|
|
1106
|
-
var keepParams = req.routing.param['keep-params'] || false;
|
|
1107
|
-
|
|
1108
|
-
var condition = true; //set by default for url @ path redirect
|
|
1109
|
-
|
|
1110
|
-
if (route) { // will go with route first
|
|
1111
|
-
condition = ( typeof(routing[route]) != 'undefined') ? true : false;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
if ( !self.forward404Unless(condition, req, res) ) { // forward to 404 if bad route
|
|
1115
|
-
|
|
1116
|
-
if (wroot.substr(wroot.length-1,1) == '/') {
|
|
1117
|
-
wroot = wroot.substr(wroot.length-1,1).replace('/', '')
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
if (route) { // will go with route first
|
|
1122
|
-
path = (ignoreWebRoot) ? routing[route].url.replace(wroot, '') : routing[route].url;
|
|
1123
|
-
if (path instanceof Array) {
|
|
1124
|
-
path = path[0] //if it is an array, we just take the first one
|
|
1125
|
-
}
|
|
1126
|
-
} else if (url && !path) {
|
|
1127
|
-
path = ( (/\:\/\//).test(url) ) ? url : req.protocol + '://' + url;
|
|
1128
|
-
} else if(path && typeof(isRelative) != 'undefined') {
|
|
1129
|
-
// nothing to do
|
|
1130
|
-
} else {
|
|
1131
|
-
//path = conf.protocol + '://' +conf.hostname + path
|
|
1132
|
-
path = conf.hostname + path
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
if (req.headersSent) return next();
|
|
1136
|
-
|
|
1137
|
-
if (conf.env == 'dev') {
|
|
1138
|
-
res.writeHead(code, {
|
|
1139
|
-
'Location': path,
|
|
1140
|
-
'Cache-Control': 'no-cache, no-store, must-revalidate', // preventing browsers from caching it
|
|
1141
|
-
'Pragma': 'no-cache',
|
|
1142
|
-
'Expires': '0'
|
|
1143
|
-
})
|
|
1144
|
-
} else {
|
|
1145
|
-
res.writeHead(code, { 'Location': path })
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
console.warn(local.req.method +' ['+local.res.statusCode +'] '+ path);
|
|
1150
|
-
res.end();
|
|
1151
|
-
local.res.headersSent = true;// done for the render() method
|
|
1152
|
-
}
|
|
1153
|
-
next()
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
/**
|
|
1157
|
-
* Move files to assets dir
|
|
1158
|
-
*
|
|
1159
|
-
* @param {object} res
|
|
1160
|
-
* @param {collection} files
|
|
1161
|
-
*
|
|
1162
|
-
* @callback cb
|
|
1163
|
-
* @param {object} [err]
|
|
1164
|
-
* */
|
|
1165
|
-
var movefiles = function (i, res, files, cb) {
|
|
1166
|
-
if (!files.length || files.length == 0) {
|
|
1167
|
-
cb(false)
|
|
1168
|
-
} else {
|
|
1169
|
-
if ( fs.existsSync(files[i].target) ) new _(files[i].target).rmSync();
|
|
1170
|
-
|
|
1171
|
-
var sourceStream = fs.createReadStream(files[i].source);
|
|
1172
|
-
var destinationStream = fs.createWriteStream(files[i].target);
|
|
1173
|
-
|
|
1174
|
-
sourceStream
|
|
1175
|
-
.pipe(destinationStream)
|
|
1176
|
-
.on('error', function () {
|
|
1177
|
-
var err = 'Error on SuperController::copyFile(...): Not found ' + files[i].source + ' or ' + files[i].target;
|
|
1178
|
-
cb(err)
|
|
1179
|
-
})
|
|
1180
|
-
.on('close', function () {
|
|
1181
|
-
|
|
1182
|
-
try {
|
|
1183
|
-
fs.unlinkSync(files[i].source);
|
|
1184
|
-
files.splice(i, 1);
|
|
1185
|
-
} catch (err) {
|
|
1186
|
-
cb(err)
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
movefiles(i, res, files, cb)
|
|
1190
|
-
})
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
// TODO - download file
|
|
1195
|
-
/**
|
|
1196
|
-
* Download to targeteded filename.ext - Will create target if new
|
|
1197
|
-
* Use `cb` callback or `onComplete` event
|
|
1198
|
-
*
|
|
1199
|
-
* @param {string} filename
|
|
1200
|
-
* @param {string} content
|
|
1201
|
-
*
|
|
1202
|
-
* @callback [cb]
|
|
1203
|
-
* @param {object|null} error
|
|
1204
|
-
*
|
|
1205
|
-
* @event
|
|
1206
|
-
* @param {object|null} error
|
|
1207
|
-
**/
|
|
1208
|
-
//this.download(filename, content, cb) {}
|
|
1209
|
-
|
|
1210
|
-
//this.downloadLocalfile = function(pathname){}
|
|
1211
|
-
|
|
1212
|
-
/**
|
|
1213
|
-
* Upload to target - Will create target if new
|
|
1214
|
-
* Use `cb` callback or `onComplete` event
|
|
1215
|
-
*
|
|
1216
|
-
* @param {string} target
|
|
1217
|
-
*
|
|
1218
|
-
* @callback [cb]
|
|
1219
|
-
* @param {object} error
|
|
1220
|
-
* @param {array} files
|
|
1221
|
-
*
|
|
1222
|
-
* @event
|
|
1223
|
-
* @param {object} error
|
|
1224
|
-
* @param {array} files
|
|
1225
|
-
*
|
|
1226
|
-
* */
|
|
1227
|
-
this.upload = function(target, cb) {
|
|
1228
|
-
|
|
1229
|
-
var start = function(target, cb) {
|
|
1230
|
-
var files = local.req.files, uploadedFiles = [];
|
|
1231
|
-
|
|
1232
|
-
if ( typeof(files) == 'undefined' || files.count() == 0 ) {
|
|
1233
|
-
if (cb) {
|
|
1234
|
-
cb(new Error('No file to upload'))
|
|
1235
|
-
} else {
|
|
1236
|
-
self.emit('uploaded', new Error('No file to upload'))
|
|
1237
|
-
}
|
|
1238
|
-
} else {
|
|
1239
|
-
// saving files
|
|
1240
|
-
var uploadDir = new _(target)
|
|
1241
|
-
, list = []
|
|
1242
|
-
, i = 0
|
|
1243
|
-
, folder = uploadDir.mkdirSync()
|
|
1244
|
-
, el = null;
|
|
1245
|
-
|
|
1246
|
-
if (folder instanceof Error) {
|
|
1247
|
-
if (cb) {
|
|
1248
|
-
cb(folder)
|
|
1249
|
-
} else {
|
|
1250
|
-
self.emit('uploaded', folder)
|
|
1251
|
-
}
|
|
1252
|
-
} else {
|
|
1253
|
-
// files list
|
|
1254
|
-
for (el in files) {
|
|
1255
|
-
list[i] = {
|
|
1256
|
-
source: files[el].path,
|
|
1257
|
-
target: _(uploadDir.toString() + '/' + files[el].originalFilename)
|
|
1258
|
-
};
|
|
1259
|
-
uploadedFiles[i] = { location: list[i].target, file: files[el].originalFilename };
|
|
1260
|
-
++i
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
movefiles(0, local.res, list, function (err) {
|
|
1264
|
-
if (err) {
|
|
1265
|
-
if (cb) {
|
|
1266
|
-
cb(new Error('No file to upload'))
|
|
1267
|
-
} else {
|
|
1268
|
-
self.emit('uploaded', new Error('No file to upload'))
|
|
1269
|
-
}
|
|
1270
|
-
} else {
|
|
1271
|
-
if (cb) {
|
|
1272
|
-
cb(false, uploadedFiles)
|
|
1273
|
-
} else {
|
|
1274
|
-
self.emit('uploaded', false, uploadedFiles)
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
})
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
if ( typeof(cb) == 'undefined' ) {
|
|
1283
|
-
|
|
1284
|
-
return {
|
|
1285
|
-
onComplete : function(cb){
|
|
1286
|
-
self.on('uploaded', cb);
|
|
1287
|
-
start(target)
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
} else {
|
|
1291
|
-
start(target, cb)
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
/**
|
|
1297
|
-
* Query
|
|
1298
|
-
*
|
|
1299
|
-
* Allows you to act as a proxy between your frontend and a 1/3 API
|
|
1300
|
-
* */
|
|
1301
|
-
local.query.data = {};
|
|
1302
|
-
local.query.options = {
|
|
1303
|
-
host : undefined, // Must be an IP
|
|
1304
|
-
hostname : undefined, // cname of the host e.g.: `www.google.com` or `localhost`
|
|
1305
|
-
path : undefined, // e.g.: /test.html
|
|
1306
|
-
port : 80, // #80 by default but can be 3000
|
|
1307
|
-
method : 'GET', // POST | GET | PUT | DELETE
|
|
1308
|
-
agent : false,
|
|
1309
|
-
keepAlive: true,
|
|
1310
|
-
auth : undefined, // use `"username:password"` for basic authentification
|
|
1311
|
-
rejectUnauthorized: undefined, // ignore verification when requesting on https (443)
|
|
1312
|
-
headers : {
|
|
1313
|
-
'Content-Type': 'application/json',
|
|
1314
|
-
// 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
1315
|
-
|
|
1316
|
-
// 'X-Requested-With': 'XMLHttpRequest' // to convert into an XHR query
|
|
1317
|
-
'Content-Length': local.query.data.length
|
|
1318
|
-
}
|
|
1319
|
-
};
|
|
1320
|
-
|
|
1321
|
-
this.query = function(options, data, callback) {
|
|
1322
|
-
|
|
1323
|
-
var queryData = {}
|
|
1324
|
-
, defaultOptions = local.query.options
|
|
1325
|
-
, path = options.path
|
|
1326
|
-
, browser = null
|
|
1327
|
-
, options = merge(options, defaultOptions)
|
|
1328
|
-
;
|
|
1329
|
-
|
|
1330
|
-
for (var o in options) {//cleaning
|
|
1331
|
-
if ( typeof(options[o]) == 'undefined' || options[o] == undefined) {
|
|
1332
|
-
delete options[o]
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
if ( !options.host && !options.hostname ) {
|
|
1337
|
-
self.emit('query#complete', new Error('SuperController::query() needs at least a `host IP` or a `hostname`'))
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
if ( /\:\/\//.test(options.host) ) {
|
|
1341
|
-
var hArr = options.host.split('://');
|
|
1342
|
-
options.port = ports[hArr[0]];
|
|
1343
|
-
options.host = hArr[1]
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
if (arguments.length <3) {
|
|
1347
|
-
if ( typeof(data) == 'function') {
|
|
1348
|
-
var callback = data;
|
|
1349
|
-
var data = undefined;
|
|
1350
|
-
} else {
|
|
1351
|
-
callback = undefined;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
if ( typeof(data) != 'undefined' && data.count() > 0) {
|
|
1355
|
-
|
|
1356
|
-
queryData = '?';
|
|
1357
|
-
// TODO - if 'application/json' && method == (put|post)
|
|
1358
|
-
if ( ['put', 'post'].indexOf(options.method.toLowerCase()) >-1 && /(text\/plain|application\/json|application\/x\-www\-form)/i.test(options.headers['Content-Type']) ) {
|
|
1359
|
-
// replacing
|
|
1360
|
-
queryData = encodeURIComponent(JSON.stringify(data))
|
|
1361
|
-
|
|
1362
|
-
} else {
|
|
1363
|
-
//Sample request.
|
|
1364
|
-
//options.path = '/updater/start?release={"version":"0.0.5-dev","url":"http://10.1.0.1:8080/project/bundle/repository/archive?ref=0.0.5-dev","date":1383669077141}&pid=46493';
|
|
1365
|
-
|
|
1366
|
-
for (var d in data) {
|
|
1367
|
-
if ( typeof(data[d]) == 'object') {
|
|
1368
|
-
data[d] = JSON.stringify(data[d]);
|
|
1369
|
-
}
|
|
1370
|
-
queryData += d + '=' + data[d] + '&';
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
queryData = queryData.substring(0, queryData.length-1);
|
|
1374
|
-
queryData = queryData.replace(/\s/g, '%20');
|
|
1375
|
-
options.path += queryData;
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
} else {
|
|
1379
|
-
queryData = ''
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
// Internet Explorer override
|
|
1384
|
-
if ( /msie/i.test(local.req.headers['user-agent']) ) {
|
|
1385
|
-
options.headers['Content-Type'] = 'text/plain';
|
|
1386
|
-
} else {
|
|
1387
|
-
options.headers['Content-Type'] = local.options.conf.server.coreConfiguration.mime['json'];
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
if ( typeof(local.req.headers.cookie) != 'undefined' ) { // useful for CORS : forward cookies from the original request
|
|
1391
|
-
options.headers.cookie = local.req.headers.cookie;
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
//you need this, even when empty.
|
|
1395
|
-
options.headers['Content-Length'] = queryData.length;
|
|
1396
|
-
|
|
1397
|
-
browser = (options.port == 443) ? https : http;
|
|
1398
|
-
|
|
1399
|
-
var req = browser.request(options, function(res) {
|
|
1400
|
-
|
|
1401
|
-
res.setEncoding('utf8');
|
|
1402
|
-
|
|
1403
|
-
// upgrade response headers to handler
|
|
1404
|
-
if ( typeof(res.headers['access-control-allow-credentials']) != 'undefined' )
|
|
1405
|
-
local.options.withCredentials = res.headers['access-control-allow-credentials'];
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
var data = '';
|
|
1409
|
-
|
|
1410
|
-
res.on('data', function onData (chunk) {
|
|
1411
|
-
data += chunk;
|
|
1412
|
-
});
|
|
1413
|
-
|
|
1414
|
-
res.on('end', function onEnd() {
|
|
1415
|
-
|
|
1416
|
-
//Only when needed.
|
|
1417
|
-
if ( typeof(callback) != 'undefined' ) {
|
|
1418
|
-
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)/.test(data) ) {
|
|
1419
|
-
try {
|
|
1420
|
-
data = JSON.parse(data)
|
|
1421
|
-
} catch (err) {
|
|
1422
|
-
data = {
|
|
1423
|
-
status : 500,
|
|
1424
|
-
error : data
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
if ( data.status && !/^2/.test(data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.status]) != 'undefined' ) {
|
|
1430
|
-
callback(data)
|
|
1431
|
-
} else {
|
|
1432
|
-
callback( false, data )
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
} else {
|
|
1436
|
-
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)/.test(data) ) {
|
|
1437
|
-
try {
|
|
1438
|
-
data = JSON.parse(data)
|
|
1439
|
-
} catch (err) {
|
|
1440
|
-
data = {
|
|
1441
|
-
status : 500,
|
|
1442
|
-
error : data
|
|
1443
|
-
}
|
|
1444
|
-
self.emit('query#complete', data)
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
if ( data.status && !/^2/.test(data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.status]) != 'undefined' ) {
|
|
1449
|
-
self.emit('query#complete', data)
|
|
1450
|
-
} else {
|
|
1451
|
-
self.emit('query#complete', false, data)
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
})
|
|
1455
|
-
});
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
//starting from from >0.10.15
|
|
1459
|
-
req.on('error', function onError(err) {
|
|
1460
|
-
|
|
1461
|
-
console.error(err.stack||err.message);
|
|
1462
|
-
// you can get here if :
|
|
1463
|
-
// - you are trying to query using: `enctype="multipart/form-data"`
|
|
1464
|
-
// -
|
|
1465
|
-
if ( typeof(callback) != "undefined") {
|
|
1466
|
-
callback(err)
|
|
1467
|
-
} else {
|
|
1468
|
-
var data = {
|
|
1469
|
-
status : 500,
|
|
1470
|
-
error : err.stack || err.message
|
|
1471
|
-
};
|
|
1472
|
-
|
|
1473
|
-
self.emit('query#complete', data)
|
|
1474
|
-
}
|
|
1475
|
-
});
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
if (req) { // don't touch this please
|
|
1479
|
-
if (req.write) req.write(queryData);
|
|
1480
|
-
if (req.end) req.end();
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
return {
|
|
1484
|
-
onComplete : function(cb) {
|
|
1485
|
-
self.once('query#complete', function(err, data){
|
|
1486
|
-
|
|
1487
|
-
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)/.test(data) ) {
|
|
1488
|
-
try {
|
|
1489
|
-
data = JSON.parse(data)
|
|
1490
|
-
} catch (err) {
|
|
1491
|
-
data = {
|
|
1492
|
-
status : 500,
|
|
1493
|
-
error : data
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
if ( data.status && !/^2/.test(data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.status]) != 'undefined') {
|
|
1499
|
-
cb(data)
|
|
1500
|
-
} else {
|
|
1501
|
-
cb(err, data)
|
|
1502
|
-
}
|
|
1503
|
-
})
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
/**
|
|
1510
|
-
* forward404Unless
|
|
1511
|
-
*
|
|
1512
|
-
* @param {boolean} condition
|
|
1513
|
-
* @param {object} req
|
|
1514
|
-
* @param {object} res
|
|
1515
|
-
*
|
|
1516
|
-
* @callback [ next ]
|
|
1517
|
-
* @param {string | boolean} err
|
|
1518
|
-
*
|
|
1519
|
-
* @return {string | boolean} err
|
|
1520
|
-
* */
|
|
1521
|
-
this.forward404Unless = function(condition, req, res, next) {
|
|
1522
|
-
var pathname = req.url;
|
|
1523
|
-
|
|
1524
|
-
if (!condition) {
|
|
1525
|
-
self.throwError(res, 404, 'Page not found\n' + pathname);
|
|
1526
|
-
var err = new Error('Page not found\n' + pathname);
|
|
1527
|
-
if ( typeof(next) != 'undefined')
|
|
1528
|
-
next(err)
|
|
1529
|
-
else
|
|
1530
|
-
return err
|
|
1531
|
-
} else {
|
|
1532
|
-
if ( typeof(next) != 'undefined' )
|
|
1533
|
-
next(false)
|
|
1534
|
-
else
|
|
1535
|
-
return false
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
/**
|
|
1540
|
-
* Get all Params
|
|
1541
|
-
* */
|
|
1542
|
-
var getParams = function(req) {
|
|
1543
|
-
|
|
1544
|
-
req.getParams = function() {
|
|
1545
|
-
// copy
|
|
1546
|
-
var params = JSON.parse(JSON.stringify(req.params));
|
|
1547
|
-
switch( req.method.toLowerCase() ) {
|
|
1548
|
-
case 'get':
|
|
1549
|
-
params = merge(params, req.get, true);
|
|
1550
|
-
break;
|
|
1551
|
-
|
|
1552
|
-
case 'post':
|
|
1553
|
-
params = merge(params, req.post, true);
|
|
1554
|
-
break;
|
|
1555
|
-
|
|
1556
|
-
case 'put':
|
|
1557
|
-
params = merge(params, req.put, true);
|
|
1558
|
-
break;
|
|
1559
|
-
|
|
1560
|
-
case 'delete':
|
|
1561
|
-
params = merge(params, req.delete, true);
|
|
1562
|
-
break;
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
return params
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
req.getParam = function(name) {
|
|
1569
|
-
// copy
|
|
1570
|
-
var param = null, params = JSON.parse(JSON.stringify(req.params));
|
|
1571
|
-
switch( req.method.toLowerCase() ) {
|
|
1572
|
-
case 'get':
|
|
1573
|
-
param = req.get[name];
|
|
1574
|
-
break;
|
|
1575
|
-
|
|
1576
|
-
case 'post':
|
|
1577
|
-
param = req.post[name];
|
|
1578
|
-
break;
|
|
1579
|
-
|
|
1580
|
-
case 'put':
|
|
1581
|
-
param= req.put[name];
|
|
1582
|
-
break;
|
|
1583
|
-
|
|
1584
|
-
case 'delete':
|
|
1585
|
-
param = req.delete[name];
|
|
1586
|
-
break;
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
return param
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
/**
|
|
1594
|
-
* Get config
|
|
1595
|
-
*
|
|
1596
|
-
* @param {string} [name] - Conf name without extension.
|
|
1597
|
-
* @return {object} config
|
|
1598
|
-
*
|
|
1599
|
-
* TODO - Protect result
|
|
1600
|
-
* */
|
|
1601
|
-
this.getConfig = function(name) {
|
|
1602
|
-
var config = null;
|
|
1603
|
-
|
|
1604
|
-
if ( typeof(name) != 'undefined' ) {
|
|
1605
|
-
try {
|
|
1606
|
-
// needs to be read only
|
|
1607
|
-
config = JSON.stringify(local.options.conf.content[name]);
|
|
1608
|
-
return JSON.parse(config)
|
|
1609
|
-
} catch (err) {
|
|
1610
|
-
return undefined
|
|
1611
|
-
}
|
|
1612
|
-
} else {
|
|
1613
|
-
config = JSON.stringify(local.options.conf);
|
|
1614
|
-
return JSON.parse(config)
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
/**
|
|
1619
|
-
* Get locales
|
|
1620
|
-
*
|
|
1621
|
-
* @param {string} [shortCountryCode] - e.g. EN
|
|
1622
|
-
*
|
|
1623
|
-
* @return {object} locales
|
|
1624
|
-
* */
|
|
1625
|
-
this.getLocales = function (shortCountryCode) {
|
|
1626
|
-
|
|
1627
|
-
var userLocales = local.options.conf.locales;
|
|
1628
|
-
|
|
1629
|
-
if ( typeof(shortCountryCode) != 'undefined' ) {
|
|
1630
|
-
|
|
1631
|
-
var locales = new Collection( getContext('gina').locales );
|
|
1632
|
-
|
|
1633
|
-
try {
|
|
1634
|
-
userLocales = locales.findOne({ lang: userLangCode }).content
|
|
1635
|
-
} catch (err) {
|
|
1636
|
-
console.warn('language code `'+ userLangCode +'` not handled to setup locales: replacing by `en`');
|
|
1637
|
-
userLocales = locales.findOne({ lang: 'en' }).content // by default
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
/**
|
|
1643
|
-
* Get countries list
|
|
1644
|
-
*
|
|
1645
|
-
* @param {string} [code] - e.g.: short, long, fifa, m49
|
|
1646
|
-
*
|
|
1647
|
-
* @return {object} countries - countries code & value list
|
|
1648
|
-
* */
|
|
1649
|
-
var getCountries = function (code) {
|
|
1650
|
-
var list = {}, cde = 'short', name = null;
|
|
1651
|
-
|
|
1652
|
-
if ( typeof(code) != 'undefined' && typeof(userLocales[0][code]) == 'string' ) {
|
|
1653
|
-
cde = code
|
|
1654
|
-
} else if ( typeof(code) != 'undefined' ) (
|
|
1655
|
-
console.warn('`'+ code +'` not supported : sticking with `short` code')
|
|
1656
|
-
)
|
|
1657
|
-
|
|
1658
|
-
for ( var i = 0, len = userLocales.length; i< len; ++i ) {
|
|
1659
|
-
|
|
1660
|
-
if (userLocales[i][cde]) {
|
|
1661
|
-
|
|
1662
|
-
name = userLocales[i].full || userLocales[i].officialName.short;
|
|
1663
|
-
|
|
1664
|
-
if ( name )
|
|
1665
|
-
list[ userLocales[i][cde] ] = name;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
return list
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
return {
|
|
1673
|
-
'getCountries': getCountries
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
/**
|
|
1678
|
-
* Get forms rules
|
|
1679
|
-
*
|
|
1680
|
-
* @param {string} [formId]
|
|
1681
|
-
*
|
|
1682
|
-
* @return {object} rules
|
|
1683
|
-
*
|
|
1684
|
-
* */
|
|
1685
|
-
this.getFormsRules = function (formId) {
|
|
1686
|
-
try {
|
|
1687
|
-
|
|
1688
|
-
if ( typeof(formId) != 'undefined' ) {
|
|
1689
|
-
try {
|
|
1690
|
-
formId = formId.replace(/\-/g, '.');
|
|
1691
|
-
return JSON.parse(JSON.stringify(local.options.conf.content.forms)).rules[formId]
|
|
1692
|
-
} catch (err) {
|
|
1693
|
-
self.throwError(err)
|
|
1694
|
-
}
|
|
1695
|
-
} else {
|
|
1696
|
-
return JSON.parse(JSON.stringify(local.options.conf.content.forms)).rules
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
} catch (err) {
|
|
1700
|
-
self.throwError(local.res, 500, err.stack||err.message)
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
/**
|
|
1705
|
-
* Throw error
|
|
1706
|
-
*
|
|
1707
|
-
* @param {object} [ res ]
|
|
1708
|
-
* @param {number} code
|
|
1709
|
-
* @param {string} msg
|
|
1710
|
-
*
|
|
1711
|
-
* @return {void}
|
|
1712
|
-
* */
|
|
1713
|
-
this.throwError = function(res, code, msg) {
|
|
1714
|
-
|
|
1715
|
-
if (arguments.length == 1 && typeof(res) == 'object' ) {
|
|
1716
|
-
var code = ( res && typeof(res.status) != 'undefined' ) ? res.status : 500;
|
|
1717
|
-
//, msg = res.stack || res.message || res.error
|
|
1718
|
-
var msg = {};
|
|
1719
|
-
|
|
1720
|
-
if ( res instanceof Error) {
|
|
1721
|
-
msg.error = res.message;
|
|
1722
|
-
msg.stack = res.stack;
|
|
1723
|
-
} else {
|
|
1724
|
-
msg = JSON.parse(JSON.stringify(res))
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
var res = local.res;
|
|
1728
|
-
|
|
1729
|
-
} else if (arguments.length < 3) {
|
|
1730
|
-
var msg = code || null
|
|
1731
|
-
, code = res || 500
|
|
1732
|
-
, res = local.res;
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
var req = local.req;
|
|
1736
|
-
var next = local.next;
|
|
1737
|
-
|
|
1738
|
-
if (!res.headersSent) {
|
|
1739
|
-
if ( self.isXMLRequest() || !hasViews() || !local.options.isUsingTemplate ) {
|
|
1740
|
-
// allowing this.throwError(err)
|
|
1741
|
-
if ( typeof(code) == 'object' && !msg && typeof(code.status) != 'undefined' && typeof(code.error) != 'undefined' ) {
|
|
1742
|
-
msg = code.error || code.message;
|
|
1743
|
-
code = code.status || 500;
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
if ( !req.headers['content-type'] ) {
|
|
1747
|
-
req.headers['content-type'] = local.options.conf.server.coreConfiguration.mime['json']
|
|
1748
|
-
}
|
|
1749
|
-
// Internet Explorer override
|
|
1750
|
-
if ( typeof(req.headers['user-agent']) != 'undefined' ) {
|
|
1751
|
-
if ( /msie/i.test(req.headers['user-agent']) ) {
|
|
1752
|
-
res.writeHead(code, "Content-Type", "text/plain")
|
|
1753
|
-
} else {
|
|
1754
|
-
res.writeHead(code, { 'Content-Type': req.headers['content-type']} )
|
|
1755
|
-
}
|
|
1756
|
-
} else if ( typeof(req.headers['content-type']) != 'undefined' ) {
|
|
1757
|
-
res.writeHead(code, { 'Content-Type': req.headers['content-type']} )
|
|
1758
|
-
} else {
|
|
1759
|
-
res.writeHead(code, "Content-Type", local.options.conf.server.coreConfiguration.mime['json'])
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
console.error(req.method +' ['+res.statusCode +'] '+ req.url);
|
|
1763
|
-
res.end(JSON.stringify({
|
|
1764
|
-
status: code,
|
|
1765
|
-
error: msg.error || msg,
|
|
1766
|
-
stack: msg.stack
|
|
1767
|
-
}))
|
|
1768
|
-
} else {
|
|
1769
|
-
res.writeHead(code, { 'Content-Type': 'text/html'} );
|
|
1770
|
-
console.error(req.method +' ['+ res.statusCode +'] '+ req.url);
|
|
1771
|
-
|
|
1772
|
-
//var msgString = msg.stack || msg.error || msg;
|
|
1773
|
-
var msgString = '<h1 class="status">Error '+ code +'.</h1>';
|
|
1774
|
-
var eCode = code.toString().substr(0,1);
|
|
1775
|
-
|
|
1776
|
-
if ( typeof(msg) == 'object' ) {
|
|
1777
|
-
|
|
1778
|
-
if (msg.title) {
|
|
1779
|
-
msgString += '<pre class="'+ eCode +'xx title">'+ msg.title +'</pre>';
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
if (msg.error) {
|
|
1783
|
-
msgString += '<pre class="'+ eCode +'xx message">'+ msg.error +'</pre>';
|
|
1784
|
-
}
|
|
1785
|
-
|
|
1786
|
-
if (msg.message) {
|
|
1787
|
-
msgString += '<pre class="'+ eCode +'xx message">'+ msg.message +'</pre>';
|
|
1788
|
-
}
|
|
1789
|
-
|
|
1790
|
-
if (msg.stack) {
|
|
1791
|
-
|
|
1792
|
-
if (msg.error) {
|
|
1793
|
-
msg.stack = msg.stack.replace(msg.error, '')
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
|
-
if (msg.message) {
|
|
1797
|
-
msg.stack = msg.stack.replace(msg.message, '')
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
msg.stack = msg.stack.replace('Error:', '').replace(' ', '');
|
|
1801
|
-
msgString += '<pre class="'+ eCode +'xx stack">'+ msg.stack +'</pre>';
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
} else {
|
|
1805
|
-
msgString += '<pre class="'+ eCode +'xx message">'+ msg +'</pre>';
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
res.end(msgString)
|
|
1809
|
-
}
|
|
1810
|
-
} else {
|
|
1811
|
-
next()
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
// converting references to objects
|
|
1816
|
-
var refToObj = function (arr){
|
|
1817
|
-
var tmp = null,
|
|
1818
|
-
curObj = {},
|
|
1819
|
-
obj = {},
|
|
1820
|
-
count = 0,
|
|
1821
|
-
data = {},
|
|
1822
|
-
last = null;
|
|
1823
|
-
for (var r in arr) {
|
|
1824
|
-
tmp = r.split(".");
|
|
1825
|
-
//Creating structure - Adding sub levels
|
|
1826
|
-
for (var o in tmp) {
|
|
1827
|
-
count++;
|
|
1828
|
-
if (last && typeof(obj[last]) == "undefined") {
|
|
1829
|
-
curObj[last] = {};
|
|
1830
|
-
if (count >= tmp.length) {
|
|
1831
|
-
// assigning.
|
|
1832
|
-
// !!! if null or undefined, it will be ignored while extending.
|
|
1833
|
-
curObj[last][tmp[o]] = (arr[r]) ? arr[r] : "undefined";
|
|
1834
|
-
last = null;
|
|
1835
|
-
count = 0;
|
|
1836
|
-
break
|
|
1837
|
-
} else {
|
|
1838
|
-
curObj[last][tmp[o]] = {}
|
|
1839
|
-
}
|
|
1840
|
-
} else if (tmp.length === 1) { //Just one root var
|
|
1841
|
-
curObj[tmp[o]] = (arr[r]) ? arr[r] : "undefined";
|
|
1842
|
-
obj = curObj;
|
|
1843
|
-
break
|
|
1844
|
-
}
|
|
1845
|
-
obj = curObj;
|
|
1846
|
-
last = tmp[o]
|
|
1847
|
-
}
|
|
1848
|
-
//data = merge(data, obj, true);
|
|
1849
|
-
data = merge(obj, data);
|
|
1850
|
-
obj = {};
|
|
1851
|
-
curObj = {}
|
|
1852
|
-
}
|
|
1853
|
-
return data
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
init()
|
|
1857
|
-
};
|
|
1858
|
-
|
|
1859
|
-
SuperController = inherits(SuperController, EventEmitter);
|
|
1860
|
-
module.exports = SuperController
|