gina 0.1.1-alpha.18 → 0.1.1-alpha.180
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/AUTHORS +2 -1
- package/LICENSE +1 -1
- package/README-4Contributors.md +30 -0
- package/README.md +208 -32
- package/bin/cli +165 -68
- package/bin/cli-debug +49 -18
- package/bin/cmd +40 -18
- package/bin/gina +48 -37
- package/framework/{v0.1.1-alpha.18/lib/inherits → v0.1.1-alpha.180}/LICENSE +1 -1
- package/framework/v0.1.1-alpha.180/VERSION +1 -0
- package/framework/{v0.1.1-alpha.18/core/asset/js/plugin/readme.md → v0.1.1-alpha.180/core/asset/plugin/README.md} +31 -9
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/css/gina.min.css +1 -0
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/css/gina.min.css.map +1 -0
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/html/toolbar.html +251 -0
- package/framework/{v0.1.1-alpha.18/core/asset/js/plugin/dist → v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/js}/gina.js +3958 -3170
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/js/gina.min.js +759 -0
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/js/gina.min.js.map +8 -0
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/js/gina.onload.min.js +5 -0
- package/framework/v0.1.1-alpha.180/core/asset/plugin/dist/vendor/gina/js/gina.onload.min.js.map +8 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/config.js +123 -54
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/connectors/couchbase/index.js +373 -259
- package/framework/v0.1.1-alpha.180/core/connectors/couchbase/lib/connector.js +22 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/connectors/couchbase/lib/connector.v2.js +51 -51
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/connectors/couchbase/lib/connector.v3.js +51 -51
- package/framework/v0.1.1-alpha.180/core/connectors/couchbase/lib/connector.v4.js +384 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/connectors/couchbase/lib/n1ql.js +3 -2
- package/framework/v0.1.1-alpha.180/core/connectors/couchbase/lib/session-store.js +22 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/connectors/couchbase/lib/session-store.v3.js +12 -12
- package/framework/v0.1.1-alpha.180/core/connectors/couchbase/lib/session-store.v4.js +361 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/controller/controller.js +900 -767
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/dev/index.js +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/dev/lib/class.js +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/dev/lib/factory.js +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/gna.js +13 -9
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/README.md +5 -0
- package/framework/v0.1.1-alpha.180/core/locales/dist/region/en.json +5727 -0
- package/framework/v0.1.1-alpha.180/core/locales/dist/region/fr.json +11452 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/index.js +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/src/make.js +39 -41
- package/framework/v0.1.1-alpha.180/core/locales/src/resources/region.mapping.json +43 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/model/entity.js +87 -67
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/model/index.js +16 -16
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/model/template/entityFactory.js +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/model/template/index.js +15 -14
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/index.js +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/file/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/intl/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/intl/src/main.js +5 -5
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/storage/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/storage/src/main.js +4 -4
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/validator/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/validator/src/form-validator.js +399 -298
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/validator/src/main.js +1292 -1258
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/router.js +96 -90
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/server.isaac.js +184 -179
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/server.js +245 -67
- package/framework/v0.1.1-alpha.180/core/template/boilerplate/bundle/config/settings.json +12 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/config/settings.server.json +4 -4
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/config/templates.json +4 -4
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/controllers/controller.content.js +1 -1
- package/framework/v0.1.1-alpha.180/core/template/boilerplate/bundle/controllers/setup.js +111 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/index.js +13 -1
- package/framework/v0.1.1-alpha.180/core/template/boilerplate/bundle_templates/html/content/homepage.html +8 -0
- package/framework/v0.1.1-alpha.180/core/template/boilerplate/bundle_templates/html/includes/error-msg-noscript.html +11 -0
- package/framework/v0.1.1-alpha.180/core/template/boilerplate/bundle_templates/html/includes/error-msg-outdated-browser.html +8 -0
- package/framework/{v0.1.1-alpha.18/core/template/boilerplate/bundle_templates/html/layout → v0.1.1-alpha.180/core/template/boilerplate/bundle_templates/html/layouts}/main.html +10 -3
- package/framework/v0.1.1-alpha.180/core/template/command/gina.bat.tpl +8 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/command/gina.tpl +4 -4
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/conf/env.json +11 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/conf/package.json +1 -1
- package/framework/v0.1.1-alpha.180/core/template/conf/statics.json +12 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/conf/templates.json +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/console.js +3 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/context.js +146 -6
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/dateFormat.js +9 -7
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/index.js +13 -8
- package/framework/v0.1.1-alpha.180/helpers/json/LICENSE +9 -0
- package/framework/{v0.1.1-alpha.18/helpers/plugins → v0.1.1-alpha.180/helpers/json}/package.json +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/json/src/main.js +51 -25
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/path.js +163 -96
- package/framework/{v0.1.1-alpha.18/helpers/json → v0.1.1-alpha.180/helpers/plugins}/package.json +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/plugins/src/api-error.js +23 -23
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/plugins/src/main.js +3 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/prototypes.js +46 -38
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/task.js +21 -14
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/text.js +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/archiver/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/archiver/src/dep/jszip.min.js +3 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/archiver/src/main.js +168 -168
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/aliases.json +4 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/add.js +79 -22
- package/framework/v0.1.1-alpha.180/lib/cmd/bundle/arguments.json +7 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/help.txt +4 -2
- package/framework/v0.1.1-alpha.180/lib/cmd/bundle/list.js +176 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/remove.js +22 -22
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/start.js +264 -46
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/stop.js +93 -74
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/list.js +20 -4
- package/framework/{v0.1.1-alpha.18/lib/cmd/scope → v0.1.1-alpha.180/lib/cmd/env}/use.js +21 -1
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/build.js +85 -0
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/init.js +798 -0
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/link-node-modules.js +86 -0
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/link.js +109 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/open.js +15 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/restart.js +58 -26
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/set.js +273 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/start.js +43 -20
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/status.js +138 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/stop.js +44 -28
- package/framework/v0.1.1-alpha.180/lib/cmd/framework/tail.js +299 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/version.js +12 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/helper.js +74 -5
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/index.js +23 -23
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/port/inc/scan.js +32 -16
- package/framework/v0.1.1-alpha.180/lib/cmd/port/list.js +459 -0
- package/framework/v0.1.1-alpha.180/lib/cmd/port/reset.js +426 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/add.js +146 -122
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/arguments.json +2 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/list.js +16 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/remove.js +17 -17
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/protocol/set.js +239 -201
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/list.js +24 -8
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/view/add.js +34 -9
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/collection/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/collection/src/main.js +241 -241
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/config.js +31 -30
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cron/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cron/src/main.js +10 -9
- package/framework/v0.1.1-alpha.180/lib/domain/LICENSE +9 -0
- package/framework/v0.1.1-alpha.180/lib/domain/README.md +46 -0
- package/framework/v0.1.1-alpha.180/lib/domain/dist/public_suffix_list.dat +14186 -0
- package/framework/v0.1.1-alpha.180/lib/domain/package.json +20 -0
- package/framework/v0.1.1-alpha.180/lib/domain/src/main.js +442 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/generator/index.js +4 -4
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/index.js +3 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180/lib/inherits}/LICENSE +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/README.md +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/package.json +3 -4
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/src/main.js +3 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/package.json +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/default/index.js +13 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/file/index.js +109 -14
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/mq/index.js +12 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/mq/listener.js +16 -14
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/mq/speaker.js +32 -3
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/helper.js +21 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/main.js +34 -9
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/math/index.js +9 -9
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/merge/README.md +2 -2
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/merge/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/merge/src/main.js +76 -88
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/model.js +10 -10
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/proc.js +87 -49
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/routing/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/routing/src/main.js +280 -274
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/session-store.js +6 -6
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/shell.js +3 -3
- package/framework/v0.1.1-alpha.180/lib/swig-filters/README.md +0 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/swig-filters/package.json +1 -1
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/swig-filters/src/main.js +140 -119
- package/framework/v0.1.1-alpha.180/lib/url/README.md +0 -0
- package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/validator.js +2 -2
- package/framework/v0.1.1-alpha.180/package.json +14 -0
- package/package.json +33 -24
- package/resources/home/main.json +53 -4
- package/resources/home/settings.json +9 -0
- package/resources/home/user/extensions/logger/default/config.json +1 -1
- package/resources/package.json.template +29 -18
- package/script/post_install.js +411 -126
- package/script/post_publish.js +186 -0
- package/script/pre_install.js +425 -77
- package/script/prepare_version.js +275 -98
- package/services/.gna/67fdf1b224a2ed5597e63d4b64283834468e05e3.txt +0 -0
- package/services/.gna/arch +1 -0
- package/services/.gna/locals.json +14 -0
- package/services/.gna/platform +1 -0
- package/services/configure +6 -0
- package/services/env.json +18 -0
- package/services/manifest.json +30 -0
- package/services/package.json +11 -0
- package/services/src/proxy/config/app.json +6 -0
- package/services/src/proxy/config/routing.json +11 -0
- package/services/src/proxy/config/settings.json +9 -0
- package/services/src/proxy/config/settings.server.json +31 -0
- package/services/src/proxy/config/statics.json +3 -0
- package/services/src/proxy/controllers/controller.content.js +58 -0
- package/services/src/proxy/controllers/controller.js +30 -0
- package/{framework/v0.1.1-alpha.18/core/template/boilerplate/bundle → services/src/proxy}/controllers/setup.js +14 -14
- package/services/src/proxy/index.js +31 -0
- package/services/src/proxy/lib/domain/README.md +48 -0
- package/services/src/proxy/lib/domain/src/config/public_suffix_list.dat +14186 -0
- package/services/src/toolbar/config/app.json +6 -0
- package/services/src/toolbar/config/routing.json +11 -0
- package/{framework/v0.1.1-alpha.18/core/template/boilerplate/bundle → services/src/toolbar}/config/settings.json +0 -0
- package/services/src/toolbar/config/settings.server.json +30 -0
- package/services/src/toolbar/controllers/controller.content.js +39 -0
- package/services/src/toolbar/controllers/controller.js +30 -0
- package/services/src/toolbar/controllers/setup.js +111 -0
- package/services/src/toolbar/index.js +43 -0
- package/utils/helper.js +236 -185
- package/utils/prototypes.js +9 -9
- package/utils/prototypes.json_clone.js +36 -35
- package/doc/framework/cli/doc.json +0 -9
- package/doc/framework/index.md +0 -60
- package/framework/v0.1.1-alpha.18/VERSION +0 -1
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.js.map +0 -56
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.min.css +0 -1
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.min.css.map +0 -1
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.min.js +0 -736
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.min.js.map +0 -56
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.onload.min.js +0 -5
- package/framework/v0.1.1-alpha.18/core/asset/js/plugin/dist/gina.onload.min.js.map +0 -8
- package/framework/v0.1.1-alpha.18/core/connectors/couchbase/lib/connector.js +0 -20
- package/framework/v0.1.1-alpha.18/core/connectors/couchbase/lib/session-store.js +0 -21
- package/framework/v0.1.1-alpha.18/core/locales/dist/region/en.json +0 -9492
- package/framework/v0.1.1-alpha.18/core/locales/dist/region/fr.json +0 -9492
- package/framework/v0.1.1-alpha.18/core/locales/src/resources/region.mapping.json +0 -28
- package/framework/v0.1.1-alpha.18/core/template/boilerplate/bundle_templates/html/homepage.html +0 -4
- package/framework/v0.1.1-alpha.18/core/template/conf/statics.json +0 -10
- package/framework/v0.1.1-alpha.18/lib/cmd/bundle/arguments.json +0 -4
- package/framework/v0.1.1-alpha.18/lib/cmd/bundle/list.js +0 -129
- package/framework/v0.1.1-alpha.18/lib/cmd/framework/init.js +0 -514
- package/framework/v0.1.1-alpha.18/lib/cmd/framework/set.js +0 -161
- package/framework/v0.1.1-alpha.18/lib/cmd/framework/status.js +0 -72
- package/framework/v0.1.1-alpha.18/lib/cmd/framework/tail.js +0 -183
- package/framework/v0.1.1-alpha.18/lib/cmd/port/list.js +0 -176
- package/framework/v0.1.1-alpha.18/package.json +0 -14
- /package/{framework/v0.1.1-alpha.18/core/template/command/gina.bat.tpl → bin/gina.bat} +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/AUTHORS +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/html/nolayout.html +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/html/static.html +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/img/android-chrome-192x192.png +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/img/android-chrome-512x512.png +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/img/apple-touch-icon.png +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/img/favicon-16x16.png +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/img/favicon-32x32.png +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/asset/img/favicon.ico +0 -0
- /package/framework/{v0.1.1-alpha.18/core/asset/js → v0.1.1-alpha.180/core/asset}/plugin/uuid.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/connectors/couchbase/lib/session-store.v2.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/controller/controller.framework.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/controller/index.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/.travis.yml +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/LICENSE +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/deps/encoding/encoding-indexes.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/deps/encoding/encoding.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/lib/main.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/lib/types/multipart.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/lib/types/urlencoded.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/lib/utils.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/busboy/package.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/deps/swig-client/swig-2.0.0.min.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/dev/lib/tools.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/currency.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/dist/language/en.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/dist/language/fr.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/src/resources/currency.csv +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/locales/src/resources/region.csv +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/mime.types +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/file/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/file/build.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/intl/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/intl/build.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/storage/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/storage/build.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/validator/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/plugins/lib/validator/build.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/server.express.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/status.codes +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/config/app.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/config/routing.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle/controllers/controller.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_namespace/controllers/controller.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_public/css/default.css +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_public/css/vendor/readme.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_public/favicon.ico +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_public/js/vendor/readme.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_public/readme.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/boilerplate/bundle_templates/handlers/main.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/conf/manifest.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/conf/settings.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/error/client/json/401.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/error/client/json/403.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/error/client/json/404.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/error/server/html/50x.html +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/error/server/json/500.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/error/server/json/503.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/core/template/extensions/logger/config.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/json/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/helpers/plugins/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/archiver/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/archiver/build.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/copy.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/cp.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/rename.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/restart.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/rm.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/bundle/status.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/add.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/get.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/help.txt +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/link-dev.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/remove.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/rm.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/set.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/env/unset.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/dot.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/get.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/help.txt +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/msg.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/framework/update.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/gina-dev.1.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/gina-framework.1.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/gina.1.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/msg.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/port/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/port/help.txt +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/port/set.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/build.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/help.txt +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/import.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/move.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/rename.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/restart.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/rm.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/start.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/status.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/project/stop.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/protocol/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/protocol/help.txt +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/protocol/list.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/help.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/help.txt +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/link-local.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/remove.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/rm.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/set.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cmd/scope/unset.js +0 -0
- /package/framework/{v0.1.1-alpha.18/lib/cmd/env → v0.1.1-alpha.180/lib/cmd/scope}/use.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/collection/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/collection/build.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/cron/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18/lib/routing/README.md → v0.1.1-alpha.180/lib/domain/exemples/backend.js} +0 -0
- /package/framework/{v0.1.1-alpha.18/lib/routing/build.json → v0.1.1-alpha.180/lib/domain/exemples/frontend.html} +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/example/inheriting_eventemitter.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/example/protected_inheritance.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/example/simple_inheritance.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/inherits/example/super_attribute_overridden_by_child_on_init.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/file/lib/logrotator/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/logger/src/containers/file/lib/logrotator/index.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/merge/example/merge.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/merge/example/merge_2_literal objects.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/merge/example/merge_and_preserve_first.js +0 -0
- /package/framework/{v0.1.1-alpha.18/lib/swig-filters → v0.1.1-alpha.180/lib/routing}/README.md +0 -0
- /package/framework/{v0.1.1-alpha.18/lib/url/README.md → v0.1.1-alpha.180/lib/routing/build.json} +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/url/index.js +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/url/mocks.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/url/routing.json +0 -0
- /package/framework/{v0.1.1-alpha.18 → v0.1.1-alpha.180}/lib/url/test.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
3
|
* This file is part of the gina package.
|
|
4
|
-
* Copyright (c) 2009-
|
|
4
|
+
* Copyright (c) 2009-2023 Rhinostone <contact@gina.io>
|
|
5
5
|
*
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
@@ -19,13 +19,15 @@ var zlib = require('zlib');
|
|
|
19
19
|
// var tls = require('tls');
|
|
20
20
|
// var crypto = require('crypto');
|
|
21
21
|
|
|
22
|
-
var lib = require('./../../lib') ||
|
|
22
|
+
var lib = require('./../../lib') || require.cache[require.resolve('./../../lib')];
|
|
23
23
|
var merge = lib.merge;
|
|
24
24
|
var inherits = lib.inherits;
|
|
25
25
|
var console = lib.logger;
|
|
26
26
|
var Collection = lib.Collection;
|
|
27
|
-
var
|
|
27
|
+
var routingLib = lib.routing;
|
|
28
28
|
var swig = require('swig');
|
|
29
|
+
// Swig 2
|
|
30
|
+
// var swig = require('./../deps/swig-client/swig-2.0.0.min.js');
|
|
29
31
|
var SwigFilters = lib.SwigFilters;
|
|
30
32
|
var statusCodes = requireJSON( _( getPath('gina').core + '/status.codes') );
|
|
31
33
|
|
|
@@ -44,9 +46,9 @@ function SuperController(options) {
|
|
|
44
46
|
|
|
45
47
|
//public
|
|
46
48
|
this.name = 'SuperController';
|
|
47
|
-
this.engine = {};
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
this.engine = {};
|
|
50
|
+
|
|
51
|
+
|
|
50
52
|
var self = this;
|
|
51
53
|
//private
|
|
52
54
|
var local = {
|
|
@@ -68,16 +70,16 @@ function SuperController(options) {
|
|
|
68
70
|
if ( typeof(SuperController.initialized) != 'undefined' ) {
|
|
69
71
|
return getInstance()
|
|
70
72
|
} else {
|
|
71
|
-
|
|
73
|
+
|
|
72
74
|
SuperController.instance = self;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
|
|
76
|
+
|
|
75
77
|
if (local.options) {
|
|
76
78
|
SuperController.instance._options = local.options;
|
|
77
79
|
}
|
|
78
|
-
|
|
80
|
+
|
|
79
81
|
SuperController.initialized = true;
|
|
80
|
-
|
|
82
|
+
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -85,46 +87,64 @@ function SuperController(options) {
|
|
|
85
87
|
local.options = SuperController.instance._options = options;
|
|
86
88
|
// 2022-03-07 Fix for none-developpement environnements (without cache)
|
|
87
89
|
self._options = local.options;
|
|
88
|
-
|
|
90
|
+
|
|
89
91
|
return SuperController.instance;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
var hasViews = function() {
|
|
93
95
|
return ( typeof(local.options.template) != 'undefined' ) ? true : false;
|
|
94
96
|
}
|
|
95
|
-
|
|
97
|
+
|
|
96
98
|
/**
|
|
97
99
|
* isHttp2
|
|
98
100
|
* Returns `true` if server configured for HTTP/2
|
|
99
|
-
*
|
|
101
|
+
*
|
|
100
102
|
* @returns {boolean} isHttp2
|
|
101
103
|
*/
|
|
102
104
|
var isHttp2 = function() {
|
|
103
|
-
var options = local.options;
|
|
105
|
+
var options = local.options;
|
|
104
106
|
var protocolVersion = ~~options.conf.server.protocol.match(/\/(.*)$/)[1].replace(/\.\d+/, '');
|
|
105
107
|
var httpLib = options.conf.server.protocol.match(/^(.*)\//)[1] + ( (protocolVersion >= 2) ? protocolVersion : '' );
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
|
|
109
|
+
|
|
108
110
|
return /http2/.test(httpLib)
|
|
109
111
|
}
|
|
112
|
+
|
|
113
|
+
var headersSent = function(res) {
|
|
114
|
+
var _res = ( typeof(res) != 'undefined' ) ? res : local.res;
|
|
115
|
+
|
|
116
|
+
if ( typeof(_res.headersSent) != 'undefined' ) {
|
|
117
|
+
return _res.headersSent
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
typeof(_res.stream) != 'undefined'
|
|
122
|
+
&& typeof(_res.stream.headersSent) != 'undefined'
|
|
123
|
+
&& _res.stream.headersSent != 'null'
|
|
124
|
+
) {
|
|
125
|
+
return true
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
110
130
|
/**
|
|
111
131
|
* isSecured
|
|
112
132
|
* Returns `true` if server configured to handle a HTTPS exchanges
|
|
113
|
-
*
|
|
133
|
+
*
|
|
114
134
|
* @returns {boolean} isSecured
|
|
115
135
|
*/
|
|
116
136
|
var isSecured = function() {
|
|
117
137
|
return /https/.test(local.options.conf.server.scheme)
|
|
118
138
|
}
|
|
119
|
-
|
|
139
|
+
|
|
120
140
|
this.getRequestObject = function() {
|
|
121
141
|
return local.req;
|
|
122
142
|
}
|
|
123
|
-
|
|
143
|
+
|
|
124
144
|
this.getResponseObject = function() {
|
|
125
145
|
return local.res;
|
|
126
146
|
}
|
|
127
|
-
|
|
147
|
+
|
|
128
148
|
this.getNextCallback = function() {
|
|
129
149
|
return local.next;
|
|
130
150
|
}
|
|
@@ -146,7 +166,7 @@ function SuperController(options) {
|
|
|
146
166
|
local.options = SuperController.instance._options = options;
|
|
147
167
|
local.options.renderingStack = (local.options.renderingStack) ? local.options.renderingStack : [];
|
|
148
168
|
local.options.isRenderingCustomError = (local.options.isRenderingCustomError) ? local.options.isRenderingCustomError : false;
|
|
149
|
-
|
|
169
|
+
|
|
150
170
|
|
|
151
171
|
// N.B.: Avoid setting `page` properties as much as possible from the routing.json
|
|
152
172
|
// It will be easier for the framework if set from the controller.
|
|
@@ -169,12 +189,12 @@ function SuperController(options) {
|
|
|
169
189
|
// var data = { page: { view: { title: "My Title"}}};
|
|
170
190
|
// self.render(data)
|
|
171
191
|
// }
|
|
172
|
-
|
|
192
|
+
|
|
173
193
|
if ( typeof(options.conf.content.routing[options.rule].param) != 'undefined' ) {
|
|
174
194
|
var str = 'page.'
|
|
175
195
|
, p = options.conf.content.routing[options.rule].param
|
|
176
196
|
;
|
|
177
|
-
|
|
197
|
+
|
|
178
198
|
for (var key in p) {
|
|
179
199
|
if ( p.hasOwnProperty(key) && !/^(control)$/.test(key) ) {
|
|
180
200
|
str += key + '.';
|
|
@@ -213,23 +233,23 @@ function SuperController(options) {
|
|
|
213
233
|
, rule = local.options.rule
|
|
214
234
|
, ext = 'html' // by default
|
|
215
235
|
, isWithoutLayout = false // by default
|
|
216
|
-
, namespace = local.options.namespace ||
|
|
236
|
+
, namespace = local.options.namespace || '';
|
|
217
237
|
|
|
218
238
|
|
|
219
239
|
if ( typeof(local.options.template) != 'undefined' && local.options.template ) {
|
|
220
|
-
if (
|
|
221
|
-
typeof(local.options.template.ext) != 'undefined'
|
|
222
|
-
&& local.options.template.ext
|
|
240
|
+
if (
|
|
241
|
+
typeof(local.options.template.ext) != 'undefined'
|
|
242
|
+
&& local.options.template.ext
|
|
223
243
|
&& local.options.template.ext != ''
|
|
224
244
|
) {
|
|
225
245
|
ext = local.options.template.ext
|
|
226
246
|
}
|
|
227
|
-
|
|
247
|
+
|
|
228
248
|
if ( !/\./.test(ext) ) {
|
|
229
249
|
ext = '.' + ext;
|
|
230
250
|
local.options.template.ext = ext
|
|
231
251
|
}
|
|
232
|
-
|
|
252
|
+
|
|
233
253
|
if (
|
|
234
254
|
typeof(local.options.template.layout) == 'undefined'
|
|
235
255
|
|| /^false$/.test(local.options.template.layout)
|
|
@@ -238,27 +258,27 @@ function SuperController(options) {
|
|
|
238
258
|
isWithoutLayout = true;
|
|
239
259
|
}
|
|
240
260
|
}
|
|
241
|
-
|
|
242
|
-
|
|
261
|
+
|
|
262
|
+
|
|
243
263
|
if ( hasViews() ) {
|
|
244
264
|
|
|
245
265
|
if ( typeof(local.options.file) == 'undefined') {
|
|
246
266
|
local.options.file = 'index'
|
|
247
267
|
}
|
|
248
|
-
|
|
268
|
+
|
|
249
269
|
if ( typeof(local.options.isWithoutLayout) == 'undefined' || !isWithoutLayout ) {
|
|
250
270
|
local.options.isWithoutLayout = false;
|
|
251
271
|
}
|
|
252
|
-
|
|
272
|
+
|
|
253
273
|
rule = local.options.rule;
|
|
254
|
-
namespace = local.options.namespace ||
|
|
255
|
-
|
|
256
|
-
|
|
274
|
+
namespace = local.options.namespace || 'default';
|
|
275
|
+
|
|
276
|
+
|
|
257
277
|
set('page.view.file', local.options.file);
|
|
258
278
|
set('page.view.title', rule.replace(new RegExp('@' + options.conf.bundle), ''));
|
|
259
279
|
set('page.view.namespace', namespace);
|
|
260
|
-
}
|
|
261
|
-
|
|
280
|
+
}
|
|
281
|
+
|
|
262
282
|
|
|
263
283
|
var ctx = getContext('gina');
|
|
264
284
|
// new declaration && overrides
|
|
@@ -270,6 +290,8 @@ function SuperController(options) {
|
|
|
270
290
|
"middleware" : ctx.middleware
|
|
271
291
|
};
|
|
272
292
|
|
|
293
|
+
set('page.environment.allocated memory', (require('v8').getHeapStatistics().heap_size_limit / (1024 * 1024 * 1024)).toFixed(2) +' GB');
|
|
294
|
+
|
|
273
295
|
set('page.environment.gina', version.number);
|
|
274
296
|
set('page.environment.gina pid', GINA_PID);
|
|
275
297
|
set('page.environment.nodejs', version.nodejs +' '+ version.platform +' '+ version.arch);
|
|
@@ -277,19 +299,20 @@ function SuperController(options) {
|
|
|
277
299
|
set('page.environment.env', process.env.NODE_ENV);
|
|
278
300
|
set('page.environment.envIsDev', self.isCacheless());
|
|
279
301
|
set('page.environment.date.now', new Date().format("isoDateTime"));
|
|
280
|
-
|
|
281
|
-
|
|
302
|
+
|
|
303
|
+
|
|
282
304
|
var routing = local.options.conf.routing = ctx.config.envConf.routing; // all routes
|
|
283
|
-
set('page.environment.routing',
|
|
305
|
+
set('page.environment.routing', encodeRFC5987ValueChars(JSON.stringify(routing))); // export for GFF
|
|
284
306
|
//reverseRouting
|
|
285
307
|
var reverseRouting = local.options.conf.reverseRouting = ctx.config.envConf.reverseRouting; // all routes
|
|
286
|
-
set('page.environment.reverseRouting',
|
|
287
|
-
|
|
308
|
+
set('page.environment.reverseRouting', encodeRFC5987ValueChars(JSON.stringify(reverseRouting))); // export for GFF
|
|
309
|
+
|
|
288
310
|
var forms = local.options.conf.forms = options.conf.content.forms // all forms
|
|
289
|
-
set('page.environment.forms',
|
|
311
|
+
set('page.environment.forms', encodeRFC5987ValueChars(JSON.stringify(forms))); // export for GFF
|
|
290
312
|
set('page.forms', options.conf.content.forms);
|
|
291
|
-
|
|
313
|
+
|
|
292
314
|
set('page.environment.hostname', ctx.config.envConf[options.conf.bundle][process.env.NODE_ENV].hostname);
|
|
315
|
+
set('page.environment.rootDomain', ctx.config.envConf[options.conf.bundle][process.env.NODE_ENV].rootDomain);
|
|
293
316
|
set('page.environment.webroot', options.conf.server.webroot);
|
|
294
317
|
set('page.environment.bundle', options.conf.bundle);
|
|
295
318
|
set('page.environment.project', options.conf.projectName);
|
|
@@ -298,14 +321,14 @@ function SuperController(options) {
|
|
|
298
321
|
set('page.environment.port', options.conf.server.port);
|
|
299
322
|
set('page.environment.debugPort', options.conf.server.debugPort);
|
|
300
323
|
set('page.environment.pid', process.pid);
|
|
301
|
-
|
|
302
|
-
|
|
324
|
+
|
|
325
|
+
|
|
303
326
|
set('page.view.ext', ext);
|
|
304
327
|
set('page.view.control', action);
|
|
305
328
|
set('page.view.controller', local.options.controller.replace(options.conf.bundlesPath, ''), true);
|
|
306
329
|
if (typeof (local.options.controlRequired) != 'undefined' ) {
|
|
307
330
|
set('page.view.controlRequired', local.options.controlRequired);
|
|
308
|
-
}
|
|
331
|
+
}
|
|
309
332
|
set('page.view.method', local.options.method);
|
|
310
333
|
set('page.view.namespace', namespace); // by default
|
|
311
334
|
set('page.view.url', req.url);
|
|
@@ -314,12 +337,12 @@ function SuperController(options) {
|
|
|
314
337
|
set('page.view.html.properties.mode.javascriptsDeferEnabled', local.options.template.javascriptsDeferEnabled);
|
|
315
338
|
set('page.view.html.properties.mode.routeNameAsFilenameEnabled', local.options.template.routeNameAsFilenameEnabled);
|
|
316
339
|
}
|
|
317
|
-
|
|
318
|
-
|
|
340
|
+
|
|
341
|
+
|
|
319
342
|
var parameters = JSON.clone(req.getParams());
|
|
320
343
|
parameters = merge(parameters, options.conf.content.routing[rule].param);
|
|
321
344
|
// excluding default page properties
|
|
322
|
-
delete parameters[0];
|
|
345
|
+
delete parameters[0];
|
|
323
346
|
delete parameters.file;
|
|
324
347
|
delete parameters.control;
|
|
325
348
|
delete parameters.title;
|
|
@@ -329,7 +352,7 @@ function SuperController(options) {
|
|
|
329
352
|
|
|
330
353
|
set('page.view.route', rule);
|
|
331
354
|
|
|
332
|
-
|
|
355
|
+
|
|
333
356
|
var acceptLanguage = GINA_CULTURE; // by default : language-COUNTRY
|
|
334
357
|
if ( typeof(req.headers['accept-language']) != 'undefined' ) {
|
|
335
358
|
acceptLanguage = req.headers['accept-language']
|
|
@@ -348,8 +371,8 @@ function SuperController(options) {
|
|
|
348
371
|
|
|
349
372
|
try {
|
|
350
373
|
userLocales = locales.findOne({ lang: userLangCode }).content;
|
|
351
|
-
} catch (err) {
|
|
352
|
-
//var defaultRegion = (local.options.conf.content.settings.region) ? local.options.conf.content.settings.region.shortCode
|
|
374
|
+
} catch (err) {
|
|
375
|
+
//var defaultRegion = (local.options.conf.content.settings.region) ? local.options.conf.content.settings.region.shortCode
|
|
353
376
|
console.warn('language code `'+ userLangCode +'` not handled by current locales setup: replacing by default: `'+ local.options.conf.content.settings.region.shortCode +'`');
|
|
354
377
|
userLocales = locales.findOne({ lang: local.options.conf.content.settings.region.shortCode }).content // by default
|
|
355
378
|
}
|
|
@@ -359,7 +382,7 @@ function SuperController(options) {
|
|
|
359
382
|
|
|
360
383
|
// user locale
|
|
361
384
|
options.conf.locale = new Collection(userLocales).findOne({ short: userCountryCode }) || {};
|
|
362
|
-
|
|
385
|
+
|
|
363
386
|
//set('page.date.now', new Date().format("isoDateTime"));
|
|
364
387
|
if ( typeof(options.conf.locale) == 'undefined' || !options.conf.locale ) {
|
|
365
388
|
options.conf.locale = {}
|
|
@@ -370,21 +393,21 @@ function SuperController(options) {
|
|
|
370
393
|
set('page.view.locale', options.conf.locale);
|
|
371
394
|
set('page.view.lang', userCulture);
|
|
372
395
|
}
|
|
373
|
-
|
|
396
|
+
|
|
374
397
|
if ( !getContext('isProxyHost') ) {
|
|
375
398
|
var isProxyHost = ( typeof(req.headers.host) != 'undefined' && local.options.conf.server.scheme +'://'+ req.headers.host != local.options.conf.hostname || typeof(req.headers[':authority']) != 'undefined' && local.options.conf.server.scheme +'://'+ req.headers[':authority'] != local.options.conf.hostname ) ? true : false;
|
|
376
399
|
setContext('isProxyHost', isProxyHost);
|
|
377
400
|
}
|
|
378
|
-
|
|
401
|
+
|
|
379
402
|
//TODO - detect when to use swig
|
|
380
403
|
var dir = null;
|
|
381
404
|
if (local.options.template || self.templates) {
|
|
382
405
|
dir = local.options.template.templates || self.templates;
|
|
383
|
-
|
|
406
|
+
|
|
384
407
|
var swigOptions = {
|
|
385
408
|
autoescape : ( typeof(local.options.autoescape) != 'undefined') ? local.options.autoescape : false,
|
|
386
409
|
// `memory` is no working yet ... advanced rendering setup required
|
|
387
|
-
//cache : (local.options.cacheless) ? false : 'memory'
|
|
410
|
+
// cache : (local.options.cacheless) ? false : 'memory'
|
|
388
411
|
cache : false
|
|
389
412
|
};
|
|
390
413
|
if (dir) {
|
|
@@ -401,11 +424,11 @@ function SuperController(options) {
|
|
|
401
424
|
// preserve the same timezone as the system
|
|
402
425
|
var defaultTZOffset = new Date().getTimezoneOffset();
|
|
403
426
|
swig.setDefaultTZOffset(defaultTZOffset);
|
|
404
|
-
|
|
427
|
+
|
|
405
428
|
self.engine = swig;
|
|
406
429
|
}
|
|
407
430
|
}
|
|
408
|
-
|
|
431
|
+
|
|
409
432
|
this.renderWithoutLayout = function (data, displayToolbar) {
|
|
410
433
|
|
|
411
434
|
// preventing multiple call of self.renderWithoutLayout() when controller is rendering from another required controller
|
|
@@ -414,7 +437,7 @@ function SuperController(options) {
|
|
|
414
437
|
}
|
|
415
438
|
|
|
416
439
|
local.options.isWithoutLayout = true;
|
|
417
|
-
|
|
440
|
+
|
|
418
441
|
self.render(data, displayToolbar);
|
|
419
442
|
}
|
|
420
443
|
|
|
@@ -444,47 +467,52 @@ function SuperController(options) {
|
|
|
444
467
|
) ? true : false;
|
|
445
468
|
if (isRenderingCustomError)
|
|
446
469
|
delete userData.isRenderingCustomError;
|
|
447
|
-
|
|
470
|
+
|
|
448
471
|
var localOptions = (errOptions) ? errOptions : local.options;
|
|
449
472
|
localOptions.renderingStack.push( self.name );
|
|
450
473
|
// preventing multiple call of self.render() when controller is rendering from another required controller
|
|
451
474
|
if ( localOptions.renderingStack.length > 1 && !isRenderingCustomError ) {
|
|
452
475
|
return false
|
|
453
476
|
}
|
|
454
|
-
|
|
455
|
-
|
|
477
|
+
|
|
478
|
+
|
|
456
479
|
var data = null
|
|
457
480
|
, layout = null
|
|
458
481
|
, template = null
|
|
459
482
|
, file = null
|
|
460
483
|
, path = null
|
|
461
484
|
, plugin = null
|
|
462
|
-
, isWithoutLayout = (localOptions.isWithoutLayout) ? true : false
|
|
485
|
+
, isWithoutLayout = (localOptions.isWithoutLayout) ? true : false
|
|
463
486
|
;
|
|
464
|
-
|
|
487
|
+
|
|
465
488
|
localOptions.debugMode = ( typeof(displayToolbar) == 'undefined' ) ? undefined : ( (/true/i.test(displayToolbar)) ? true : false ); // only active for dev env
|
|
466
|
-
|
|
489
|
+
|
|
467
490
|
// specific override
|
|
468
491
|
if (
|
|
469
492
|
self.isCacheless()
|
|
470
|
-
&& typeof(local.req[ local.req.method.toLowerCase() ]) != 'undefined'
|
|
471
|
-
&& typeof(local.req[ local.req.method.toLowerCase() ].debug) != 'undefined'
|
|
493
|
+
&& typeof(local.req[ local.req.method.toLowerCase() ]) != 'undefined'
|
|
494
|
+
&& typeof(local.req[ local.req.method.toLowerCase() ].debug) != 'undefined'
|
|
472
495
|
) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
496
|
+
if ( !/^(true|false)$/i.test(local.req[ local.req.method.toLowerCase() ].debug) ) {
|
|
497
|
+
console.warn('Detected wrong value for `debug`: '+ local.req[ local.req.method.toLowerCase() ].debug);
|
|
498
|
+
console.warn('Switching `debug` to `true` as `cacheless` mode is enabled');
|
|
499
|
+
local.req[ local.req.method.toLowerCase() ].debug = true;
|
|
500
|
+
}
|
|
501
|
+
localOptions.debugMode = ( /^true$/i.test(local.req[ local.req.method.toLowerCase() ].debug) ) ? true : false;
|
|
502
|
+
} else if (
|
|
503
|
+
self.isCacheless()
|
|
476
504
|
&& hasViews()
|
|
477
|
-
&& !isWithoutLayout
|
|
478
|
-
&& localOptions.debugMode == undefined
|
|
505
|
+
&& !isWithoutLayout
|
|
506
|
+
&& localOptions.debugMode == undefined
|
|
479
507
|
) {
|
|
480
508
|
localOptions.debugMode = true;
|
|
481
509
|
} else if ( localOptions.debugMode == undefined ) {
|
|
482
510
|
localOptions.debugMode = self.isCacheless()
|
|
483
511
|
}
|
|
484
|
-
|
|
512
|
+
|
|
485
513
|
try {
|
|
486
514
|
data = getData();
|
|
487
|
-
|
|
515
|
+
|
|
488
516
|
if (!userData) {
|
|
489
517
|
userData = { page: { view: {}}}
|
|
490
518
|
} else if ( userData && !userData['page']) {
|
|
@@ -502,7 +530,7 @@ function SuperController(options) {
|
|
|
502
530
|
if ( isWithoutLayout ) {
|
|
503
531
|
localTemplateConf = JSON.clone(localOptions.template);
|
|
504
532
|
localTemplateConf.javascripts = new Collection(localTemplateConf.javascripts).find({ isCommon: false}, { isCommon: true, name: 'gina' });
|
|
505
|
-
localTemplateConf.stylesheets = new Collection(localTemplateConf.stylesheets).find({ isCommon: false}, { isCommon: true, name: 'gina' });
|
|
533
|
+
localTemplateConf.stylesheets = new Collection(localTemplateConf.stylesheets).find({ isCommon: false}, { isCommon: true, name: 'gina' });
|
|
506
534
|
}
|
|
507
535
|
setResources(localTemplateConf);
|
|
508
536
|
// Allowing file & ext override
|
|
@@ -512,13 +540,13 @@ function SuperController(options) {
|
|
|
512
540
|
) {
|
|
513
541
|
data.page.view.file = localOptions.file = local.req.routing.param.file
|
|
514
542
|
}
|
|
515
|
-
if (
|
|
516
|
-
typeof(local.req.routing.param.ext) != 'undefined'
|
|
543
|
+
if (
|
|
544
|
+
typeof(local.req.routing.param.ext) != 'undefined'
|
|
517
545
|
&& data.page.view.ext !== local.req.routing.param.ext
|
|
518
546
|
) {
|
|
519
547
|
data.page.view.ext = localOptions.template.ext = local.req.routing.param.ext
|
|
520
548
|
}
|
|
521
|
-
|
|
549
|
+
|
|
522
550
|
file = (isRenderingCustomError) ? localOptions.file : data.page.view.file;
|
|
523
551
|
|
|
524
552
|
// pre-compiling variables
|
|
@@ -527,13 +555,13 @@ function SuperController(options) {
|
|
|
527
555
|
if (typeof(data.page.data) == 'undefined' ) {
|
|
528
556
|
data.page.data = {}
|
|
529
557
|
}
|
|
530
|
-
|
|
531
558
|
|
|
532
|
-
|
|
559
|
+
|
|
560
|
+
if (
|
|
533
561
|
!local.options.isRenderingCustomError
|
|
534
|
-
&& typeof(data.page.data.status) != 'undefined'
|
|
535
|
-
&& !/^2/.test(data.page.data.status)
|
|
536
|
-
&& typeof(data.page.data.error) != 'undefined'
|
|
562
|
+
&& typeof(data.page.data.status) != 'undefined'
|
|
563
|
+
&& !/^2/.test(data.page.data.status)
|
|
564
|
+
&& typeof(data.page.data.error) != 'undefined'
|
|
537
565
|
) {
|
|
538
566
|
var statusCode = localOptions.conf.server.coreConfiguration.statusCodes;
|
|
539
567
|
var errorObject = {
|
|
@@ -553,11 +581,16 @@ function SuperController(options) {
|
|
|
553
581
|
// making path thru [namespace &] file
|
|
554
582
|
if ( typeof(localOptions.namespace) != 'undefined' && localOptions.namespace ) {
|
|
555
583
|
// excepted for custom paths
|
|
556
|
-
if ( !/^(\.|\/|\\)/.test(file) )
|
|
584
|
+
if ( !/^(\.|\/|\\)/.test(file) ) {
|
|
585
|
+
var _ext = data.page.view.ext;
|
|
586
|
+
console.warn('file `'+ file +'` used in routing `'+ localOptions.rule +'` does not respect gina naming convention ! You should rename the file `'+ file + _ext +'` to `'+ ''+ file.replace(localOptions.namespace+'-', '') + _ext +'`');
|
|
587
|
+
console.warn('The reason you are getting this message is because your filename begeins with `<namespace>-`\n If you don\‘t want to rename, use template path like ./../'+ localOptions.namespace +'/'+file);
|
|
557
588
|
file = ''+ file.replace(localOptions.namespace+'-', '');
|
|
558
|
-
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
|
|
559
592
|
// means that rule name === namespace -> pointing to root namespace dir
|
|
560
|
-
if (!file ||
|
|
593
|
+
if (!file || file === localOptions.namespace) {
|
|
561
594
|
file = 'index'
|
|
562
595
|
}
|
|
563
596
|
path = (isRenderingCustomError) ? _(file) : _(localOptions.template.html +'/'+ localOptions.namespace + '/' + file)
|
|
@@ -593,14 +626,14 @@ function SuperController(options) {
|
|
|
593
626
|
dic['page.'+d] = data.page[d]
|
|
594
627
|
}
|
|
595
628
|
|
|
596
|
-
|
|
629
|
+
|
|
597
630
|
|
|
598
631
|
// please, do not start with a slashe when including...
|
|
599
632
|
// ex.:
|
|
600
633
|
// /html/inc/_partial.html (BAD)
|
|
601
634
|
// html/inc/_partial.html (GOOD)
|
|
602
635
|
// ./html/namespace/page.html (GOOD)
|
|
603
|
-
|
|
636
|
+
|
|
604
637
|
if ( !fs.existsSync(path) ) {
|
|
605
638
|
msg = 'could not open "'+ path +'"' +
|
|
606
639
|
'\n1) The requested file does not exists in your templates/html (check your template directory). Can you find: '+path +
|
|
@@ -614,32 +647,32 @@ function SuperController(options) {
|
|
|
614
647
|
self.throwError(err);
|
|
615
648
|
return;
|
|
616
649
|
}
|
|
617
|
-
|
|
618
|
-
var isProxyHost = (
|
|
619
|
-
typeof(local.req.headers.host) != 'undefined'
|
|
620
|
-
&& localOptions.conf.server.scheme +'://'+ local.req.headers.host != localOptions.conf.hostname
|
|
621
|
-
|| typeof(local.req.headers[':authority']) != 'undefined'
|
|
622
|
-
&& localOptions.conf.server.scheme +'://'+ local.req.headers[':authority'] != localOptions.conf.hostname
|
|
650
|
+
|
|
651
|
+
var isProxyHost = (
|
|
652
|
+
typeof(local.req.headers.host) != 'undefined'
|
|
653
|
+
&& localOptions.conf.server.scheme +'://'+ local.req.headers.host != localOptions.conf.hostname
|
|
654
|
+
|| typeof(local.req.headers[':authority']) != 'undefined'
|
|
655
|
+
&& localOptions.conf.server.scheme +'://'+ local.req.headers[':authority'] != localOptions.conf.hostname
|
|
623
656
|
) ? true : false;
|
|
624
|
-
// setup swig default filters
|
|
657
|
+
// setup swig default filters
|
|
625
658
|
var filters = SwigFilters({
|
|
626
659
|
options : JSON.clone(localOptions),
|
|
627
660
|
isProxyHost : isProxyHost,
|
|
628
661
|
throwError : self.throwError,
|
|
629
662
|
req : local.req,
|
|
630
|
-
res : local.res
|
|
663
|
+
res : local.res
|
|
631
664
|
});
|
|
632
665
|
|
|
633
666
|
try {
|
|
634
|
-
|
|
667
|
+
|
|
635
668
|
// Extends default `length` filter
|
|
636
669
|
swig.setFilter('length', filters.length);
|
|
637
670
|
|
|
638
|
-
|
|
671
|
+
|
|
639
672
|
|
|
640
673
|
// Allows you to get a bundle web root
|
|
641
674
|
swig.setFilter('getWebroot', filters.getWebroot);
|
|
642
|
-
|
|
675
|
+
|
|
643
676
|
swig.setFilter('getUrl', filters.getUrl);
|
|
644
677
|
|
|
645
678
|
} catch (err) {
|
|
@@ -651,10 +684,10 @@ function SuperController(options) {
|
|
|
651
684
|
self.throwError(local.res, 500, new Error('template compilation exception encoutered: [ '+path+' ]\n'+(err.stack||err.message)));
|
|
652
685
|
return;
|
|
653
686
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
var layoutPath = null
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
var layoutPath = null
|
|
658
691
|
, assets = null
|
|
659
692
|
, mapping = null
|
|
660
693
|
, XHRData = null
|
|
@@ -665,26 +698,26 @@ function SuperController(options) {
|
|
|
665
698
|
, isWithSwigLayout = null
|
|
666
699
|
, isUsingGinaLayout = (!isWithoutLayout && typeof(localOptions.template.layout) != 'undefined' && fs.existsSync(local.options.template.layout)) ? true : false
|
|
667
700
|
;
|
|
668
|
-
|
|
669
|
-
if ( isWithoutLayout ||
|
|
701
|
+
|
|
702
|
+
if ( isWithoutLayout || isUsingGinaLayout ) {
|
|
670
703
|
layoutPath = (isWithoutLayout) ? localOptions.template.noLayout : localOptions.template.layout;
|
|
671
704
|
// user layout override
|
|
672
|
-
if (
|
|
705
|
+
if ( isUsingGinaLayout && !isWithoutLayout ) {
|
|
673
706
|
layoutPath = localOptions.template.layout;
|
|
674
|
-
}
|
|
707
|
+
}
|
|
675
708
|
if (isWithoutLayout) {
|
|
676
709
|
data.page.view.layout = layoutPath;
|
|
677
|
-
}
|
|
710
|
+
}
|
|
678
711
|
} else { // without layout case
|
|
679
|
-
|
|
712
|
+
|
|
680
713
|
// by default
|
|
681
714
|
layoutPath = localOptions.template.layout;
|
|
682
715
|
if ( !/^\//.test(layoutPath)) {
|
|
683
716
|
layoutPath = localOptions.template.templates +'/'+ layoutPath;
|
|
684
717
|
}
|
|
685
718
|
// default layout
|
|
686
|
-
if (
|
|
687
|
-
!isWithoutLayout && !fs.existsSync(layoutPath) && layoutPath == localOptions.template.templates +'/index.html'
|
|
719
|
+
if (
|
|
720
|
+
!isWithoutLayout && !fs.existsSync(layoutPath) && layoutPath == localOptions.template.templates +'/index.html'
|
|
688
721
|
) {
|
|
689
722
|
console.warn('Layout '+ local.options.template.layout +' not found, replacing with `nolayout`: '+ localOptions.template.noLayout);
|
|
690
723
|
layoutPath = localOptions.template.noLayout
|
|
@@ -703,57 +736,57 @@ function SuperController(options) {
|
|
|
703
736
|
self.throwError(err);
|
|
704
737
|
return;
|
|
705
738
|
}
|
|
706
|
-
|
|
739
|
+
|
|
707
740
|
}
|
|
708
|
-
|
|
709
|
-
|
|
741
|
+
|
|
742
|
+
|
|
710
743
|
var isLoadingPartial = false;
|
|
711
|
-
try {
|
|
744
|
+
try {
|
|
712
745
|
assets = {assets:"${assets}"};
|
|
713
|
-
|
|
746
|
+
|
|
714
747
|
/**
|
|
715
748
|
* retrieve template & layout
|
|
716
|
-
* */
|
|
717
|
-
var tpl = null;
|
|
749
|
+
* */
|
|
750
|
+
var tpl = null;
|
|
718
751
|
// tpl = fs.readFileSync(path).toString();
|
|
719
|
-
// layout = fs.readFileSync(layoutPath).toString();
|
|
720
|
-
|
|
752
|
+
// layout = fs.readFileSync(layoutPath).toString();
|
|
753
|
+
|
|
721
754
|
await Promise.all([
|
|
722
|
-
|
|
723
|
-
|
|
755
|
+
readFile(layoutPath),
|
|
756
|
+
readFile(path)
|
|
724
757
|
])
|
|
725
|
-
.then(([_layout, _tpl]) => {
|
|
758
|
+
.then(([_layout, _tpl]) => {
|
|
726
759
|
layout = _layout.toString();
|
|
727
760
|
tpl = _tpl.toString();
|
|
728
761
|
})
|
|
729
762
|
.catch(error => {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
763
|
+
console.error(error.message);
|
|
764
|
+
return;
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
|
|
735
768
|
// mappin conf
|
|
736
769
|
mapping = { filename: path };
|
|
737
770
|
if (isRenderingCustomError) {
|
|
738
771
|
// TODO - Test if there is a block call `gina-error` in the layout & replace block name from tpl
|
|
739
|
-
|
|
772
|
+
|
|
740
773
|
if ( !/\{\%(\s+extends|extends)/.test(tpl) ) {
|
|
741
774
|
tpl = "\n{% extends '"+ layoutPath +"' %}\n" + tpl;
|
|
742
775
|
}
|
|
743
776
|
if (!/\{\% block content/.test(tpl)) {
|
|
744
777
|
// TODO - test if lyout has <body>
|
|
745
778
|
tpl = '{% block content %}<p>If you view this message you didn’t define a content block in your template.</p>{% endblock %}' + tpl;
|
|
746
|
-
}
|
|
747
|
-
|
|
779
|
+
}
|
|
780
|
+
|
|
748
781
|
tpl = tpl.replace(/\{\{ page\.content \}\}/g, '');
|
|
749
782
|
}
|
|
750
|
-
|
|
783
|
+
|
|
751
784
|
if ( isWithoutLayout || isWithSwigLayout) {
|
|
752
|
-
layout = tpl;
|
|
785
|
+
layout = tpl;
|
|
753
786
|
} else if (isUsingGinaLayout) {
|
|
754
787
|
mapping = { filename: path };
|
|
755
788
|
if ( /(\{\{|\{\{\s+)page\.content/.test(layout) ) {
|
|
756
|
-
|
|
789
|
+
|
|
757
790
|
if ( /\{\%(\s+extends|extends)/.test(tpl) ) {
|
|
758
791
|
err = new Error('You cannot use at the same time `page.content` in your layout `'+ layoutPath +'` while calling `extends` from your page or content `'+ path +'`. You have to choose one or the other');
|
|
759
792
|
self.throwError(local.res, 500, err);
|
|
@@ -761,9 +794,9 @@ function SuperController(options) {
|
|
|
761
794
|
}
|
|
762
795
|
layout = layout.replace('{{ page.content }}', tpl);
|
|
763
796
|
} else {
|
|
764
|
-
layout = layout.replace(/\<\/body\>/i, '\t'+tpl+'\n</body>');
|
|
797
|
+
layout = layout.replace(/\<\/body\>/i, '\t'+tpl+'\n</body>');
|
|
765
798
|
}
|
|
766
|
-
|
|
799
|
+
|
|
767
800
|
} else {
|
|
768
801
|
tpl = tpl.replace('{{ page.view.layout }}', data.page.view.layout);
|
|
769
802
|
if (/\<\/body\>/i.test(layout)) {
|
|
@@ -771,178 +804,201 @@ function SuperController(options) {
|
|
|
771
804
|
}
|
|
772
805
|
else {
|
|
773
806
|
layout += tpl;
|
|
774
|
-
}
|
|
807
|
+
}
|
|
775
808
|
}
|
|
776
|
-
|
|
809
|
+
|
|
777
810
|
// precompilation needed in case of `extends` or in order to display the toolbar
|
|
778
|
-
if ( hasViews() && self.isCacheless() || /\{\%(\s+extends|extends)/.test(layout) ) {
|
|
811
|
+
if ( hasViews() && self.isCacheless() || /\{\%(\s+extends|extends)/.test(layout) ) {
|
|
779
812
|
layout = swig.compile(layout, mapping)(data);
|
|
780
813
|
}
|
|
781
|
-
//dic['page.content'] = layout;
|
|
782
|
-
|
|
814
|
+
//dic['page.content'] = layout;
|
|
815
|
+
|
|
783
816
|
} catch(err) {
|
|
784
817
|
err.stack = 'Exception, bad syntax or undefined data found: start investigating in '+ mapping.filename +'\n' + err.stack;
|
|
785
818
|
self.throwError(local.res, 500, err);
|
|
786
819
|
return
|
|
787
820
|
}
|
|
788
|
-
|
|
789
|
-
isLoadingPartial = (
|
|
790
|
-
!/\<html/i.test(layout)
|
|
791
|
-
|| !/\<head/i.test(layout)
|
|
792
|
-
|| !/\<body/i.test(layout)
|
|
821
|
+
|
|
822
|
+
isLoadingPartial = (
|
|
823
|
+
!/\<html/i.test(layout)
|
|
824
|
+
|| !/\<head/i.test(layout)
|
|
825
|
+
|| !/\<body/i.test(layout)
|
|
793
826
|
) ? true : false;
|
|
794
|
-
|
|
827
|
+
|
|
795
828
|
// if (isLoadingPartial) {
|
|
796
829
|
// console.warn('----------------> loading partial `'+ path);
|
|
797
830
|
// }
|
|
798
|
-
|
|
799
|
-
isDeferModeEnabled = localOptions.template.javascriptsDeferEnabled || localOptions.conf.content.templates._common.javascriptsDeferEnabled || false;
|
|
800
|
-
|
|
831
|
+
|
|
832
|
+
isDeferModeEnabled = localOptions.template.javascriptsDeferEnabled || localOptions.conf.content.templates._common.javascriptsDeferEnabled || false;
|
|
833
|
+
|
|
801
834
|
// iframe case - without HTML TAG
|
|
802
835
|
if (!self.isXMLRequest() && !/\<html/.test(layout) ) {
|
|
803
836
|
layout = '<html>\n\t<head></head>\n\t<body class="gina-iframe-body">\n\t\t'+ layout +'\n\t</body>\n</html>';
|
|
804
|
-
}
|
|
805
|
-
|
|
837
|
+
}
|
|
838
|
+
|
|
806
839
|
// adding stylesheets
|
|
807
840
|
if (!isWithoutLayout && data.page.view.stylesheets && !/\{\{\s+(page\.view\.stylesheets)\s+\}\}/.test(layout) ) {
|
|
808
841
|
layout = layout.replace(/\<\/head\>/i, '\n\t{{ page.view.stylesheets }}\n</head>')
|
|
809
842
|
}
|
|
810
|
-
|
|
843
|
+
|
|
811
844
|
if (hasViews() && isWithoutLayout) {
|
|
812
845
|
// $.getScript(...)
|
|
813
846
|
//var isProxyHost = ( typeof(local.req.headers.host) != 'undefined' && localOptions.conf.server.scheme +'://'+ local.req.headers.host != localOptions.conf.hostname || typeof(local.req.headers[':authority']) != 'undefined' && localOptions.conf.server.scheme +'://'+ local.req.headers[':authority'] != localOptions.conf.hostname ) ? true : false;
|
|
814
847
|
//var hostname = (isProxyHost) ? localOptions.conf.hostname.replace(/\:\d+$/, '') : localOptions.conf.hostname;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
818
851
|
var scripts = data.page.view.scripts;
|
|
819
852
|
scripts = scripts.replace(/\s+\<script/g, '\n<script');
|
|
820
|
-
|
|
853
|
+
|
|
821
854
|
if (!isProxyHost) {
|
|
822
855
|
var webroot = data.page.environment.webroot;
|
|
823
856
|
scripts = scripts.replace(/src\=\"\/(.*)\"/g, 'src="'+ webroot +'$1"');
|
|
824
857
|
//stylesheets = stylesheets.replace(/href\=\"\/(.*)\"/g, 'href="'+ webroot +'$1"')
|
|
825
858
|
}
|
|
826
|
-
|
|
859
|
+
|
|
827
860
|
// iframe case - without HTML TAG
|
|
828
|
-
if (self.isXMLRequest() || !/\<html/.test(layout) ) {
|
|
829
|
-
layout += scripts;
|
|
830
|
-
//layout += stylesheets;
|
|
831
|
-
}
|
|
832
|
-
|
|
861
|
+
if (self.isXMLRequest() || !/\<html/.test(layout) ) {
|
|
862
|
+
layout += scripts;
|
|
863
|
+
//layout += stylesheets;
|
|
864
|
+
}
|
|
865
|
+
|
|
833
866
|
}
|
|
834
867
|
|
|
835
868
|
// adding plugins
|
|
836
|
-
|
|
837
|
-
|
|
869
|
+
// means that we don't want GFF context or we already have it loaded
|
|
870
|
+
viewInfos = JSON.clone(data.page.view);
|
|
871
|
+
if ( !isWithoutLayout )
|
|
872
|
+
viewInfos.assets = assets;
|
|
873
|
+
|
|
838
874
|
if (
|
|
839
|
-
hasViews() && self.isCacheless() && !isWithoutLayout
|
|
840
|
-
&& localOptions.debugMode
|
|
841
|
-
||
|
|
842
|
-
hasViews() && self.isCacheless() && !isWithoutLayout
|
|
843
|
-
&& typeof(localOptions.debugMode) == 'undefined'
|
|
844
|
-
||
|
|
845
|
-
hasViews() && localOptions.debugMode
|
|
875
|
+
hasViews() && self.isCacheless() && !isWithoutLayout
|
|
876
|
+
&& localOptions.debugMode
|
|
877
|
+
||
|
|
878
|
+
hasViews() && self.isCacheless() && !isWithoutLayout
|
|
879
|
+
&& typeof(localOptions.debugMode) == 'undefined'
|
|
880
|
+
||
|
|
881
|
+
hasViews() && localOptions.debugMode
|
|
846
882
|
) {
|
|
847
883
|
|
|
848
884
|
layout = ''
|
|
885
|
+
// + '{%- set ginaDataInspector = JSON.clone(page) -%}'
|
|
849
886
|
+ '{%- set ginaDataInspector = JSON.clone(page) -%}'
|
|
887
|
+
// + '{%- set ginaDataInspector = { view: {}, environment: { routing: {}}} -%}'
|
|
850
888
|
+ '{%- set ginaDataInspector.view.assets = {} -%}'
|
|
851
889
|
+ '{%- set ginaDataInspector.view.scripts = "ignored-by-toolbar" -%}'
|
|
852
890
|
+ '{%- set ginaDataInspector.view.stylesheets = "ignored-by-toolbar" -%}'
|
|
853
891
|
+ layout
|
|
854
892
|
;
|
|
855
|
-
|
|
893
|
+
|
|
856
894
|
plugin = '\t'
|
|
857
895
|
+ '{# Gina Toolbar #}'
|
|
858
896
|
+ '{%- set userDataInspector = JSON.clone(page) -%}'
|
|
897
|
+
// + '{%- set userDataInspector = { view: {}, environment: { routing: {}}} -%}'
|
|
859
898
|
+ '{%- set userDataInspector.view.scripts = "ignored-by-toolbar" -%}'
|
|
860
899
|
+ '{%- set userDataInspector.view.stylesheets = "ignored-by-toolbar" -%}'
|
|
861
900
|
+ '{%- set userDataInspector.view.assets = '+ JSON.stringify(assets) +' -%}'
|
|
862
|
-
+ '{%- include "'+ getPath('gina').core +'/asset/
|
|
863
|
-
+ '{# END Gina Toolbar #}'
|
|
901
|
+
+ '{%- include "'+ getPath('gina').core +'/asset/plugin/dist/vendor/gina/html/toolbar.html" with { gina: ginaDataInspector, user: userDataInspector } -%}'// jshint ignore:line
|
|
902
|
+
+ '{# END Gina Toolbar #}'
|
|
864
903
|
;
|
|
865
|
-
|
|
904
|
+
|
|
866
905
|
|
|
867
906
|
if (isWithoutLayout && localOptions.debugMode || localOptions.debugMode ) {
|
|
868
907
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
908
|
+
if (self.isXMLRequest()) {
|
|
909
|
+
XHRData = '\t<input type="hidden" id="gina-without-layout-xhr-data" value="'+ encodeRFC5987ValueChars(JSON.stringify(data.page.data)) +'">\n\r';
|
|
910
|
+
XHRView = '\n<input type="hidden" id="gina-without-layout-xhr-view" value="'+ encodeRFC5987ValueChars(JSON.stringify(viewInfos)) +'">';
|
|
911
|
+
if ( /<\/body>/i.test(layout) ) {
|
|
912
|
+
layout = layout.replace(/<\/body>/i, XHRData + XHRView + '\n\t</body>');
|
|
913
|
+
} else {
|
|
914
|
+
// Popin case
|
|
915
|
+
// Fix added on 2023-01-25
|
|
916
|
+
layout += XHRData + XHRView + '\n\t'
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
|
|
872
921
|
}
|
|
873
|
-
|
|
922
|
+
|
|
874
923
|
if (self.isCacheless() || localOptions.debugMode ) {
|
|
875
924
|
layout = layout.replace(/<\/body>/i, plugin + '\n\t</body>');
|
|
876
925
|
}
|
|
877
|
-
|
|
926
|
+
|
|
878
927
|
// adding javascripts
|
|
879
|
-
layout.replace('{{ page.view.scripts }}', '');
|
|
928
|
+
layout.replace('{{ page.view.scripts }}', '');
|
|
880
929
|
// placed in the HEAD excepted when rendering a partial or when `isDeferModeEnabled` == true
|
|
881
930
|
if (isLoadingPartial) {
|
|
882
931
|
layout += '\t{{ page.view.scripts }}';
|
|
883
932
|
} else {
|
|
884
933
|
if ( isDeferModeEnabled ) {
|
|
885
934
|
layout = layout.replace(/\<\/head\>/i, '\t{{ page.view.scripts }}\n\t</head>');
|
|
886
|
-
} else { // placed in the BODY
|
|
935
|
+
} else { // placed in the BODY
|
|
887
936
|
layout = layout.replace(/\<\/body\>/i, '\t{{ page.view.scripts }}\n</body>');
|
|
888
937
|
}
|
|
889
938
|
}
|
|
890
|
-
|
|
939
|
+
|
|
891
940
|
// ginaLoader cannot be deferred
|
|
892
941
|
if ( !localOptions.template.javascriptsExcluded || localOptions.template.javascriptsExcluded != '**' ) {
|
|
893
|
-
layout = layout.replace(/\<\/head\>/i, '\t'+ localOptions.template.ginaLoader +'\n</head>');
|
|
942
|
+
layout = layout.replace(/\<\/head\>/i, '\t'+ localOptions.template.ginaLoader +'\n</head>');
|
|
894
943
|
}
|
|
895
944
|
|
|
896
945
|
} else if ( hasViews() && self.isCacheless() && self.isXMLRequest() ) {
|
|
897
|
-
|
|
898
|
-
if (isWithoutLayout) {
|
|
946
|
+
|
|
947
|
+
if (isWithoutLayout) {
|
|
899
948
|
delete data.page.view.scripts;
|
|
900
|
-
delete data.page.view.stylesheets;
|
|
949
|
+
delete data.page.view.stylesheets;
|
|
901
950
|
}
|
|
902
951
|
// means that we don't want GFF context or we already have it loaded
|
|
903
|
-
viewInfos = JSON.clone(data.page.view);
|
|
904
|
-
if ( !isWithoutLayout )
|
|
905
|
-
|
|
952
|
+
// viewInfos = JSON.clone(data.page.view);
|
|
953
|
+
// if ( !isWithoutLayout )
|
|
954
|
+
// viewInfos.assets = assets;
|
|
906
955
|
|
|
907
|
-
XHRData = '\n<input type="hidden" id="gina-without-layout-xhr-data" value="'+ encodeURIComponent(JSON.stringify(data.page.data)) +'">';
|
|
908
|
-
XHRView = '\n<input type="hidden" id="gina-without-layout-xhr-view" value="'+ encodeURIComponent(JSON.stringify(viewInfos)) +'">';
|
|
909
956
|
|
|
957
|
+
XHRData = '\n<input type="hidden" id="gina-without-layout-xhr-data" value="'+ encodeRFC5987ValueChars(JSON.stringify(data.page.data)) +'">';
|
|
958
|
+
XHRView = '\n<input type="hidden" id="gina-without-layout-xhr-view" value="'+ encodeRFC5987ValueChars(JSON.stringify(viewInfos)) +'">';
|
|
959
|
+
if ( /<\/body>/i.test(layout) ) {
|
|
960
|
+
layout = layout.replace(/<\/body>/i, XHRData + XHRView + '\n\t</body>');
|
|
961
|
+
} else {
|
|
962
|
+
// Popin case
|
|
963
|
+
// Fix added on 2023-01-25
|
|
964
|
+
layout += XHRData + XHRView + '\n\t'
|
|
965
|
+
}
|
|
910
966
|
|
|
911
|
-
layout += XHRData + XHRView;
|
|
967
|
+
// layout += XHRData + XHRView;
|
|
912
968
|
|
|
913
969
|
} else { // other envs like prod ...
|
|
914
|
-
|
|
970
|
+
|
|
915
971
|
// adding javascripts
|
|
916
972
|
// cleanup first
|
|
917
|
-
layout.replace('{{ page.view.scripts }}', '');
|
|
973
|
+
layout.replace('{{ page.view.scripts }}', '');
|
|
918
974
|
// placed in the HEAD excepted when rendering a partial or when `isDeferModeEnabled` == true
|
|
919
975
|
// if (isLoadingPartial) {
|
|
920
976
|
// layout += '\t{{ page.view.scripts }}';
|
|
921
977
|
// } else {
|
|
922
978
|
// if ( isDeferModeEnabled ) {
|
|
923
979
|
// layout = layout.replace(/\<\/head\>/i, '\t{{ page.view.scripts }}\n\t</head>');
|
|
924
|
-
// } else { // placed in the BODY
|
|
980
|
+
// } else { // placed in the BODY
|
|
925
981
|
// layout = layout.replace(/\<\/body\>/i, '\t{{ page.view.scripts }}\n</body>');
|
|
926
982
|
// }
|
|
927
983
|
// }
|
|
928
|
-
|
|
984
|
+
|
|
929
985
|
// // ginaLoader cannot be deferred
|
|
930
986
|
// if ( !localOptions.template.javascriptsExcluded || localOptions.template.javascriptsExcluded != '**' ) {
|
|
931
|
-
// layout = layout.replace(/\<\/head\>/i, '\t'+ localOptions.template.ginaLoader +'\n</head>');
|
|
987
|
+
// layout = layout.replace(/\<\/head\>/i, '\t'+ localOptions.template.ginaLoader +'\n</head>');
|
|
932
988
|
// }
|
|
933
|
-
|
|
989
|
+
|
|
934
990
|
// adding javascripts
|
|
935
991
|
layout.replace('{{ page.view.scripts }}', '');
|
|
936
|
-
if (isLoadingPartial) {
|
|
992
|
+
if (isLoadingPartial) {
|
|
937
993
|
layout += '\t{{ page.view.scripts }}\n';
|
|
938
994
|
if ( !localOptions.template.javascriptsExcluded || localOptions.template.javascriptsExcluded != '**' ) {
|
|
939
995
|
layout += '\t'+ localOptions.template.ginaLoader +'\n';
|
|
940
996
|
}
|
|
941
997
|
} else {
|
|
942
|
-
if ( isDeferModeEnabled && /\<\/head\>/i.test(layout) ) { // placed in the HEAD
|
|
998
|
+
if ( isDeferModeEnabled && /\<\/head\>/i.test(layout) ) { // placed in the HEAD
|
|
943
999
|
layout = layout.replace(/\<\/head\>/i, '\t{{ page.view.scripts }}\n\t</head>');
|
|
944
|
-
|
|
945
|
-
} else { // placed in the BODY
|
|
1000
|
+
|
|
1001
|
+
} else { // placed in the BODY
|
|
946
1002
|
layout = layout.replace(/\<\/body\>/i, '\t{{ page.view.scripts }}\n</body>');
|
|
947
1003
|
}
|
|
948
1004
|
// ginaLoader cannot be deferred
|
|
@@ -951,20 +1007,20 @@ function SuperController(options) {
|
|
|
951
1007
|
}
|
|
952
1008
|
}
|
|
953
1009
|
}
|
|
954
|
-
|
|
955
|
-
|
|
1010
|
+
|
|
1011
|
+
|
|
956
1012
|
layout = whisper(dic, layout, /\{{ ([a-zA-Z.]+) \}}/g );
|
|
957
1013
|
dic['page.content'] = layout;
|
|
958
1014
|
/**
|
|
959
1015
|
// special case for template without layout in debug mode - dev only
|
|
960
1016
|
if ( hasViews() && localOptions.debugMode && self.isCacheless() && !/\{\# Gina Toolbar \#\}/.test(layout) ) {
|
|
961
|
-
try {
|
|
962
|
-
|
|
963
|
-
layout = layout.replace(/<\/body>/i, plugin + '\n\t</body>');
|
|
1017
|
+
try {
|
|
1018
|
+
|
|
1019
|
+
layout = layout.replace(/<\/body>/i, plugin + '\n\t</body>');
|
|
964
1020
|
layout = whisper(dic, layout, /\{{ ([a-zA-Z.]+) \}}/g );
|
|
965
1021
|
//swig.invalidateCache();
|
|
966
1022
|
layout = swig.compile(layout, mapping)(data);
|
|
967
|
-
|
|
1023
|
+
|
|
968
1024
|
|
|
969
1025
|
} catch (err) {
|
|
970
1026
|
filename = localOptions.template.html;
|
|
@@ -972,7 +1028,7 @@ function SuperController(options) {
|
|
|
972
1028
|
self.throwError(local.res, 500, new Error('Compilation error encountered while trying to process template `'+ filename + '`\n'+(err.stack||err.message)));
|
|
973
1029
|
return;
|
|
974
1030
|
}
|
|
975
|
-
}
|
|
1031
|
+
}
|
|
976
1032
|
else if (hasViews() && localOptions.debugMode && self.isCacheless()) {
|
|
977
1033
|
try {
|
|
978
1034
|
//layout = whisper(dic, layout, /\{{ ([a-zA-Z.]+) \}}/g );
|
|
@@ -983,11 +1039,12 @@ function SuperController(options) {
|
|
|
983
1039
|
self.throwError(local.res, 500, new Error('Compilation error encountered while trying to process template `'+ filename + '`\n'+(err.stack||err.message)));
|
|
984
1040
|
return;
|
|
985
1041
|
}
|
|
986
|
-
}
|
|
987
|
-
*/
|
|
988
|
-
|
|
1042
|
+
}
|
|
1043
|
+
*/
|
|
1044
|
+
|
|
989
1045
|
|
|
990
|
-
if ( !local.res.headersSent ) {
|
|
1046
|
+
// if ( !local.res.headersSent ) {
|
|
1047
|
+
if ( !headersSent() ) {
|
|
991
1048
|
local.res.statusCode = ( typeof(localOptions.conf.server.coreConfiguration.statusCodes[data.page.data.status]) != 'undefined' ) ? data.page.data.status : 200; // by default
|
|
992
1049
|
//catching errors
|
|
993
1050
|
if (
|
|
@@ -1004,62 +1061,63 @@ function SuperController(options) {
|
|
|
1004
1061
|
}
|
|
1005
1062
|
|
|
1006
1063
|
local.res.setHeader('content-type', localOptions.conf.server.coreConfiguration.mime['html'] + '; charset='+ localOptions.conf.encoding );
|
|
1007
|
-
|
|
1064
|
+
|
|
1008
1065
|
try {
|
|
1009
|
-
|
|
1066
|
+
|
|
1010
1067
|
// escape special chars
|
|
1011
1068
|
var blacklistRe = new RegExp('[\<\>]', 'g');
|
|
1012
1069
|
// DO NOT REPLACE IT BY JSON.clone() !!!!
|
|
1013
|
-
|
|
1070
|
+
|
|
1014
1071
|
data.page.data = JSON.parse(JSON.stringify(data.page.data).replace(blacklistRe, '\$&'));
|
|
1015
|
-
|
|
1072
|
+
|
|
1016
1073
|
} catch (err) {
|
|
1017
1074
|
filename = localOptions.template.html;
|
|
1018
1075
|
filename += ( typeof(data.page.view.namespace) != 'undefined' && data.page.view.namespace != '' && new RegExp('^' + data.page.view.namespace +'-').test(data.page.view.file) ) ? '/' + data.page.view.namespace + data.page.view.file.split(data.page.view.namespace +'-').join('/') + ( (data.page.view.ext != '') ? data.page.view.ext: '' ) : '/' + data.page.view.file+ ( (data.page.view.ext != '') ? data.page.view.ext: '' );
|
|
1019
1076
|
self.throwError(local.res, 500, new Error('Controller::render(...) compilation error encountered while trying to process template `'+ filename + '`\n' + (err.stack||err.message||err) ));
|
|
1020
1077
|
return;
|
|
1021
1078
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1079
|
+
|
|
1080
|
+
|
|
1024
1081
|
// Only available for http/2.0 for now
|
|
1025
1082
|
if ( !self.isXMLRequest() && /http\/2/.test(localOptions.conf.server.protocol) ) {
|
|
1026
1083
|
try {
|
|
1027
|
-
// TODO - button in toolbar to empty url assets cache
|
|
1084
|
+
// TODO - button in toolbar to empty url assets cache
|
|
1028
1085
|
if ( /** self.isCacheless() ||*/ typeof(localOptions.template.assets) == 'undefined' || typeof(localOptions.template.assets[local.req.url]) == 'undefined' ) {
|
|
1029
1086
|
// assets string -> object
|
|
1030
1087
|
//assets = self.serverInstance.getAssets(localOptions.conf, layout.toString(), swig, data);
|
|
1031
1088
|
assets = self.serverInstance.getAssets(localOptions.conf, layout, swig, data);
|
|
1032
1089
|
localOptions.template.assets = JSON.parse(assets);
|
|
1033
1090
|
}
|
|
1034
|
-
|
|
1091
|
+
|
|
1035
1092
|
// only for toolbar - TODO hasToolbar()
|
|
1036
1093
|
if (
|
|
1037
1094
|
self.isCacheless() && hasViews() && !isWithoutLayout
|
|
1038
1095
|
|| hasViews() && localOptions.debugMode
|
|
1039
|
-
|| self.isCacheless() && hasViews() && self.isXMLRequest()
|
|
1040
|
-
) {
|
|
1041
|
-
layout = layout.replace('{"assets":"${assets}"}', assets );
|
|
1096
|
+
|| self.isCacheless() && hasViews() && self.isXMLRequest()
|
|
1097
|
+
) {
|
|
1098
|
+
layout = layout.replace('{"assets":"${assets}"}', assets );
|
|
1042
1099
|
}
|
|
1043
|
-
|
|
1100
|
+
|
|
1044
1101
|
} catch (err) {
|
|
1045
1102
|
self.throwError(local.res, 500, new Error('Controller::render(...) calling getAssets(...) \n' + (err.stack||err.message||err) ));
|
|
1046
1103
|
return;
|
|
1047
1104
|
}
|
|
1048
1105
|
}
|
|
1049
|
-
|
|
1050
|
-
// Last compilation before rendering
|
|
1051
|
-
layout = swig.compile(layout, mapping)(data);
|
|
1052
|
-
|
|
1053
|
-
if ( !
|
|
1106
|
+
|
|
1107
|
+
// Last compilation before rendering
|
|
1108
|
+
layout = swig.compile(layout, mapping)(data);
|
|
1109
|
+
|
|
1110
|
+
if ( !headersSent() ) {
|
|
1054
1111
|
if ( local.options.isRenderingCustomError ) {
|
|
1055
1112
|
local.options.isRenderingCustomError = false;
|
|
1056
1113
|
}
|
|
1114
|
+
|
|
1057
1115
|
local.res.end(layout);
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1060
1118
|
console.info(local.req.method +' ['+local.res.statusCode +'] '+ local.req.url);
|
|
1061
|
-
|
|
1062
|
-
} else if (typeof(local.next) != 'undefined') {
|
|
1119
|
+
|
|
1120
|
+
} else if (typeof(local.next) != 'undefined') {
|
|
1063
1121
|
// local.next();
|
|
1064
1122
|
return local.next();
|
|
1065
1123
|
} else {
|
|
@@ -1075,7 +1133,7 @@ function SuperController(options) {
|
|
|
1075
1133
|
return;
|
|
1076
1134
|
}
|
|
1077
1135
|
}
|
|
1078
|
-
|
|
1136
|
+
|
|
1079
1137
|
|
|
1080
1138
|
this.isXMLRequest = function() {
|
|
1081
1139
|
return local.options.isXMLRequest;
|
|
@@ -1102,21 +1160,21 @@ function SuperController(options) {
|
|
|
1102
1160
|
return false
|
|
1103
1161
|
}
|
|
1104
1162
|
if ( self.isProcessingError ) {
|
|
1105
|
-
return;
|
|
1163
|
+
return;
|
|
1106
1164
|
}
|
|
1107
1165
|
|
|
1108
1166
|
var request = local.req;
|
|
1109
1167
|
var response = local.res;
|
|
1110
1168
|
var next = local.next || null;
|
|
1111
1169
|
// var stream = null;
|
|
1112
|
-
// if ( /http\/2/.test(local.options.conf.server.protocol) ) {
|
|
1113
|
-
// stream = response.stream;
|
|
1170
|
+
// if ( /http\/2/.test(local.options.conf.server.protocol) ) {
|
|
1171
|
+
// stream = response.stream;
|
|
1114
1172
|
// }
|
|
1115
1173
|
|
|
1116
1174
|
if (!jsonObj) {
|
|
1117
1175
|
jsonObj = {}
|
|
1118
1176
|
}
|
|
1119
|
-
|
|
1177
|
+
|
|
1120
1178
|
try {
|
|
1121
1179
|
// just in case
|
|
1122
1180
|
if ( typeof(jsonObj) == 'string') {
|
|
@@ -1126,7 +1184,7 @@ function SuperController(options) {
|
|
|
1126
1184
|
// if( typeof(local.options) != "undefined" && typeof(local.options.charset) != "undefined" ){
|
|
1127
1185
|
// response.setHeader("charset", local.options.charset);
|
|
1128
1186
|
// }
|
|
1129
|
-
|
|
1187
|
+
|
|
1130
1188
|
|
|
1131
1189
|
//catching errors
|
|
1132
1190
|
if (
|
|
@@ -1151,7 +1209,7 @@ function SuperController(options) {
|
|
|
1151
1209
|
response.setHeader('content-type', local.options.conf.server.coreConfiguration.mime['json'] + '; charset='+ local.options.conf.encoding)
|
|
1152
1210
|
}
|
|
1153
1211
|
|
|
1154
|
-
if ( !response
|
|
1212
|
+
if ( !headersSent(response) ) {
|
|
1155
1213
|
console.info(request.method +' ['+ response.statusCode +'] '+ request.url);
|
|
1156
1214
|
|
|
1157
1215
|
if ( local.options.isXMLRequest && self.isWithCredentials() ) {
|
|
@@ -1164,17 +1222,17 @@ function SuperController(options) {
|
|
|
1164
1222
|
} else {
|
|
1165
1223
|
len = data.length
|
|
1166
1224
|
}
|
|
1167
|
-
|
|
1168
|
-
if (!response
|
|
1225
|
+
|
|
1226
|
+
if (!headersSent(response))
|
|
1169
1227
|
response.setHeader("content-length", len);
|
|
1170
|
-
|
|
1171
|
-
|
|
1228
|
+
|
|
1229
|
+
|
|
1172
1230
|
// if (stream && !stream.destroyed) {
|
|
1173
1231
|
// //stream.respond(header);
|
|
1174
1232
|
// stream.end(data);
|
|
1175
1233
|
// } else {
|
|
1176
1234
|
response.write(data);
|
|
1177
|
-
|
|
1235
|
+
|
|
1178
1236
|
// required to close connection
|
|
1179
1237
|
setTimeout(function () {
|
|
1180
1238
|
response.end();
|
|
@@ -1184,21 +1242,21 @@ function SuperController(options) {
|
|
|
1184
1242
|
// Ignoring warning
|
|
1185
1243
|
//console.warn(err);
|
|
1186
1244
|
}
|
|
1187
|
-
|
|
1245
|
+
|
|
1188
1246
|
if ( next ) {
|
|
1189
1247
|
next()
|
|
1190
1248
|
}
|
|
1191
1249
|
}, 200);
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1195
1253
|
return // force completion
|
|
1196
1254
|
// }
|
|
1197
|
-
|
|
1255
|
+
|
|
1198
1256
|
|
|
1199
1257
|
} else { // normal case
|
|
1200
1258
|
response.end(JSON.stringify(jsonObj));
|
|
1201
|
-
if (!response
|
|
1259
|
+
if (!headersSent(response)) {
|
|
1202
1260
|
try {
|
|
1203
1261
|
response.headersSent = true;
|
|
1204
1262
|
} catch(err) {
|
|
@@ -1207,9 +1265,9 @@ function SuperController(options) {
|
|
|
1207
1265
|
}
|
|
1208
1266
|
}
|
|
1209
1267
|
if ( next ) {
|
|
1210
|
-
next()
|
|
1268
|
+
return next()
|
|
1211
1269
|
}
|
|
1212
|
-
|
|
1270
|
+
|
|
1213
1271
|
return;
|
|
1214
1272
|
}
|
|
1215
1273
|
}
|
|
@@ -1239,7 +1297,7 @@ function SuperController(options) {
|
|
|
1239
1297
|
local.res.setHeader('content-type', 'text/plain' + '; charset='+ local.options.conf.encoding);
|
|
1240
1298
|
}
|
|
1241
1299
|
|
|
1242
|
-
if ( !
|
|
1300
|
+
if ( !headersSent() ) {
|
|
1243
1301
|
console.info(local.req.method +' ['+local.res.statusCode +'] '+ local.req.url);
|
|
1244
1302
|
local.res.end(content);
|
|
1245
1303
|
try {
|
|
@@ -1308,7 +1366,7 @@ function SuperController(options) {
|
|
|
1308
1366
|
* Get data
|
|
1309
1367
|
*
|
|
1310
1368
|
* @param {String} variable Data name to set
|
|
1311
|
-
* @returns {Object |
|
|
1369
|
+
* @returns {Object | String} data Data object or String
|
|
1312
1370
|
* */
|
|
1313
1371
|
var get = function(variable) {
|
|
1314
1372
|
return local.userData[variable]
|
|
@@ -1324,24 +1382,24 @@ function SuperController(options) {
|
|
|
1324
1382
|
self.throwError(500, new Error('No views configuration found. Did you try to add views before using Controller::render(...) ? Try to run: gina view:add '+ options.conf.bundle +' @'+ options.conf.projectName));
|
|
1325
1383
|
return;
|
|
1326
1384
|
}
|
|
1327
|
-
|
|
1385
|
+
|
|
1328
1386
|
var authority = ( typeof(local.req.headers['x-forwarded-proto']) != 'undefined' ) ? local.req.headers['x-forwarded-proto'] : local.options.conf.server.scheme;
|
|
1329
1387
|
authority += '://'+ local.req.headers.host;
|
|
1330
1388
|
var useWebroot = false;
|
|
1331
1389
|
if ( !/^\/$/.test(local.options.conf.server.webroot) && local.options.conf.server.webroot.length > 0 && local.options.conf.hostname.replace(/\:\d+$/, '') == authority ) {
|
|
1332
1390
|
useWebroot = true
|
|
1333
1391
|
}
|
|
1334
|
-
|
|
1392
|
+
|
|
1335
1393
|
var reURL = new RegExp('^'+ local.options.conf.server.webroot);
|
|
1336
1394
|
|
|
1337
1395
|
var cssStr = '', jsStr = '';
|
|
1338
|
-
|
|
1396
|
+
|
|
1339
1397
|
//Get css
|
|
1340
1398
|
if( viewConf.stylesheets ) {
|
|
1341
1399
|
cssStr = getNodeRes('css', viewConf.stylesheets, useWebroot, reURL)
|
|
1342
1400
|
}
|
|
1343
1401
|
//Get js
|
|
1344
|
-
if( viewConf.javascripts ) {
|
|
1402
|
+
if( viewConf.javascripts ) {
|
|
1345
1403
|
jsStr = getNodeRes('js', viewConf.javascripts, useWebroot, reURL)
|
|
1346
1404
|
}
|
|
1347
1405
|
|
|
@@ -1362,7 +1420,7 @@ function SuperController(options) {
|
|
|
1362
1420
|
* @private
|
|
1363
1421
|
* */
|
|
1364
1422
|
var getNodeRes = function(type, resArr, useWebroot, reURL) {
|
|
1365
|
-
|
|
1423
|
+
|
|
1366
1424
|
var r = 0
|
|
1367
1425
|
, rLen = resArr.length
|
|
1368
1426
|
, obj = null
|
|
@@ -1370,7 +1428,7 @@ function SuperController(options) {
|
|
|
1370
1428
|
;
|
|
1371
1429
|
switch(type){
|
|
1372
1430
|
case 'css':
|
|
1373
|
-
for (; r < rLen; ++r) {
|
|
1431
|
+
for (; r < rLen; ++r) {
|
|
1374
1432
|
obj = resArr[r];
|
|
1375
1433
|
if (useWebroot && !reURL.test(obj.url) ) {
|
|
1376
1434
|
obj.url = local.options.conf.server.webroot + obj.url.substr(1);
|
|
@@ -1378,32 +1436,32 @@ function SuperController(options) {
|
|
|
1378
1436
|
// TODO - add support for cdn
|
|
1379
1437
|
if (!/\:\/\//.test(obj.url) ) {
|
|
1380
1438
|
obj.url = local.options.conf.hostname + obj.url;
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1383
1441
|
if (obj.media)
|
|
1384
|
-
str += '\n\t\t<link href="'+ obj.url +'" media="'+ obj.media +'" rel="'+ obj.rel +'" type="'+ obj.type +'">';
|
|
1442
|
+
str += '\n\t\t<link href="'+ obj.url +'" media="'+ obj.media +'" rel="'+ obj.rel +'" type="'+ obj.type +'">';
|
|
1385
1443
|
else
|
|
1386
|
-
str += '\n\t\t<link href="'+ obj.url +'" rel="'+ obj.rel +'" type="'+ obj.type +'">';
|
|
1444
|
+
str += '\n\t\t<link href="'+ obj.url +'" rel="'+ obj.rel +'" type="'+ obj.type +'">';
|
|
1387
1445
|
}
|
|
1388
|
-
|
|
1446
|
+
|
|
1389
1447
|
return str;
|
|
1390
1448
|
break;
|
|
1391
1449
|
|
|
1392
1450
|
case 'js':
|
|
1393
1451
|
var deferMode = (local.options.template.javascriptsDeferEnabled) ? ' defer' : '';
|
|
1394
|
-
|
|
1452
|
+
|
|
1395
1453
|
for (; r < rLen; ++r) {
|
|
1396
1454
|
obj = resArr[r];
|
|
1397
1455
|
if (useWebroot && !reURL.test(obj.url) ) {
|
|
1398
1456
|
obj.url = local.options.conf.server.webroot + obj.url.substr(1);
|
|
1399
1457
|
}
|
|
1400
|
-
// TODO - add support for cdn
|
|
1458
|
+
// TODO - add support for cdn
|
|
1401
1459
|
if (!/\:\/\//.test(obj.url) ) {
|
|
1402
1460
|
obj.url = local.options.conf.hostname + obj.url;
|
|
1403
1461
|
}
|
|
1404
|
-
str += '\n\t\t<script'+ deferMode +' type="'+ obj.type +'" src="'+ obj.url +'"></script>'
|
|
1462
|
+
str += '\n\t\t<script'+ deferMode +' type="'+ obj.type +'" src="'+ obj.url +'"></script>'
|
|
1405
1463
|
}
|
|
1406
|
-
|
|
1464
|
+
|
|
1407
1465
|
return str;
|
|
1408
1466
|
break;
|
|
1409
1467
|
}
|
|
@@ -1419,17 +1477,17 @@ function SuperController(options) {
|
|
|
1419
1477
|
var getData = function() {
|
|
1420
1478
|
return refToObj( local.userData )
|
|
1421
1479
|
}
|
|
1422
|
-
|
|
1480
|
+
|
|
1423
1481
|
|
|
1424
1482
|
var isValidURL = function(url){
|
|
1425
1483
|
var re = /(http|ftp|https|sftp):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/;
|
|
1426
1484
|
return (re.test(url)) ? true : false
|
|
1427
1485
|
}
|
|
1428
|
-
|
|
1486
|
+
|
|
1429
1487
|
/**
|
|
1430
|
-
* Set method - Override current method
|
|
1488
|
+
* Set method - Override current method
|
|
1431
1489
|
* E.g.: in case of redirect, to force PUT to GET
|
|
1432
|
-
*
|
|
1490
|
+
*
|
|
1433
1491
|
* @param {string} requestMethod - GET, POST, PUT, DELETE
|
|
1434
1492
|
*/
|
|
1435
1493
|
var localRequestMethod = null, localRequestMethodParams = null;
|
|
@@ -1438,75 +1496,75 @@ function SuperController(options) {
|
|
|
1438
1496
|
if ( /http\/2/i.test(conf.server.protocolShort) ) {
|
|
1439
1497
|
local.req.headers[':method'] = local.req.method.toUpperCase()
|
|
1440
1498
|
}
|
|
1441
|
-
|
|
1499
|
+
|
|
1442
1500
|
localRequestMethod = local.req.method = local.req.routing.method = requestMethod.toUpperCase();
|
|
1443
|
-
|
|
1501
|
+
|
|
1444
1502
|
local.res.setHeader('access-control-allow-methods', localRequestMethod);
|
|
1445
|
-
|
|
1446
|
-
return localRequestMethod;
|
|
1503
|
+
|
|
1504
|
+
return localRequestMethod;
|
|
1447
1505
|
}
|
|
1448
|
-
|
|
1506
|
+
|
|
1449
1507
|
this.getRequestMethod = function() {
|
|
1450
1508
|
return localRequestMethod;
|
|
1451
1509
|
}
|
|
1452
|
-
|
|
1510
|
+
|
|
1453
1511
|
this.setRequestMethodParams = function(params) {
|
|
1454
1512
|
localRequestMethodParams = local.req[local.req.method.toLowerCase()] = localRequestMethodParams = params
|
|
1455
1513
|
}
|
|
1456
|
-
|
|
1514
|
+
|
|
1457
1515
|
this.getRequestMethodParams = function() {
|
|
1458
|
-
return (localRequestMethodParams) ? localRequestMethodParams :
|
|
1516
|
+
return (localRequestMethodParams) ? localRequestMethodParams : local.req[local.req.method.toLowerCase()]
|
|
1459
1517
|
}
|
|
1460
|
-
|
|
1518
|
+
|
|
1461
1519
|
/**
|
|
1462
1520
|
* isStaticRoute
|
|
1463
1521
|
* Trying to determine if url is a `statics` ressource
|
|
1464
|
-
*
|
|
1522
|
+
*
|
|
1465
1523
|
* @param {string} url
|
|
1466
1524
|
* @param {string} method
|
|
1467
|
-
*
|
|
1525
|
+
*
|
|
1468
1526
|
* @returns {boolean} isStaticRoute
|
|
1469
1527
|
*/
|
|
1470
1528
|
var isStaticRoute = function(url, method, bundle, env, conf) {
|
|
1471
|
-
|
|
1529
|
+
|
|
1472
1530
|
if ( !/get/i.test(method) ) {
|
|
1473
1531
|
return false
|
|
1474
1532
|
}
|
|
1475
|
-
|
|
1533
|
+
|
|
1476
1534
|
// priority to statics - this portion of code has been duplicated to Server.js
|
|
1477
|
-
|
|
1535
|
+
|
|
1478
1536
|
var staticsArr = conf[bundle][env].publicResources;
|
|
1479
1537
|
var staticProps = {
|
|
1480
1538
|
firstLevel : '/' + url.split(/\//g)[1] + '/',
|
|
1481
1539
|
// to be considered as a stativ content, url must content at least 2 caracters after last `.`: .js, .html are ok
|
|
1482
1540
|
isStaticFilename : /(\.([A-Za-z0-9]+){2}|\/)$/.test(url)
|
|
1483
|
-
};
|
|
1484
|
-
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1485
1543
|
// handle resources from public with webroot in url
|
|
1486
1544
|
if ( staticProps.isStaticFilename && conf[bundle][env].server.webroot != '/' && staticProps.firstLevel == conf[bundle][env].server.webroot ) {
|
|
1487
1545
|
var matchedFirstInUrl = url.replace(conf[bundle][env].server.webroot, '').match(/[A-Za-z0-9_-]+\/?/);
|
|
1488
1546
|
if ( matchedFirstInUrl && matchedFirstInUrl.length > 0 ) {
|
|
1489
1547
|
staticProps.firstLevel = conf[bundle][env].server.webroot + matchedFirstInUrl[0]
|
|
1490
|
-
}
|
|
1548
|
+
}
|
|
1491
1549
|
}
|
|
1492
|
-
|
|
1493
|
-
if (
|
|
1494
|
-
staticProps.isStaticFilename && staticsArr.indexOf(url) > -1
|
|
1495
|
-
|| staticProps.isStaticFilename && staticsArr.indexOf( url.replace(url.substr(url.lastIndexOf('/')+1), '') ) > -1
|
|
1550
|
+
|
|
1551
|
+
if (
|
|
1552
|
+
staticProps.isStaticFilename && staticsArr.indexOf(url) > -1
|
|
1553
|
+
|| staticProps.isStaticFilename && staticsArr.indexOf( url.replace(url.substr(url.lastIndexOf('/')+1), '') ) > -1
|
|
1496
1554
|
|| staticProps.isStaticFilename && staticsArr.indexOf(staticProps.firstLevel) > -1
|
|
1497
1555
|
) {
|
|
1498
1556
|
return true
|
|
1499
1557
|
}
|
|
1500
|
-
|
|
1558
|
+
|
|
1501
1559
|
return false;
|
|
1502
1560
|
}
|
|
1503
1561
|
|
|
1504
1562
|
/**
|
|
1505
1563
|
* redirect
|
|
1506
1564
|
*
|
|
1507
|
-
* TODO - improve redirect based on `
|
|
1565
|
+
* TODO - improve redirect based on `lib.routing`
|
|
1508
1566
|
* e.g.: self.redirect('project-get', { companyId: companyId, clientId: clientId, id: projectId }, true)
|
|
1509
|
-
*
|
|
1567
|
+
*
|
|
1510
1568
|
* How to avoid redirect inside popin context
|
|
1511
1569
|
* N.B.: When you are in a popin context, add an `id` to your template tag so it can be ignored by the default PopinHandler
|
|
1512
1570
|
* E.g.: id="delete-link" -> <a href="#" id="delete-link">delete</a>
|
|
@@ -1553,21 +1611,21 @@ function SuperController(options) {
|
|
|
1553
1611
|
* `ignoreWebRoot` behaves the like set to `false` by default
|
|
1554
1612
|
*
|
|
1555
1613
|
* N.B.: Gina will tell browsers not to cache redirections if you are using `dev` environement
|
|
1556
|
-
*
|
|
1614
|
+
*
|
|
1557
1615
|
* Trobleshouting:
|
|
1558
1616
|
* ---------------
|
|
1559
|
-
*
|
|
1617
|
+
*
|
|
1560
1618
|
* Redirecting to a popin from the controller while posting from a form
|
|
1561
1619
|
* If this does not work, like doing a real redirect, this
|
|
1562
1620
|
* only means that the ID you are using for the form might be
|
|
1563
1621
|
* a duplicate one from the the main document !!!
|
|
1564
1622
|
*
|
|
1565
|
-
* @param {object|string} req|rule - Request Object or Rule/Route name
|
|
1623
|
+
* @param {object|string} req|rule|url - Request Object or Rule/Route name
|
|
1566
1624
|
* @param {object|boolean} res|ignoreWebRoot - Response Object or Ignore WebRoot & start from domain root: /
|
|
1567
1625
|
* @param {object} [params] TODO
|
|
1568
1626
|
*
|
|
1569
1627
|
* @callback [ next ]
|
|
1570
|
-
* */
|
|
1628
|
+
* */
|
|
1571
1629
|
this.redirect = function(req, res, next) {
|
|
1572
1630
|
var conf = self.getConfig();
|
|
1573
1631
|
var bundle = conf.bundle;
|
|
@@ -1579,15 +1637,15 @@ function SuperController(options) {
|
|
|
1579
1637
|
var ignoreWebRoot = null, isRelative = false;
|
|
1580
1638
|
var originalUrl = null;
|
|
1581
1639
|
var method = null;
|
|
1582
|
-
var originalMethod = null;
|
|
1640
|
+
var originalMethod = null;
|
|
1583
1641
|
|
|
1584
1642
|
if ( typeof(req) === 'string' ) {
|
|
1585
1643
|
|
|
1586
1644
|
// if ( typeof(res) == 'undefined') {
|
|
1587
1645
|
// // nothing to do
|
|
1588
1646
|
// ignoreWebRoot = false
|
|
1589
|
-
// } else
|
|
1590
|
-
if (typeof(res) === 'string' || typeof(res) === 'number'
|
|
1647
|
+
// } else
|
|
1648
|
+
if (typeof(res) === 'string' || typeof(res) === 'number' || typeof(res) === 'boolean') {
|
|
1591
1649
|
if ( /true|1/.test(res) ) {
|
|
1592
1650
|
ignoreWebRoot = true
|
|
1593
1651
|
} else if ( /false|0/.test(res) ) {
|
|
@@ -1608,26 +1666,26 @@ function SuperController(options) {
|
|
|
1608
1666
|
ignoreWebRoot = false;
|
|
1609
1667
|
}
|
|
1610
1668
|
}
|
|
1611
|
-
|
|
1669
|
+
|
|
1612
1670
|
}
|
|
1613
1671
|
|
|
1614
1672
|
if ( req.substr(0,1) === '/') { // is relative (not checking if the URI is defined in the routing.json)
|
|
1615
1673
|
// if (wroot.substr(wroot.length-1,1) == '/') {
|
|
1616
1674
|
// wroot = wroot.substr(wroot.length-1,1).replace('/', '')
|
|
1617
1675
|
// }
|
|
1618
|
-
|
|
1676
|
+
|
|
1619
1677
|
if ( /^\//.test(req) && !ignoreWebRoot )
|
|
1620
1678
|
req = req.substr(1);
|
|
1621
|
-
|
|
1679
|
+
|
|
1622
1680
|
rte = ( ignoreWebRoot != null && ignoreWebRoot ) ? req : wroot + req;
|
|
1623
1681
|
// cleaning url in case of ?param=value
|
|
1624
|
-
originalUrl = rte;
|
|
1682
|
+
originalUrl = rte;
|
|
1625
1683
|
rte = rte.replace(/\?(.*)/, '');
|
|
1626
|
-
|
|
1684
|
+
|
|
1627
1685
|
req = local.req;
|
|
1628
|
-
originalMethod = ( typeof(req.originalMethod) != 'undefined') ? req.originalMethod : req.method;
|
|
1629
|
-
console.debug('[ BUNDLE ][ '+ local.options.conf.bundle +' ][ Controller ] trying to get route: ', rte, bundle, req.method);
|
|
1630
|
-
if ( !ignoreWebRoot || !isStaticRoute(rte, req.method, bundle, env, ctx.config.envConf) && !ignoreWebRoot ) {
|
|
1686
|
+
originalMethod = ( typeof(req.originalMethod) != 'undefined') ? req.originalMethod : req.method;
|
|
1687
|
+
console.debug('[ BUNDLE ][ '+ local.options.conf.bundle +' ][ Controller ] trying to get route: ', rte, bundle, req.method);
|
|
1688
|
+
if ( !ignoreWebRoot || !isStaticRoute(rte, req.method, bundle, env, ctx.config.envConf) && !ignoreWebRoot ) {
|
|
1631
1689
|
req.routing = lib.routing.getRouteByUrl(rte, bundle, req.method, req);
|
|
1632
1690
|
// try alternative method
|
|
1633
1691
|
if (!req.routing) {
|
|
@@ -1637,7 +1695,7 @@ function SuperController(options) {
|
|
|
1637
1695
|
method = req.method = 'GET'
|
|
1638
1696
|
}
|
|
1639
1697
|
}
|
|
1640
|
-
|
|
1698
|
+
|
|
1641
1699
|
//route = route = req.routing.name;
|
|
1642
1700
|
} else {
|
|
1643
1701
|
req.routing = {
|
|
@@ -1646,59 +1704,59 @@ function SuperController(options) {
|
|
|
1646
1704
|
}
|
|
1647
1705
|
}
|
|
1648
1706
|
}
|
|
1649
|
-
|
|
1707
|
+
|
|
1650
1708
|
res = local.res;
|
|
1651
1709
|
next = local.next;
|
|
1652
1710
|
isRelative = true;
|
|
1653
|
-
|
|
1711
|
+
|
|
1654
1712
|
req.routing.param.path = rte
|
|
1655
1713
|
} else if ( isValidURL(req) ) { // might be an URL
|
|
1656
1714
|
rte = req;
|
|
1657
|
-
originalUrl = rte;
|
|
1715
|
+
originalUrl = rte;
|
|
1658
1716
|
rte = rte.replace(/\?(.*)/, '');
|
|
1659
|
-
|
|
1717
|
+
|
|
1660
1718
|
req = local.req;
|
|
1661
1719
|
res = local.res;
|
|
1662
1720
|
next = local.next;
|
|
1663
|
-
|
|
1721
|
+
|
|
1664
1722
|
req.routing.param.url = rte
|
|
1665
1723
|
} else { // is by default a route name
|
|
1666
|
-
|
|
1724
|
+
|
|
1667
1725
|
if ( /\@/.test(req) ) {
|
|
1668
1726
|
var rteArr = req.split(/\//);
|
|
1669
1727
|
if ( typeof(rteArr[1]) != 'undefined' )
|
|
1670
1728
|
env = rteArr[1];
|
|
1671
|
-
|
|
1729
|
+
|
|
1672
1730
|
rte = route = rteArr[0];
|
|
1673
1731
|
rteArr = rteArr[0].split(/\@/);
|
|
1674
|
-
|
|
1732
|
+
|
|
1675
1733
|
bundle = rteArr[1];
|
|
1676
|
-
|
|
1734
|
+
|
|
1677
1735
|
} else {
|
|
1678
1736
|
rte = route = ( new RegExp('^/'+conf.bundle+'-$').test(req) ) ? req : wroot.match(/[^/]/g).join('') +'-'+ req;
|
|
1679
1737
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1738
|
+
|
|
1739
|
+
|
|
1682
1740
|
req = local.req;
|
|
1683
1741
|
res = local.res;
|
|
1684
1742
|
next = local.next;
|
|
1685
|
-
|
|
1743
|
+
|
|
1686
1744
|
req.routing.param.route = routing[rte]
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1689
1747
|
} else {
|
|
1690
|
-
route = req.routing.param.route;
|
|
1748
|
+
route = req.routing.param.route;
|
|
1691
1749
|
}
|
|
1692
|
-
|
|
1750
|
+
|
|
1693
1751
|
if ( !originalMethod ) {
|
|
1694
1752
|
originalMethod = ( typeof(req.originalMethod) != 'undefined') ? req.originalMethod : req.method;
|
|
1695
1753
|
}
|
|
1696
|
-
|
|
1697
|
-
var path = originalUrl || req.routing.param.path ||
|
|
1754
|
+
|
|
1755
|
+
var path = originalUrl || req.routing.param.path || '';
|
|
1698
1756
|
var url = req.routing.param.url;
|
|
1699
|
-
var code = req.routing.param.code ||
|
|
1757
|
+
var code = req.routing.param.code || 301;
|
|
1700
1758
|
|
|
1701
|
-
var keepParams = req.routing.param['keep-params'] ||
|
|
1759
|
+
var keepParams = req.routing.param['keep-params'] || false;
|
|
1702
1760
|
|
|
1703
1761
|
var condition = true; //set by default for url @ path redirect
|
|
1704
1762
|
|
|
@@ -1710,20 +1768,20 @@ function SuperController(options) {
|
|
|
1710
1768
|
|
|
1711
1769
|
var isProxyHost = ( typeof(local.req.headers.host) != 'undefined' && local.options.conf.server.scheme +'://'+ local.req.headers.host != local.options.conf.hostname || typeof(local.req.headers[':authority']) != 'undefined' && local.options.conf.server.scheme +'://'+ local.req.headers[':authority'] != local.options.conf.hostname ) ? true : false;
|
|
1712
1770
|
var hostname = (isProxyHost) ? ctx.config.envConf[bundle][env].hostname.replace(/\:\d+$/, '') : ctx.config.envConf[bundle][env].hostname;
|
|
1713
|
-
|
|
1771
|
+
|
|
1714
1772
|
// if ( !/\:\d+$/.test(req.headers.host) )
|
|
1715
1773
|
// hostname = hostname.replace(/\:\d+$/, '');
|
|
1716
1774
|
|
|
1717
1775
|
if (route) { // will go with route first
|
|
1718
|
-
|
|
1776
|
+
|
|
1719
1777
|
if ( /\,/.test(routing[route].url) ) {
|
|
1720
1778
|
var paths = routing[route].url.split(/\,/g);
|
|
1721
1779
|
path = (ignoreWebRoot) ? paths[0].replace(wroot, '') : paths[0];
|
|
1722
1780
|
} else {
|
|
1723
1781
|
path = (ignoreWebRoot) ? routing[route].url.replace(wroot, '') : routing[route].url;
|
|
1724
1782
|
}
|
|
1725
|
-
|
|
1726
|
-
if (bundle != conf.bundle) {
|
|
1783
|
+
|
|
1784
|
+
if (bundle != conf.bundle) {
|
|
1727
1785
|
path = hostname + path;
|
|
1728
1786
|
}
|
|
1729
1787
|
} else if (url && !path) {
|
|
@@ -1737,59 +1795,60 @@ function SuperController(options) {
|
|
|
1737
1795
|
// nothing to do, just ignoring
|
|
1738
1796
|
//} else {
|
|
1739
1797
|
} else if ( !path && typeof(isRelative) == 'undefined' ) {
|
|
1740
|
-
|
|
1798
|
+
|
|
1741
1799
|
path = hostname + path
|
|
1742
1800
|
//path = local.req.headers.host + path
|
|
1743
1801
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
1802
|
|
|
1747
|
-
|
|
1748
|
-
|
|
1803
|
+
|
|
1804
|
+
|
|
1805
|
+
if (!headersSent()) {
|
|
1806
|
+
|
|
1749
1807
|
// backing up oldParams
|
|
1750
1808
|
var oldParams = local.req[originalMethod.toLowerCase()];
|
|
1751
|
-
var requestParams = req[req.method.toLowerCase()] ||
|
|
1809
|
+
var requestParams = req[req.method.toLowerCase()] || {};
|
|
1752
1810
|
if ( typeof(requestParams) != 'undefined' && typeof(requestParams.error) != 'undefined' ) {
|
|
1753
1811
|
var redirectError = requestParams.error;
|
|
1754
1812
|
self.throwError(requestParams.error);
|
|
1755
1813
|
return;
|
|
1756
1814
|
}
|
|
1757
|
-
|
|
1758
|
-
if (
|
|
1759
|
-
!/GET/i.test(req.method)
|
|
1760
|
-
||
|
|
1761
|
-
originalMethod && !/GET/i.test(originalMethod)
|
|
1762
|
-
) { // trying to redirect using the wrong method ?
|
|
1763
|
-
|
|
1815
|
+
|
|
1816
|
+
if (
|
|
1817
|
+
!/GET/i.test(req.method)
|
|
1818
|
+
||
|
|
1819
|
+
originalMethod && !/GET/i.test(originalMethod)
|
|
1820
|
+
) { // trying to redirect using the wrong method ?
|
|
1821
|
+
|
|
1764
1822
|
console.warn(new Error('Your are trying to redirect using the wrong method: `'+ req.method+'`.\nThis can often occur while redirecting from a controller to another controller or from a bundle to another.\nA redirection is not permitted in this scenario.\nD\'ont panic :)\nSwitching request method to `GET` method instead.\n').message);
|
|
1765
1823
|
method = local.req.method = self.setRequestMethod('GET', conf);
|
|
1766
|
-
code = 303;
|
|
1824
|
+
code = 303;
|
|
1767
1825
|
}
|
|
1768
|
-
|
|
1769
|
-
|
|
1826
|
+
|
|
1827
|
+
var inheritedDataIsNeeded = ( req.method.toLowerCase() == originalMethod.toLowerCase() ) ? false: true;
|
|
1828
|
+
|
|
1770
1829
|
// merging new & olds params
|
|
1771
1830
|
requestParams = merge(requestParams, oldParams);
|
|
1772
1831
|
// remove session to prevent reaching the 2000 chars limit
|
|
1773
1832
|
// if you need the session, you need to find another way to retrieve while in the next route
|
|
1774
|
-
if ( typeof(requestParams.session) != 'undefined' ) {
|
|
1833
|
+
if ( typeof(requestParams.session) != 'undefined' ) {
|
|
1775
1834
|
delete requestParams.session;
|
|
1776
1835
|
}
|
|
1777
|
-
if ( typeof(requestParams) != 'undefined' && requestParams.count() > 0 ) {
|
|
1836
|
+
if ( typeof(requestParams) != 'undefined' && requestParams.count() > 0 ) {
|
|
1778
1837
|
//if ( typeof(requestParams.error) != 'undefined' )
|
|
1779
|
-
|
|
1838
|
+
|
|
1780
1839
|
var inheritedData = null;
|
|
1781
1840
|
if ( /\?/.test(path) ) {
|
|
1782
|
-
inheritedData = '&inheritedData='+
|
|
1841
|
+
inheritedData = '&inheritedData='+ encodeRFC5987ValueChars(JSON.stringify(requestParams));
|
|
1783
1842
|
} else {
|
|
1784
|
-
inheritedData = '?inheritedData='+
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1843
|
+
inheritedData = '?inheritedData='+ encodeRFC5987ValueChars(JSON.stringify(requestParams));
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1787
1846
|
if ( inheritedData.length > 2000 ) {
|
|
1788
1847
|
var error = new ApiError('Controller::redirect(...) exceptions: `inheritedData` reached 2000 chars limit', 424);
|
|
1789
1848
|
self.throwError(error);
|
|
1790
1849
|
return;
|
|
1791
1850
|
}
|
|
1792
|
-
|
|
1851
|
+
|
|
1793
1852
|
// if redirecting from a xhrRequest
|
|
1794
1853
|
if ( self.isXMLRequest() ) {
|
|
1795
1854
|
// `requestParams` should be stored in the session to avoid passing datas in clear
|
|
@@ -1803,21 +1862,26 @@ function SuperController(options) {
|
|
|
1803
1862
|
redirectObj.location += inheritedData;
|
|
1804
1863
|
}
|
|
1805
1864
|
}
|
|
1806
|
-
|
|
1865
|
+
|
|
1807
1866
|
self.renderJSON(redirectObj);
|
|
1808
1867
|
return;
|
|
1809
1868
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1869
|
+
|
|
1870
|
+
if (inheritedDataIsNeeded) {
|
|
1871
|
+
path += inheritedData;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1814
1875
|
var ext = 'html';
|
|
1815
1876
|
res.setHeader('content-type', local.options.conf.server.coreConfiguration.mime[ext]);
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
&& local.res._headers['access-control-allow-methods'] !=
|
|
1877
|
+
|
|
1878
|
+
var resHeaderACAM = res.getHeader('access-control-allow-methods');
|
|
1879
|
+
if (
|
|
1880
|
+
// typeof(local.res._headers) != 'undefined'
|
|
1881
|
+
// && typeof(local.res._headers['access-control-allow-methods']) != 'undefined'
|
|
1882
|
+
// && local.res._headers['access-control-allow-methods'] != req.method
|
|
1883
|
+
typeof(resHeaderACAM) != 'undefined'
|
|
1884
|
+
&& resHeaderACAM != req.method
|
|
1821
1885
|
||
|
|
1822
1886
|
!new RegExp(req.method, 'i').test( res.getHeader('access-control-allow-methods') )
|
|
1823
1887
|
) {
|
|
@@ -1825,11 +1889,11 @@ function SuperController(options) {
|
|
|
1825
1889
|
}
|
|
1826
1890
|
//path += '?query='+ JSON.stringify(self.getRequestMethodParams());
|
|
1827
1891
|
local.req[req.method.toLowerCase()] = self.getRequestMethodParams() || {};
|
|
1828
|
-
|
|
1892
|
+
|
|
1829
1893
|
var headInfos = {
|
|
1830
|
-
'location': path
|
|
1831
|
-
};
|
|
1832
|
-
|
|
1894
|
+
'location': path
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1833
1897
|
if (self.isCacheless()) {
|
|
1834
1898
|
res.writeHead(code, merge(headInfos, {
|
|
1835
1899
|
'cache-control': 'no-cache, no-store, must-revalidate', // preventing browsers from using cache
|
|
@@ -1838,24 +1902,26 @@ function SuperController(options) {
|
|
|
1838
1902
|
}))
|
|
1839
1903
|
} else {
|
|
1840
1904
|
res.writeHead(code, headInfos)
|
|
1841
|
-
}
|
|
1842
|
-
// in case of query from another bundle waiting for a response
|
|
1843
|
-
var redirectObject = JSON.stringify({ status: code, headers: headInfos });
|
|
1844
|
-
|
|
1905
|
+
}
|
|
1906
|
+
// in case of query from another bundle waiting for a response
|
|
1907
|
+
var redirectObject = JSON.stringify({ status: code, headers: headInfos });
|
|
1908
|
+
|
|
1845
1909
|
try {
|
|
1910
|
+
res.end(redirectObject);
|
|
1846
1911
|
local.res.headersSent = true;// done for the render() method
|
|
1847
1912
|
} catch(err){
|
|
1848
1913
|
// ignoring the warning
|
|
1914
|
+
// console.warn(err.stack);
|
|
1849
1915
|
}
|
|
1850
|
-
|
|
1916
|
+
|
|
1851
1917
|
console.info(local.req.method.toUpperCase() +' ['+code+'] '+ path);
|
|
1852
|
-
|
|
1918
|
+
|
|
1853
1919
|
if ( typeof(next) != 'undefined' )
|
|
1854
1920
|
next();
|
|
1855
1921
|
else
|
|
1856
1922
|
return;
|
|
1857
1923
|
}
|
|
1858
|
-
|
|
1924
|
+
|
|
1859
1925
|
}
|
|
1860
1926
|
}
|
|
1861
1927
|
|
|
@@ -1896,7 +1962,7 @@ function SuperController(options) {
|
|
|
1896
1962
|
})
|
|
1897
1963
|
}
|
|
1898
1964
|
}
|
|
1899
|
-
|
|
1965
|
+
|
|
1900
1966
|
this.getBundleStatus = function(req, res, next) {
|
|
1901
1967
|
self.renderJSON({
|
|
1902
1968
|
status: 200,
|
|
@@ -1904,8 +1970,8 @@ function SuperController(options) {
|
|
|
1904
1970
|
message: 'I am alive !'
|
|
1905
1971
|
});
|
|
1906
1972
|
}
|
|
1907
|
-
|
|
1908
|
-
this.checkBundleStatus = async function(bundle, cb) {
|
|
1973
|
+
|
|
1974
|
+
this.checkBundleStatus = async function(bundle, cb) {
|
|
1909
1975
|
var opt = self.getConfig('app').proxy[bundle];
|
|
1910
1976
|
var route = lib.routing.getRoute('bundle-status@'+bundle);
|
|
1911
1977
|
opt.method = 'GET';
|
|
@@ -1915,29 +1981,35 @@ function SuperController(options) {
|
|
|
1915
1981
|
.then( function onQueryResponse(_status) {
|
|
1916
1982
|
response = _status
|
|
1917
1983
|
});
|
|
1918
|
-
|
|
1984
|
+
|
|
1919
1985
|
if (cb) {
|
|
1920
1986
|
cb(error, response);
|
|
1921
1987
|
} else {
|
|
1922
1988
|
return response;
|
|
1923
1989
|
}
|
|
1924
1990
|
}
|
|
1925
|
-
|
|
1991
|
+
|
|
1926
1992
|
/**
|
|
1927
1993
|
* downloadFromURL
|
|
1928
1994
|
* Download from an URL
|
|
1929
1995
|
* - attachment/inline
|
|
1930
1996
|
* OR
|
|
1931
|
-
* - locally: `Controller.store(target, cb)` must be called to store on `onComplete` event
|
|
1932
|
-
*
|
|
1997
|
+
* - locally: `Controller.store(target, cb)` must be called to store on `onComplete` event
|
|
1998
|
+
*
|
|
1999
|
+
* - Will trigger on frontend : Failed to load resource: Frame load interrupted
|
|
2000
|
+
* because there is no `res.end()`: whitch is normal, we want to stay on the referrer page
|
|
2001
|
+
*
|
|
2002
|
+
* - To avoid this, add to your download link the attribute `data-gina-link`
|
|
2003
|
+
* This will convert the regular HTTP Request to an XML Request
|
|
2004
|
+
*
|
|
1933
2005
|
* @param {string} url - eg.: https://upload.wikimedia.org/wikipedia/fr/2/2f/Firefox_Old_Logo.png
|
|
1934
2006
|
* @param {object} [options]
|
|
1935
|
-
*
|
|
1936
|
-
*
|
|
2007
|
+
*
|
|
2008
|
+
*
|
|
1937
2009
|
* */
|
|
1938
2010
|
this.downloadFromURL = function(url, options) {
|
|
1939
|
-
|
|
1940
|
-
var defaultOptions = {
|
|
2011
|
+
|
|
2012
|
+
var defaultOptions = {
|
|
1941
2013
|
// file name i you want to rename the file
|
|
1942
2014
|
file: null,
|
|
1943
2015
|
fileSize: null,
|
|
@@ -1947,7 +2019,7 @@ function SuperController(options) {
|
|
|
1947
2019
|
contentDisposition: 'attachment',
|
|
1948
2020
|
// content-type (https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Configuring_server_MIME_types)
|
|
1949
2021
|
contentType: 'application/octet-stream',
|
|
1950
|
-
|
|
2022
|
+
|
|
1951
2023
|
agent: false,
|
|
1952
2024
|
// set to false to ignore certificate verification
|
|
1953
2025
|
rejectUnauthorized: true,
|
|
@@ -1957,9 +2029,9 @@ function SuperController(options) {
|
|
|
1957
2029
|
keepAlive: true,
|
|
1958
2030
|
headers: {}
|
|
1959
2031
|
};
|
|
1960
|
-
|
|
2032
|
+
|
|
1961
2033
|
var opt = ( typeof(options) != 'undefined' ) ? merge(options, defaultOptions) : defaultOptions;
|
|
1962
|
-
|
|
2034
|
+
|
|
1963
2035
|
var requestOptions = {};
|
|
1964
2036
|
for (var o in opt) {
|
|
1965
2037
|
if ( !/(toLocalDir|contentDisposition|contentType|file)/.test(o) )
|
|
@@ -1968,130 +2040,135 @@ function SuperController(options) {
|
|
|
1968
2040
|
|
|
1969
2041
|
// defining protocol & scheme
|
|
1970
2042
|
var protocol = null;
|
|
1971
|
-
var scheme = null;
|
|
1972
|
-
|
|
2043
|
+
var scheme = null;
|
|
2044
|
+
|
|
1973
2045
|
if ( /\:\/\//.test(url) ) {
|
|
1974
2046
|
scheme = url.match(/^\w+\:/)[0];
|
|
1975
2047
|
scheme = scheme.substr(0, scheme.length-1);
|
|
1976
|
-
|
|
2048
|
+
|
|
1977
2049
|
if ( !/^http/.test(scheme) ) {
|
|
1978
2050
|
self.throwError(local.res, 500, new Error('[ '+ scheme +' ] Scheme not supported. Ref.: `http` or `https` only'));
|
|
1979
2051
|
return;
|
|
1980
2052
|
}
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
|
|
1984
2056
|
} else { // by default
|
|
1985
2057
|
scheme = 'http';
|
|
1986
2058
|
}
|
|
1987
|
-
|
|
2059
|
+
|
|
1988
2060
|
requestOptions.scheme = scheme +':';
|
|
1989
|
-
|
|
2061
|
+
|
|
1990
2062
|
//defining port
|
|
1991
2063
|
var port = url.match(/\:\d+\//) || null;
|
|
1992
2064
|
if ( port != null ) {
|
|
1993
2065
|
port = port[0].substr(1, port[0].length-2);
|
|
1994
|
-
requestOptions.port = ~~port;
|
|
2066
|
+
requestOptions.port = ~~port;
|
|
1995
2067
|
}
|
|
1996
|
-
|
|
2068
|
+
|
|
1997
2069
|
// defining hostname & path
|
|
1998
2070
|
var parts = url.replace(new RegExp( scheme + '\:\/\/'), '').split(/\//g);
|
|
1999
2071
|
requestOptions.host = parts[0].replace(/\:\d+/, '');
|
|
2000
2072
|
requestOptions.path = '/' + parts.splice(1).join('/');
|
|
2001
|
-
|
|
2002
|
-
|
|
2073
|
+
|
|
2074
|
+
|
|
2003
2075
|
// extension and mime
|
|
2004
|
-
var filename = url.split(/\//g).pop();
|
|
2076
|
+
var filename = url.split(/\//g).pop();
|
|
2005
2077
|
if (!filename) {
|
|
2006
2078
|
self.throwError(local.res, 500, new Error('Filename not found in url: `'+ url +'`'));
|
|
2007
2079
|
return;
|
|
2008
2080
|
}
|
|
2009
|
-
|
|
2010
|
-
|
|
2081
|
+
|
|
2082
|
+
|
|
2011
2083
|
if ( !/\.\w+$/.test(filename) ) {
|
|
2012
2084
|
self.throwError(local.res, 500, new Error('[ '+ filename +' ] extension not found.'));
|
|
2013
2085
|
return;
|
|
2014
2086
|
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2087
|
+
|
|
2088
|
+
|
|
2017
2089
|
// filename renaming
|
|
2018
2090
|
if (opt.file)
|
|
2019
2091
|
filename = opt.file;
|
|
2020
|
-
|
|
2092
|
+
|
|
2021
2093
|
if ( opt.contentDisposition == 'attachment') {
|
|
2022
2094
|
opt.contentDisposition += '; filename=' + filename;
|
|
2023
2095
|
}
|
|
2024
|
-
|
|
2096
|
+
|
|
2025
2097
|
var ext = filename.match(/\.\w+$/)[0].substr(1)
|
|
2026
2098
|
, contentType = null
|
|
2027
2099
|
, tmp = _(GINA_TMPDIR +'/'+ filename, true)
|
|
2028
2100
|
;
|
|
2029
|
-
|
|
2101
|
+
|
|
2030
2102
|
if ( typeof(local.options.conf.server.coreConfiguration.mime[ext]) != 'undefined' ) {
|
|
2031
2103
|
|
|
2032
2104
|
contentType = (opt.contentType != defaultOptions.contentType) ? opt.contentType : local.options.conf.server.coreConfiguration.mime[ext];
|
|
2033
|
-
|
|
2105
|
+
|
|
2034
2106
|
} else { // extension not supported
|
|
2035
2107
|
self.throwError(local.res, 500, new Error('[ '+ ext +' ] Extension not supported. Ref.: gina/core mime.types'));
|
|
2036
2108
|
return;
|
|
2037
2109
|
}
|
|
2038
|
-
|
|
2110
|
+
|
|
2039
2111
|
// defining responseType
|
|
2040
2112
|
requestOptions.headers['content-type'] = contentType;
|
|
2041
2113
|
requestOptions.headers['content-disposition'] = opt.contentDisposition;
|
|
2042
|
-
|
|
2114
|
+
|
|
2043
2115
|
var browser = require(''+ scheme);
|
|
2044
2116
|
//console.debug('requestOptions: \n', JSON.stringify(requestOptions, null, 4));
|
|
2045
|
-
|
|
2046
|
-
browser.get(requestOptions, function(response) {
|
|
2047
|
-
|
|
2048
|
-
local.res.setHeader('content-type', contentType + '; charset='+ local.options.conf.encoding);
|
|
2049
|
-
local.res.setHeader('content-disposition', opt.contentDisposition);
|
|
2050
|
-
if (opt.fileSize) {
|
|
2051
|
-
local.res.setHeader('content-length', opt.fileSize);
|
|
2052
|
-
}
|
|
2053
|
-
//local.res.setHeader('content-length', opt.fileSize);
|
|
2054
|
-
// local.res.setHeader('cache-control', 'must-revalidate');
|
|
2055
|
-
// local.res.setHeader('pragma', 'must-revalidate');
|
|
2056
|
-
|
|
2057
|
-
// response.on('end', function onResponsePipeEnd(){
|
|
2058
|
-
// self.renderJSON({ url: url});
|
|
2059
|
-
// //local.res.end( Buffer.from(data) );
|
|
2060
|
-
// //local.res.headersSent = true;
|
|
2061
|
-
|
|
2062
|
-
// // if ( typeof(local.next) != 'undefined')
|
|
2063
|
-
// // local.next();
|
|
2064
|
-
// // else
|
|
2065
|
-
// // return;
|
|
2066
|
-
// });
|
|
2067
|
-
|
|
2068
|
-
response.pipe(local.res);
|
|
2069
|
-
});
|
|
2070
|
-
|
|
2071
|
-
return;
|
|
2072
2117
|
|
|
2118
|
+
browser
|
|
2119
|
+
.get(requestOptions, function(response) {
|
|
2120
|
+
|
|
2121
|
+
local.res.setHeader('content-type', contentType + '; charset='+ local.options.conf.encoding);
|
|
2122
|
+
local.res.setHeader('content-disposition', opt.contentDisposition);
|
|
2123
|
+
if (opt.fileSize) {
|
|
2124
|
+
local.res.setHeader('content-length', opt.fileSize);
|
|
2125
|
+
}
|
|
2126
|
+
//local.res.setHeader('content-length', opt.fileSize);
|
|
2127
|
+
// local.res.setHeader('cache-control', 'must-revalidate');
|
|
2128
|
+
// local.res.setHeader('pragma', 'must-revalidate');
|
|
2129
|
+
|
|
2130
|
+
|
|
2131
|
+
response.pipe(local.res);
|
|
2132
|
+
})
|
|
2133
|
+
.on('error', function onDownloadError(err) {
|
|
2134
|
+
self.throwError(local.res, 500, err);
|
|
2135
|
+
});
|
|
2136
|
+
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
// Will trigger on frontend : Failed to load resource: Frame load interrupted
|
|
2140
|
+
// because there is no `res.end()`: whitch is normal, we want to stay on the referrer page
|
|
2141
|
+
|
|
2142
|
+
// To avoid this, add to your download link the attribute `data-gina-link`
|
|
2143
|
+
// This will convert the regular HTTP Request to an XML Request
|
|
2073
2144
|
}
|
|
2074
2145
|
|
|
2075
|
-
|
|
2146
|
+
|
|
2076
2147
|
/**
|
|
2077
2148
|
* Download to targeted filename.ext - Will create target if new
|
|
2078
2149
|
* Use `cb` callback or `onComplete` event
|
|
2079
2150
|
*
|
|
2151
|
+
* - Will trigger on frontend : Failed to load resource: Frame load interrupted
|
|
2152
|
+
* because there is no `res.end()`: whitch is normal, we want to stay on the referrer page
|
|
2153
|
+
*
|
|
2154
|
+
* - To avoid this, add to your download link the attribute `data-gina-link`
|
|
2155
|
+
* This will convert the regular HTTP Request to an XML Request
|
|
2156
|
+
*
|
|
2080
2157
|
* @param {string} filename
|
|
2081
2158
|
* @param {object} options
|
|
2082
2159
|
**/
|
|
2083
2160
|
this.downloadFromLocal = function(filename) {
|
|
2084
|
-
|
|
2085
|
-
var file = filename.split(/\//g).pop();
|
|
2161
|
+
|
|
2162
|
+
var file = filename.split(/\//g).pop();
|
|
2086
2163
|
var ext = file.split(/\./g).pop()
|
|
2087
2164
|
, contentType = null
|
|
2088
2165
|
;
|
|
2089
|
-
|
|
2166
|
+
|
|
2090
2167
|
if ( typeof(local.options.conf.server.coreConfiguration.mime[ext]) != 'undefined' ) {
|
|
2091
2168
|
|
|
2092
2169
|
contentType = local.options.conf.server.coreConfiguration.mime[ext];
|
|
2093
2170
|
local.res.setHeader('content-type', contentType);
|
|
2094
|
-
local.res.setHeader('content-disposition', 'attachment; filename=' + file);
|
|
2171
|
+
local.res.setHeader('content-disposition', 'attachment; filename=' + file);
|
|
2095
2172
|
|
|
2096
2173
|
var filestream = fs.createReadStream(filename);
|
|
2097
2174
|
filestream.pipe(local.res);
|
|
@@ -2099,7 +2176,7 @@ function SuperController(options) {
|
|
|
2099
2176
|
} else { // extension not supported
|
|
2100
2177
|
self.throwError(local.res, 500, new Error('[ '+ ext +' ] Extension not supported. Ref.: gina/core mime.types'));
|
|
2101
2178
|
return;
|
|
2102
|
-
}
|
|
2179
|
+
}
|
|
2103
2180
|
}
|
|
2104
2181
|
|
|
2105
2182
|
|
|
@@ -2122,17 +2199,17 @@ function SuperController(options) {
|
|
|
2122
2199
|
* */
|
|
2123
2200
|
this.store = async function(target, files, cb) {
|
|
2124
2201
|
|
|
2125
|
-
|
|
2202
|
+
|
|
2126
2203
|
var start = function(target, files, cb) {
|
|
2127
|
-
|
|
2204
|
+
|
|
2128
2205
|
if (arguments.length == 2 && typeof(arguments[1]) == 'function' ) {
|
|
2129
2206
|
var cb = arguments[1];
|
|
2130
2207
|
}
|
|
2131
|
-
|
|
2208
|
+
|
|
2132
2209
|
if ( typeof(files) == 'undefined' || typeof(files) == 'function' ) {
|
|
2133
2210
|
files = local.req.files
|
|
2134
2211
|
}
|
|
2135
|
-
|
|
2212
|
+
|
|
2136
2213
|
var uploadedFiles = [];
|
|
2137
2214
|
|
|
2138
2215
|
if ( typeof(files) == 'undefined' || files.count() == 0 ) {
|
|
@@ -2155,25 +2232,25 @@ function SuperController(options) {
|
|
|
2155
2232
|
self.emit('uploaded', folder)
|
|
2156
2233
|
}
|
|
2157
2234
|
} else {
|
|
2158
|
-
// files list
|
|
2159
|
-
var fileName = null;
|
|
2235
|
+
// files list
|
|
2236
|
+
var fileName = null;
|
|
2160
2237
|
for (var len = files.length; i < len; ++i ){
|
|
2161
|
-
|
|
2162
|
-
fileName = files[i].filename ||
|
|
2163
|
-
|
|
2238
|
+
|
|
2239
|
+
fileName = files[i].filename || files[i].originalFilename
|
|
2240
|
+
|
|
2164
2241
|
list[i] = {
|
|
2165
2242
|
source: files[i].path,
|
|
2166
2243
|
target: _(uploadDir.toString() + '/' + fileName)
|
|
2167
2244
|
};
|
|
2168
|
-
|
|
2169
|
-
uploadedFiles[i] = {
|
|
2245
|
+
|
|
2246
|
+
uploadedFiles[i] = {
|
|
2170
2247
|
file : fileName,
|
|
2171
|
-
filename : list[i].target,
|
|
2248
|
+
filename : list[i].target,
|
|
2172
2249
|
size : files[i].size,
|
|
2173
2250
|
type : files[i].type,
|
|
2174
2251
|
encoding : files[i].encoding
|
|
2175
2252
|
};
|
|
2176
|
-
|
|
2253
|
+
|
|
2177
2254
|
}
|
|
2178
2255
|
|
|
2179
2256
|
movefiles(0, local.res, list, function (err) {
|
|
@@ -2279,7 +2356,7 @@ function SuperController(options) {
|
|
|
2279
2356
|
} while (cert.fingerprint256 !== lastprint256);
|
|
2280
2357
|
|
|
2281
2358
|
}*/
|
|
2282
|
-
|
|
2359
|
+
|
|
2283
2360
|
};
|
|
2284
2361
|
|
|
2285
2362
|
this.query = function() { // options, data, callback
|
|
@@ -2293,7 +2370,7 @@ function SuperController(options) {
|
|
|
2293
2370
|
data = arguments[arguments.length-1]
|
|
2294
2371
|
}
|
|
2295
2372
|
// preventing multiple call of self.query() when controller is rendering from another required controller
|
|
2296
|
-
if (
|
|
2373
|
+
if (
|
|
2297
2374
|
typeof(local.options) != 'undefined'
|
|
2298
2375
|
&& typeof(local.options.renderingStack) != 'undefined'
|
|
2299
2376
|
&& local.options.renderingStack.length > 1
|
|
@@ -2301,22 +2378,22 @@ function SuperController(options) {
|
|
|
2301
2378
|
return false
|
|
2302
2379
|
}
|
|
2303
2380
|
self.isProcessingError = false; // by default
|
|
2304
|
-
|
|
2381
|
+
|
|
2305
2382
|
var queryData = {}
|
|
2306
2383
|
, defaultOptions = local.query.options
|
|
2307
2384
|
, path = options.path
|
|
2308
|
-
, browser = null
|
|
2385
|
+
, browser = null
|
|
2309
2386
|
;
|
|
2310
2387
|
|
|
2311
2388
|
// options must be used as a copy in case of multiple calls of self.query(options, ...)
|
|
2312
2389
|
options = merge(JSON.clone(options), defaultOptions);
|
|
2313
|
-
|
|
2390
|
+
|
|
2314
2391
|
for (var o in options) {//cleaning
|
|
2315
2392
|
if ( typeof(options[o]) == 'undefined' || options[o] == undefined) {
|
|
2316
2393
|
delete options[o]
|
|
2317
2394
|
}
|
|
2318
2395
|
}
|
|
2319
|
-
|
|
2396
|
+
|
|
2320
2397
|
if (self.isCacheless() || self.isLocalScope() ) {
|
|
2321
2398
|
options.rejectUnauthorized = false;
|
|
2322
2399
|
}
|
|
@@ -2329,23 +2406,14 @@ function SuperController(options) {
|
|
|
2329
2406
|
self.emit('query#complete', err)
|
|
2330
2407
|
}
|
|
2331
2408
|
|
|
2332
|
-
|
|
2333
2409
|
|
|
2334
|
-
// if (arguments.length <3) {
|
|
2335
|
-
// if ( typeof(data) == 'function') {
|
|
2336
|
-
// var callback = data;
|
|
2337
|
-
// var data = undefined;
|
|
2338
|
-
// } else {
|
|
2339
|
-
// callback = undefined;
|
|
2340
|
-
// }
|
|
2341
|
-
// }
|
|
2342
2410
|
if ( typeof(data) != 'undefined' && data.count() > 0) {
|
|
2343
2411
|
|
|
2344
2412
|
queryData = '?';
|
|
2345
2413
|
// TODO - if 'application/json' && method == (put|post)
|
|
2346
2414
|
if ( ['put', 'post'].indexOf(options.method.toLowerCase()) >-1 && /(text\/plain|application\/json|application\/x\-www\-form)/i.test(options.headers['content-type']) ) {
|
|
2347
2415
|
// replacing
|
|
2348
|
-
queryData =
|
|
2416
|
+
queryData = encodeRFC5987ValueChars(JSON.stringify(data))
|
|
2349
2417
|
//queryData = JSON.stringify(data)
|
|
2350
2418
|
|
|
2351
2419
|
} else {
|
|
@@ -2357,12 +2425,12 @@ function SuperController(options) {
|
|
|
2357
2425
|
if ( typeof(tmpData[d]) == 'object') {
|
|
2358
2426
|
tmpData[d] = JSON.stringify(tmpData[d]);
|
|
2359
2427
|
}
|
|
2360
|
-
queryData += d + '=' +
|
|
2428
|
+
queryData += d + '=' + encodeRFC5987ValueChars(tmpData[d]) + '&';
|
|
2361
2429
|
}
|
|
2362
2430
|
|
|
2363
2431
|
queryData = queryData.substring(0, queryData.length-1);
|
|
2364
2432
|
queryData = queryData.replace(/\s/g, '%20');
|
|
2365
|
-
|
|
2433
|
+
|
|
2366
2434
|
options.path += queryData;
|
|
2367
2435
|
}
|
|
2368
2436
|
|
|
@@ -2370,7 +2438,7 @@ function SuperController(options) {
|
|
|
2370
2438
|
queryData = ''
|
|
2371
2439
|
}
|
|
2372
2440
|
|
|
2373
|
-
|
|
2441
|
+
|
|
2374
2442
|
// Internet Explorer override
|
|
2375
2443
|
if ( local.req != null && /msie/i.test(local.req.headers['user-agent']) ) {
|
|
2376
2444
|
options.headers['content-type'] = 'text/plain';
|
|
@@ -2389,7 +2457,7 @@ function SuperController(options) {
|
|
|
2389
2457
|
|
|
2390
2458
|
//you need this, even when empty.
|
|
2391
2459
|
options.headers['content-length'] = queryData.length;
|
|
2392
|
-
|
|
2460
|
+
|
|
2393
2461
|
// adding gina headers
|
|
2394
2462
|
if ( local.req != null && typeof(local.req.ginaHeaders) != 'undefined' ) {
|
|
2395
2463
|
// gina form headers
|
|
@@ -2405,7 +2473,7 @@ function SuperController(options) {
|
|
|
2405
2473
|
;
|
|
2406
2474
|
// cleanup options.path
|
|
2407
2475
|
if (/\:\/\//.test(options.path)) {
|
|
2408
|
-
|
|
2476
|
+
|
|
2409
2477
|
var hArr = options.path.split(/^(https|http)\:\/\//);
|
|
2410
2478
|
var domain = hArr[1] +'://';
|
|
2411
2479
|
var host = hArr[2].split(/\//)[0];
|
|
@@ -2417,72 +2485,84 @@ function SuperController(options) {
|
|
|
2417
2485
|
.replace(options.host, '')
|
|
2418
2486
|
.replace(':'+port, '');
|
|
2419
2487
|
}
|
|
2420
|
-
|
|
2488
|
+
|
|
2421
2489
|
// retrieve protocol & scheme: if empty, take the bundles protocol
|
|
2422
2490
|
protocol = options.protocol || ctx.gina.config.envConf[ctx.bundle][ctx.env].server.protocol;// bundle servers's protocol by default
|
|
2423
2491
|
protocol = protocol.match(/[.a-z 0-9]+/ig)[0];
|
|
2424
2492
|
scheme = options.scheme || ctx.gina.config.envConf[ctx.bundle][ctx.env].server.scheme;// bundle servers's scheme by default
|
|
2425
2493
|
scheme = scheme.match(/[a-z 0-9]+/ig)[0];
|
|
2426
|
-
|
|
2494
|
+
// retrieve credentials
|
|
2495
|
+
if ( typeof(options.ca) == 'undefined' || ! options.ca ) {
|
|
2496
|
+
options.ca = ctx.gina.config.envConf[ctx.bundle][ctx.env].server.credentials.ca;
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2427
2499
|
//retrieving dynamic host, hostname & port
|
|
2428
2500
|
if ( /\@/.test(options.hostname) ) {
|
|
2429
|
-
|
|
2501
|
+
|
|
2430
2502
|
var bundle = ( options.hostname.replace(/(.*)\:\/\//, '') ).split(/\@/)[0];
|
|
2431
|
-
|
|
2503
|
+
|
|
2432
2504
|
// No shorcut possible because conf.hostname might differ from user inputs
|
|
2433
2505
|
options.host = ctx.gina.config.envConf[bundle][ctx.env].host.replace(/(.*)\:\/\//, '').replace(/\:\d+/, '');
|
|
2434
2506
|
options.hostname = ctx.gina.config.envConf[bundle][ctx.env].hostname;
|
|
2435
2507
|
options.port = ctx.gina.config.envConf[bundle][ctx.env].server.port;
|
|
2436
|
-
|
|
2508
|
+
|
|
2437
2509
|
options.protocol = ctx.gina.config.envConf[bundle][ctx.env].server.protocol;
|
|
2438
2510
|
options.scheme = ctx.gina.config.envConf[bundle][ctx.env].server.scheme;
|
|
2511
|
+
|
|
2512
|
+
// retrieve credentials
|
|
2513
|
+
if ( typeof(options.ca) == 'undefined' || ! options.ca ) {
|
|
2514
|
+
options.ca = ctx.gina.config.envConf[bundle][ctx.env].server.credentials.ca;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2439
2517
|
// might be != from the bundle requesting
|
|
2440
|
-
//options.protocol = ctx.gina.config.envConf[bundle][ctx.env].content.settings.server.protocol ||
|
|
2441
|
-
//options.scheme = ctx.gina.config.envConf[bundle][ctx.env].content.settings.server.scheme ||
|
|
2518
|
+
//options.protocol = ctx.gina.config.envConf[bundle][ctx.env].content.settings.server.protocol || ctx.gina.config.envConf[bundle][ctx.env].server.protocol;
|
|
2519
|
+
//options.scheme = ctx.gina.config.envConf[bundle][ctx.env].content.settings.server.scheme || ctx.gina.config.envConf[bundle][ctx.env].server.scheme;
|
|
2442
2520
|
}
|
|
2443
|
-
|
|
2521
|
+
|
|
2444
2522
|
if ( typeof(options.protocol) == 'undefined' ) {
|
|
2445
2523
|
options.protocol = protocol
|
|
2446
2524
|
}
|
|
2447
2525
|
if ( typeof(options.scheme) == 'undefined' ) {
|
|
2448
2526
|
options.scheme = scheme
|
|
2449
2527
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2528
|
+
|
|
2529
|
+
|
|
2530
|
+
|
|
2531
|
+
|
|
2452
2532
|
// reformating scheme
|
|
2453
2533
|
if( !/\:$/.test(options.scheme) )
|
|
2454
2534
|
options.scheme += ':';
|
|
2455
|
-
|
|
2456
|
-
try {
|
|
2457
|
-
options.queryData = queryData;
|
|
2535
|
+
|
|
2536
|
+
try {
|
|
2537
|
+
options.queryData = queryData;
|
|
2458
2538
|
var protocolVersion = ~~options.protocol.match(/\/(.*)$/)[1].replace(/\.\d+/, '');
|
|
2459
2539
|
var httpLib = options.protocol.match(/^(.*)\//)[1] + ( (protocolVersion >= 2) ? protocolVersion : '' );
|
|
2460
2540
|
if ( !/http2/.test(httpLib) && /https/.test(options.scheme) ) {
|
|
2461
2541
|
httpLib += 's';
|
|
2462
2542
|
}
|
|
2463
|
-
|
|
2464
|
-
browser = require(''+ httpLib);
|
|
2465
|
-
|
|
2543
|
+
|
|
2544
|
+
browser = require(''+ httpLib);
|
|
2545
|
+
|
|
2466
2546
|
if ( /http2/.test(httpLib) ) {
|
|
2467
2547
|
return handleHTTP2ClientRequest(browser, options, callback);
|
|
2468
2548
|
} else {
|
|
2469
|
-
return handleHTTP1ClientRequest(browser, options, callback);
|
|
2470
|
-
}
|
|
2471
|
-
|
|
2472
|
-
|
|
2549
|
+
return handleHTTP1ClientRequest(browser, options, callback);
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
|
|
2473
2553
|
} catch(err) {
|
|
2474
2554
|
if (callback) {
|
|
2475
2555
|
return callback(err)
|
|
2476
2556
|
}
|
|
2477
2557
|
self.emit('query#complete', err)
|
|
2478
2558
|
}
|
|
2479
|
-
|
|
2559
|
+
|
|
2480
2560
|
}
|
|
2481
|
-
|
|
2561
|
+
|
|
2482
2562
|
var handleHTTP1ClientRequest = function(browser, options, callback) {
|
|
2483
|
-
|
|
2563
|
+
|
|
2484
2564
|
var altOpt = JSON.clone(options);
|
|
2485
|
-
|
|
2565
|
+
|
|
2486
2566
|
altOpt.protocol = options.scheme;
|
|
2487
2567
|
altOpt.hostname = options.host;
|
|
2488
2568
|
altOpt.port = options.port;
|
|
@@ -2492,24 +2572,24 @@ function SuperController(options) {
|
|
|
2492
2572
|
} catch(err) {
|
|
2493
2573
|
self.emit('query#complete', err);
|
|
2494
2574
|
}
|
|
2495
|
-
|
|
2575
|
+
|
|
2496
2576
|
} else {
|
|
2497
2577
|
console.warn('[ CONTROLLER ][ HTTP/1.0#query ] options.encKey not found !');
|
|
2498
2578
|
}
|
|
2499
|
-
|
|
2579
|
+
|
|
2500
2580
|
if ( typeof(altOpt.encCert) != 'undefined' ) {
|
|
2501
2581
|
try {
|
|
2502
2582
|
altOpt.encCert = fs.readFileSync(options.encCert);
|
|
2503
2583
|
} catch(err) {
|
|
2504
2584
|
self.emit('query#complete', err);
|
|
2505
2585
|
}
|
|
2506
|
-
|
|
2586
|
+
|
|
2507
2587
|
} else {
|
|
2508
2588
|
console.warn('[ CONTROLLER ][ HTTP/1.0#query ] options.encCert not found !');
|
|
2509
2589
|
}
|
|
2510
|
-
|
|
2590
|
+
|
|
2511
2591
|
altOpt.agent = new browser.Agent(altOpt);
|
|
2512
|
-
|
|
2592
|
+
|
|
2513
2593
|
var req = browser.request(altOpt, function(res) {
|
|
2514
2594
|
|
|
2515
2595
|
res.setEncoding('utf8');
|
|
@@ -2526,24 +2606,24 @@ function SuperController(options) {
|
|
|
2526
2606
|
});
|
|
2527
2607
|
|
|
2528
2608
|
res.on('end', function onEnd(err) {
|
|
2529
|
-
|
|
2530
|
-
|
|
2609
|
+
|
|
2610
|
+
|
|
2531
2611
|
// exceptions filter
|
|
2532
2612
|
if ( typeof(data) == 'string' && /^Unknown ALPN Protocol/.test(data) ) {
|
|
2533
2613
|
err = {
|
|
2534
2614
|
status: 500,
|
|
2535
2615
|
error: new Error(data)
|
|
2536
2616
|
};
|
|
2537
|
-
|
|
2617
|
+
|
|
2538
2618
|
if ( typeof(callback) != 'undefined' ) {
|
|
2539
2619
|
callback(err)
|
|
2540
2620
|
} else {
|
|
2541
2621
|
self.emit('query#complete', err)
|
|
2542
2622
|
}
|
|
2543
|
-
|
|
2623
|
+
|
|
2544
2624
|
return
|
|
2545
2625
|
}
|
|
2546
|
-
|
|
2626
|
+
|
|
2547
2627
|
//Only when needed.
|
|
2548
2628
|
if ( typeof(callback) != 'undefined' ) {
|
|
2549
2629
|
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)|\[\]/.test(data) ) {
|
|
@@ -2573,7 +2653,7 @@ function SuperController(options) {
|
|
|
2573
2653
|
exception.status = 500;
|
|
2574
2654
|
self.throwError(exception);
|
|
2575
2655
|
return;
|
|
2576
|
-
}
|
|
2656
|
+
}
|
|
2577
2657
|
|
|
2578
2658
|
} else {
|
|
2579
2659
|
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)|\[\]/.test(data) ) {
|
|
@@ -2600,14 +2680,14 @@ function SuperController(options) {
|
|
|
2600
2680
|
|
|
2601
2681
|
//starting from from >0.10.15
|
|
2602
2682
|
req.on('error', function onError(err) {
|
|
2603
|
-
|
|
2604
|
-
|
|
2683
|
+
|
|
2684
|
+
|
|
2605
2685
|
if (
|
|
2606
|
-
typeof(err.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(err.code)
|
|
2607
|
-
||
|
|
2686
|
+
typeof(err.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(err.code)
|
|
2687
|
+
|| typeof(err.cause) != 'undefined' && typeof(err.cause.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(err.cause.code)
|
|
2608
2688
|
) {
|
|
2609
2689
|
|
|
2610
|
-
var port = getContext('gina').ports[options.protocol][options.scheme.replace(/\:/, '')][ options.port ];//err.port || err.cause.port
|
|
2690
|
+
var port = getContext('gina').ports[options.protocol][options.scheme.replace(/\:/, '')][ options.port ];//err.port || err.cause.port
|
|
2611
2691
|
if ( typeof(port) != 'undefined' ) {
|
|
2612
2692
|
err.accessPoint = port;
|
|
2613
2693
|
err.message = '`Controller::query()` could not connect to [ ' + err.accessPoint + ' ] using port '+options.port+'.\n';
|
|
@@ -2626,7 +2706,7 @@ function SuperController(options) {
|
|
|
2626
2706
|
} else {
|
|
2627
2707
|
var error = {
|
|
2628
2708
|
status : 500,
|
|
2629
|
-
error : err.stack ||
|
|
2709
|
+
error : err.stack || err.message
|
|
2630
2710
|
};
|
|
2631
2711
|
|
|
2632
2712
|
self.emit('query#complete', error)
|
|
@@ -2667,30 +2747,30 @@ function SuperController(options) {
|
|
|
2667
2747
|
exception.status = 500;
|
|
2668
2748
|
self.throwError(exception);
|
|
2669
2749
|
return;
|
|
2670
|
-
}
|
|
2750
|
+
}
|
|
2671
2751
|
})
|
|
2672
2752
|
}
|
|
2673
|
-
|
|
2753
|
+
|
|
2674
2754
|
}
|
|
2675
2755
|
}
|
|
2676
|
-
|
|
2756
|
+
|
|
2677
2757
|
var handleHTTP2ClientRequest = function(browser, options, callback) {
|
|
2678
|
-
|
|
2679
|
-
//cleanup
|
|
2758
|
+
|
|
2759
|
+
//cleanup
|
|
2680
2760
|
options[':authority'] = options.hostname;
|
|
2681
|
-
|
|
2761
|
+
|
|
2682
2762
|
delete options.host;
|
|
2683
|
-
|
|
2763
|
+
|
|
2684
2764
|
if ( typeof(options[':path']) == 'undefined' ) {
|
|
2685
2765
|
options[':path'] = options.path;
|
|
2686
2766
|
delete options.path;
|
|
2687
|
-
}
|
|
2767
|
+
}
|
|
2688
2768
|
if ( typeof(options[':method']) == 'undefined' ) {
|
|
2689
2769
|
options[':method'] = options.method.toUpperCase();
|
|
2690
2770
|
delete options.method;
|
|
2691
2771
|
}
|
|
2692
|
-
|
|
2693
|
-
// only if binary !!
|
|
2772
|
+
|
|
2773
|
+
// only if binary !!
|
|
2694
2774
|
// if ( typeof(options['content-length']) == 'undefined' ) {
|
|
2695
2775
|
// options['content-length'] = options.headers['content-length'] ;
|
|
2696
2776
|
// delete options.headers['content-length'];
|
|
@@ -2699,11 +2779,11 @@ function SuperController(options) {
|
|
|
2699
2779
|
// options['content-type'] = options.headers['content-type'] ;
|
|
2700
2780
|
// delete options.headers['content-type'];
|
|
2701
2781
|
// }
|
|
2702
|
-
|
|
2782
|
+
|
|
2703
2783
|
if ( typeof(options[':scheme']) == 'undefined' ) {
|
|
2704
2784
|
options[':scheme'] = options.scheme ;
|
|
2705
2785
|
}
|
|
2706
|
-
|
|
2786
|
+
|
|
2707
2787
|
if ( typeof(options.ca) != 'undefined' ) {
|
|
2708
2788
|
try {
|
|
2709
2789
|
options.ca = fs.readFileSync(options.ca);
|
|
@@ -2713,58 +2793,58 @@ function SuperController(options) {
|
|
|
2713
2793
|
} else {
|
|
2714
2794
|
self.emit('query#complete', err);
|
|
2715
2795
|
}
|
|
2716
|
-
|
|
2796
|
+
|
|
2717
2797
|
return;
|
|
2718
2798
|
}
|
|
2719
|
-
|
|
2799
|
+
|
|
2720
2800
|
} else {
|
|
2721
2801
|
console.warn('[ CONTROLLER ][ HTTP/2.0#query ] options.ca not found !');
|
|
2722
2802
|
}
|
|
2723
|
-
|
|
2724
|
-
|
|
2803
|
+
|
|
2804
|
+
|
|
2725
2805
|
var body = Buffer.from(options.queryData);
|
|
2726
|
-
options.headers['content-length'] = body.length;
|
|
2806
|
+
options.headers['content-length'] = body.length;
|
|
2727
2807
|
delete options.queryData;
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
const client = browser.connect(options.hostname, options);
|
|
2732
|
-
|
|
2733
|
-
|
|
2808
|
+
|
|
2809
|
+
|
|
2810
|
+
|
|
2811
|
+
const client = browser.connect(options.hostname, options);
|
|
2812
|
+
|
|
2813
|
+
|
|
2734
2814
|
const {
|
|
2735
2815
|
HTTP2_HEADER_PROTOCOL,
|
|
2736
|
-
HTTP2_HEADER_SCHEME,
|
|
2816
|
+
HTTP2_HEADER_SCHEME,
|
|
2737
2817
|
HTTP2_HEADER_AUTHORITY,
|
|
2738
2818
|
HTTP2_HEADER_PATH,
|
|
2739
2819
|
HTTP2_HEADER_METHOD,
|
|
2740
2820
|
HTTP2_HEADER_STATUS
|
|
2741
2821
|
} = browser.constants;
|
|
2742
|
-
|
|
2743
|
-
|
|
2822
|
+
|
|
2823
|
+
|
|
2744
2824
|
if ( typeof(local.req.headers['x-requested-with']) != 'undefined' ) {
|
|
2745
2825
|
options.headers['x-requested-with'] = local.req.headers['x-requested-with']
|
|
2746
2826
|
}
|
|
2747
|
-
|
|
2827
|
+
|
|
2748
2828
|
if ( typeof(local.req.headers['access-control-allow-credentials']) != 'undefined' ) {
|
|
2749
2829
|
options.headers['access-control-allow-credentials'] = local.req.headers['access-control-allow-credentials']
|
|
2750
2830
|
}
|
|
2751
|
-
|
|
2831
|
+
|
|
2752
2832
|
if ( typeof(local.req.headers['content-type']) != 'undefined' && local.req.headers['content-type'] != options.headers['content-type'] ) {
|
|
2753
2833
|
options.headers['content-type'] = local.req.headers['content-type']
|
|
2754
2834
|
}
|
|
2755
|
-
|
|
2756
|
-
var headers = merge({
|
|
2835
|
+
|
|
2836
|
+
var headers = merge({
|
|
2757
2837
|
[HTTP2_HEADER_METHOD]: options[':method'],
|
|
2758
|
-
[HTTP2_HEADER_PATH]: options[':path']
|
|
2838
|
+
[HTTP2_HEADER_PATH]: options[':path']
|
|
2759
2839
|
}, options.headers);
|
|
2760
|
-
|
|
2840
|
+
|
|
2761
2841
|
// merging with user options
|
|
2762
2842
|
for (var o in options) {
|
|
2763
2843
|
if (!/^\:/.test(o) && !/headers/.test(o) && typeof(headers[o]) == 'undefined' ) {
|
|
2764
2844
|
headers[o] = options[o]
|
|
2765
2845
|
}
|
|
2766
2846
|
}
|
|
2767
|
-
|
|
2847
|
+
|
|
2768
2848
|
/**
|
|
2769
2849
|
* sessionOptions
|
|
2770
2850
|
* endStream <boolean> true if the Http2Stream writable side should be closed initially, such as when sending a GET request that should not expect a payload body.
|
|
@@ -2778,55 +2858,55 @@ function SuperController(options) {
|
|
|
2778
2858
|
endStream = false;
|
|
2779
2859
|
sessionOptions.endStream = endStream;
|
|
2780
2860
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2861
|
+
|
|
2862
|
+
|
|
2783
2863
|
client.on('error', (error) => {
|
|
2784
|
-
|
|
2864
|
+
|
|
2785
2865
|
console.error( '`'+ options[':path']+ '` : '+ error.stack||error.message);
|
|
2786
|
-
if (
|
|
2787
|
-
typeof(error.cause) != 'undefined' && typeof(error.cause.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(error.cause.code)
|
|
2788
|
-
|| /ECONNREFUSED|ECONNRESET/.test(error.code)
|
|
2866
|
+
if (
|
|
2867
|
+
typeof(error.cause) != 'undefined' && typeof(error.cause.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(error.cause.code)
|
|
2868
|
+
|| /ECONNREFUSED|ECONNRESET/.test(error.code)
|
|
2789
2869
|
) {
|
|
2790
|
-
|
|
2870
|
+
|
|
2791
2871
|
var port = getContext('gina').ports[options.protocol][options.scheme.replace(/\:/, '')][ options.port ];
|
|
2792
2872
|
if ( typeof(port) != 'undefined' ) {
|
|
2793
2873
|
error.accessPoint = port;
|
|
2794
2874
|
error.message = 'Could not connect to [ ' + error.accessPoint + ' ].\nThe `'+port.split(/\@/)[0]+'` bundle is offline or unreachable.\n';
|
|
2795
|
-
}
|
|
2875
|
+
}
|
|
2796
2876
|
}
|
|
2797
2877
|
self.throwError(error);
|
|
2798
2878
|
return;
|
|
2799
2879
|
});
|
|
2800
|
-
|
|
2880
|
+
|
|
2801
2881
|
client.on('connect', () => {
|
|
2802
|
-
|
|
2882
|
+
|
|
2803
2883
|
var req = client.request( headers, sessionOptions );
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
// req.on('response', function onQueryResponse(headers, flags) {
|
|
2884
|
+
|
|
2885
|
+
|
|
2886
|
+
// req.on('response', function onQueryResponse(headers, flags) {
|
|
2807
2887
|
// for (const name in headers) {
|
|
2808
2888
|
// console.debug(`${name}: ${headers[name]}`);
|
|
2809
2889
|
// }
|
|
2810
2890
|
// });
|
|
2811
|
-
|
|
2891
|
+
|
|
2812
2892
|
req.setEncoding('utf8');
|
|
2813
2893
|
var data = '';
|
|
2814
|
-
req.on('data', function onQueryDataChunk(chunk) {
|
|
2815
|
-
data += chunk;
|
|
2894
|
+
req.on('data', function onQueryDataChunk(chunk) {
|
|
2895
|
+
data += chunk;
|
|
2816
2896
|
});
|
|
2817
|
-
|
|
2897
|
+
|
|
2818
2898
|
req.on('error', function onQueryError(error) {
|
|
2819
2899
|
|
|
2820
|
-
if (
|
|
2821
|
-
typeof(error.cause) != 'undefined' && typeof(error.cause.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(error.cause.code)
|
|
2822
|
-
|| /ECONNREFUSED|ECONNRESET/.test(error.code)
|
|
2900
|
+
if (
|
|
2901
|
+
typeof(error.cause) != 'undefined' && typeof(error.cause.code) != 'undefined' && /ECONNREFUSED|ECONNRESET/.test(error.cause.code)
|
|
2902
|
+
|| /ECONNREFUSED|ECONNRESET/.test(error.code)
|
|
2823
2903
|
) {
|
|
2824
|
-
|
|
2904
|
+
|
|
2825
2905
|
var port = getContext('gina').ports[options.protocol][options.scheme.replace(/\:/, '')][ options.port ];
|
|
2826
2906
|
if ( typeof(port) != 'undefined' ) {
|
|
2827
2907
|
error.accessPoint = port;
|
|
2828
2908
|
error.message = 'Could not connect to [ ' + error.accessPoint + ' ].\n' + error.message;
|
|
2829
|
-
}
|
|
2909
|
+
}
|
|
2830
2910
|
}
|
|
2831
2911
|
|
|
2832
2912
|
|
|
@@ -2834,7 +2914,7 @@ function SuperController(options) {
|
|
|
2834
2914
|
// you can get here if :
|
|
2835
2915
|
// - you are trying to query using: `enctype="multipart/form-data"`
|
|
2836
2916
|
// - server responded with an error
|
|
2837
|
-
if ( typeof(callback) != 'undefined' ) {
|
|
2917
|
+
if ( typeof(callback) != 'undefined' ) {
|
|
2838
2918
|
callback(error);
|
|
2839
2919
|
} else {
|
|
2840
2920
|
error = {
|
|
@@ -2844,28 +2924,28 @@ function SuperController(options) {
|
|
|
2844
2924
|
|
|
2845
2925
|
self.emit('query#complete', error)
|
|
2846
2926
|
}
|
|
2847
|
-
|
|
2927
|
+
|
|
2848
2928
|
return;
|
|
2849
2929
|
});
|
|
2850
|
-
|
|
2851
|
-
req.on('end', function onEnd() {
|
|
2852
|
-
|
|
2930
|
+
|
|
2931
|
+
req.on('end', function onEnd() {
|
|
2932
|
+
|
|
2853
2933
|
// exceptions filter
|
|
2854
2934
|
if ( typeof(data) == 'string' && /^Unknown ALPN Protocol/.test(data) ) {
|
|
2855
2935
|
var err = {
|
|
2856
2936
|
status: 500,
|
|
2857
2937
|
error: new Error(data)
|
|
2858
2938
|
};
|
|
2859
|
-
|
|
2939
|
+
|
|
2860
2940
|
if ( typeof(callback) != 'undefined' ) {
|
|
2861
2941
|
callback(err)
|
|
2862
2942
|
} else {
|
|
2863
2943
|
self.emit('query#complete', err)
|
|
2864
2944
|
}
|
|
2865
|
-
|
|
2945
|
+
|
|
2866
2946
|
return
|
|
2867
2947
|
}
|
|
2868
|
-
|
|
2948
|
+
|
|
2869
2949
|
//Only when needed.
|
|
2870
2950
|
if ( typeof(callback) != 'undefined' ) {
|
|
2871
2951
|
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)|\[\]/.test(data) ) {
|
|
@@ -2896,24 +2976,24 @@ function SuperController(options) {
|
|
|
2896
2976
|
if ( data.status && /^3/.test(data.status) && typeof(data.headers) != 'undefined' ) {
|
|
2897
2977
|
local.res.writeHead(data.status, data.headers);
|
|
2898
2978
|
return local.res.end();
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2901
2981
|
if ( data.status && !/^2/.test(data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.status]) != 'undefined' ) {
|
|
2902
2982
|
if ( /^5/.test(data.status) ) {
|
|
2903
|
-
return callback(data)
|
|
2983
|
+
return callback(data)
|
|
2904
2984
|
} else {
|
|
2905
2985
|
self.throwError(data);
|
|
2906
2986
|
return;
|
|
2907
|
-
}
|
|
2987
|
+
}
|
|
2908
2988
|
} else {
|
|
2909
2989
|
// required when control is used in an halted state
|
|
2910
2990
|
// Ref.: resumeRequest()
|
|
2911
2991
|
if ( self && self.isHaltedRequest() && typeof(local.onHaltedRequestResumed) != 'undefined' ) {
|
|
2912
2992
|
local.onHaltedRequestResumed(false);
|
|
2913
2993
|
}
|
|
2914
|
-
return callback( false, data )
|
|
2994
|
+
return callback( false, data )
|
|
2915
2995
|
}
|
|
2916
|
-
|
|
2996
|
+
|
|
2917
2997
|
} catch (e) {
|
|
2918
2998
|
var infos = local.options, controllerName = infos.controller.substr(infos.controller.lastIndexOf('/'));
|
|
2919
2999
|
var msg = 'Controller Query Exception while catching back.\nBundle: '+ infos.bundle +'\nController File: /controllers'+ controllerName +'\nControl: this.'+ infos.control +'(...)\n\r' + e.stack;
|
|
@@ -2921,8 +3001,8 @@ function SuperController(options) {
|
|
|
2921
3001
|
exception.status = 500;
|
|
2922
3002
|
self.throwError(exception);
|
|
2923
3003
|
return;
|
|
2924
|
-
}
|
|
2925
|
-
|
|
3004
|
+
}
|
|
3005
|
+
|
|
2926
3006
|
} else {
|
|
2927
3007
|
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)|\[\]/.test(data) ) {
|
|
2928
3008
|
try {
|
|
@@ -2935,13 +3015,13 @@ function SuperController(options) {
|
|
|
2935
3015
|
self.emit('query#complete', data)
|
|
2936
3016
|
}
|
|
2937
3017
|
}
|
|
2938
|
-
|
|
3018
|
+
|
|
2939
3019
|
// intercepting fallback redirect
|
|
2940
3020
|
if ( data.status && /^3/.test(data.status) && typeof(data.headers) != 'undefined' ) {
|
|
2941
3021
|
self.removeAllListeners(['query#complete']);
|
|
2942
3022
|
local.res.writeHead(data.status, data.headers);
|
|
2943
3023
|
return local.res.end();
|
|
2944
|
-
}
|
|
3024
|
+
}
|
|
2945
3025
|
|
|
2946
3026
|
if ( data.status && !/^2/.test(data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.status]) != 'undefined' ) {
|
|
2947
3027
|
self.emit('query#complete', data)
|
|
@@ -2953,22 +3033,22 @@ function SuperController(options) {
|
|
|
2953
3033
|
}
|
|
2954
3034
|
self.emit('query#complete', false, data)
|
|
2955
3035
|
}
|
|
2956
|
-
}
|
|
2957
|
-
|
|
3036
|
+
}
|
|
3037
|
+
|
|
2958
3038
|
client.close();
|
|
2959
3039
|
});
|
|
2960
|
-
|
|
3040
|
+
|
|
2961
3041
|
if (!endStream) {
|
|
2962
3042
|
req.end(body);
|
|
2963
3043
|
}
|
|
2964
3044
|
});
|
|
2965
|
-
|
|
2966
|
-
|
|
3045
|
+
|
|
3046
|
+
|
|
2967
3047
|
return {
|
|
2968
3048
|
onComplete : function(cb) {
|
|
2969
|
-
|
|
3049
|
+
|
|
2970
3050
|
self.once('query#complete', function(err, data){
|
|
2971
|
-
|
|
3051
|
+
|
|
2972
3052
|
if ( typeof(data) == 'string' && /^(\{|%7B|\[{)|\[\]/.test(data) ) {
|
|
2973
3053
|
try {
|
|
2974
3054
|
data = JSON.parse(data)
|
|
@@ -2979,7 +3059,7 @@ function SuperController(options) {
|
|
|
2979
3059
|
}
|
|
2980
3060
|
}
|
|
2981
3061
|
}
|
|
2982
|
-
|
|
3062
|
+
|
|
2983
3063
|
try {
|
|
2984
3064
|
if ( data.status && !/^2/.test(data.status) && typeof(local.options.conf.server.coreConfiguration.statusCodes[data.status]) != 'undefined') {
|
|
2985
3065
|
cb(data)
|
|
@@ -2989,7 +3069,7 @@ function SuperController(options) {
|
|
|
2989
3069
|
if ( self.isHaltedRequest() && typeof(local.onHaltedRequestResumed) != 'undefined' ) {
|
|
2990
3070
|
local.onHaltedRequestResumed(err);
|
|
2991
3071
|
}
|
|
2992
|
-
|
|
3072
|
+
|
|
2993
3073
|
cb(err, data)
|
|
2994
3074
|
}
|
|
2995
3075
|
} catch (e) {
|
|
@@ -2999,7 +3079,7 @@ function SuperController(options) {
|
|
|
2999
3079
|
exception.status = 500;
|
|
3000
3080
|
self.throwError(exception);
|
|
3001
3081
|
return;
|
|
3002
|
-
}
|
|
3082
|
+
}
|
|
3003
3083
|
})
|
|
3004
3084
|
}
|
|
3005
3085
|
}
|
|
@@ -3066,8 +3146,8 @@ function SuperController(options) {
|
|
|
3066
3146
|
}
|
|
3067
3147
|
|
|
3068
3148
|
req.getParam = function(name) {
|
|
3069
|
-
|
|
3070
|
-
var param = null;
|
|
3149
|
+
|
|
3150
|
+
var param = null;
|
|
3071
3151
|
switch( req.method.toLowerCase() ) {
|
|
3072
3152
|
case 'get':
|
|
3073
3153
|
param = req.get[name];
|
|
@@ -3089,24 +3169,24 @@ function SuperController(options) {
|
|
|
3089
3169
|
return param
|
|
3090
3170
|
}
|
|
3091
3171
|
}
|
|
3092
|
-
|
|
3172
|
+
|
|
3093
3173
|
/**
|
|
3094
|
-
* Forward request
|
|
3174
|
+
* Forward request
|
|
3095
3175
|
* Allowing x-bundle forward
|
|
3096
3176
|
* Attention: this is a work in progres, do not use it yet
|
|
3097
|
-
*
|
|
3098
|
-
* @param {object} req
|
|
3099
|
-
* @param {object} res
|
|
3100
|
-
* @param {callback} next
|
|
3101
|
-
* @returns
|
|
3177
|
+
*
|
|
3178
|
+
* @param {object} req
|
|
3179
|
+
* @param {object} res
|
|
3180
|
+
* @param {callback} next
|
|
3181
|
+
* @returns
|
|
3102
3182
|
*/
|
|
3103
3183
|
this.forward = function(req, res, next) {
|
|
3104
3184
|
var route = req.routing;
|
|
3105
3185
|
if ( typeof(route.param.url) == 'undefined' || /^(null|\s*)$/.test(route.param.url) ) {
|
|
3106
3186
|
self.throwError( new Error('`route.param.url` must be defiend in your route: `'+ route.rule +'`') );
|
|
3107
3187
|
return;
|
|
3108
|
-
}
|
|
3109
|
-
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3110
3190
|
var param = {};
|
|
3111
3191
|
for (let p in route.param) {
|
|
3112
3192
|
if ( /^(url|urlIndex|control|file|title|bundle|project|hostname|port|path|method)$/.test(p) ) {
|
|
@@ -3138,14 +3218,14 @@ function SuperController(options) {
|
|
|
3138
3218
|
port = route.param.port;
|
|
3139
3219
|
path = route.param.port;
|
|
3140
3220
|
}
|
|
3141
|
-
|
|
3221
|
+
|
|
3142
3222
|
var method = null;
|
|
3143
3223
|
if ( typeof(route.param.method) != 'undefined' ) {
|
|
3144
3224
|
method = route.param.method.toLowerCase();
|
|
3145
3225
|
} else {
|
|
3146
3226
|
method = req.method.toLowerCase();
|
|
3147
3227
|
}
|
|
3148
|
-
|
|
3228
|
+
|
|
3149
3229
|
var opt = {
|
|
3150
3230
|
ca: ca,
|
|
3151
3231
|
hostname: hostname,
|
|
@@ -3156,7 +3236,7 @@ function SuperController(options) {
|
|
|
3156
3236
|
if (self.isCacheless() || self.isLocalScope() ) {
|
|
3157
3237
|
opt.rejectUnauthorized = false;
|
|
3158
3238
|
}
|
|
3159
|
-
|
|
3239
|
+
|
|
3160
3240
|
var obj = req[ req.method.toLowerCase() ];
|
|
3161
3241
|
// if ( req.files != 'undefined' ) {
|
|
3162
3242
|
// obj.files = req.files;
|
|
@@ -3166,17 +3246,17 @@ function SuperController(options) {
|
|
|
3166
3246
|
self.throwError(err);
|
|
3167
3247
|
return;
|
|
3168
3248
|
}
|
|
3169
|
-
|
|
3249
|
+
|
|
3170
3250
|
// TODO - filter : redirect & location
|
|
3171
|
-
|
|
3172
|
-
// if ( self.isXMLRequest() ||
|
|
3251
|
+
|
|
3252
|
+
// if ( self.isXMLRequest() || !hasViews() || !local.options.isUsingTemplate && !hasViews() || hasViews() && !local.options.isUsingTemplate ) {
|
|
3173
3253
|
self.renderJSON(result)
|
|
3174
3254
|
// } else {
|
|
3175
3255
|
// self.render(result)
|
|
3176
|
-
// }
|
|
3256
|
+
// }
|
|
3177
3257
|
});
|
|
3178
3258
|
}
|
|
3179
|
-
|
|
3259
|
+
|
|
3180
3260
|
|
|
3181
3261
|
/**
|
|
3182
3262
|
* Get config
|
|
@@ -3206,6 +3286,7 @@ function SuperController(options) {
|
|
|
3206
3286
|
|
|
3207
3287
|
/**
|
|
3208
3288
|
* Get locales
|
|
3289
|
+
* Will take only supported lang
|
|
3209
3290
|
*
|
|
3210
3291
|
* @param {string} [shortCountryCode] - e.g. EN
|
|
3211
3292
|
*
|
|
@@ -3231,29 +3312,27 @@ function SuperController(options) {
|
|
|
3231
3312
|
/**
|
|
3232
3313
|
* Get countries list
|
|
3233
3314
|
*
|
|
3234
|
-
* @param {string} [code] - e.g.:
|
|
3315
|
+
* @param {string} [code] - e.g.: officialStateName, isoShort, isoLong, continent, capital, currency.name
|
|
3235
3316
|
*
|
|
3236
3317
|
* @returns {object} countries - countries code & value list
|
|
3237
3318
|
* */
|
|
3238
3319
|
var getCountries = function (code) {
|
|
3239
|
-
var list =
|
|
3320
|
+
var list = [], cde = 'countryName';
|
|
3240
3321
|
|
|
3241
3322
|
if ( typeof(code) != 'undefined' && typeof(userLocales[0][code]) == 'string' ) {
|
|
3242
3323
|
cde = code
|
|
3243
|
-
} else if ( typeof(code) != 'undefined' )
|
|
3324
|
+
} else if ( typeof(code) != 'undefined' ) {
|
|
3244
3325
|
console.warn('`'+ code +'` not supported : sticking with `short` code')
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
for ( var i = 0, len = userLocales.length; i< len; ++i ) {
|
|
3249
|
-
|
|
3250
|
-
if (userLocales[i][cde]) {
|
|
3326
|
+
}
|
|
3251
3327
|
|
|
3252
|
-
name = userLocales[i].officialName.short || userLocales[i].full;
|
|
3253
3328
|
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3329
|
+
for ( let i = 0, len = userLocales.length; i< len; ++i ) {
|
|
3330
|
+
list[ i ] = {
|
|
3331
|
+
isoShort: userLocales[i].isoShort,
|
|
3332
|
+
isoLong: userLocales[i].isoLong,
|
|
3333
|
+
countryName: userLocales[i].countryName,
|
|
3334
|
+
officialStateName: userLocales[i].officialStateName
|
|
3335
|
+
};
|
|
3257
3336
|
}
|
|
3258
3337
|
|
|
3259
3338
|
return list
|
|
@@ -3261,6 +3340,7 @@ function SuperController(options) {
|
|
|
3261
3340
|
|
|
3262
3341
|
return {
|
|
3263
3342
|
'getCountries': getCountries
|
|
3343
|
+
// TODO - getCurrencies()
|
|
3264
3344
|
}
|
|
3265
3345
|
}
|
|
3266
3346
|
|
|
@@ -3297,8 +3377,8 @@ function SuperController(options) {
|
|
|
3297
3377
|
} else {
|
|
3298
3378
|
rules = JSON.clone(local.options.conf.content.forms).rules[form.id] || null;
|
|
3299
3379
|
}
|
|
3300
|
-
|
|
3301
|
-
if (!rules) {
|
|
3380
|
+
|
|
3381
|
+
if (!rules) {
|
|
3302
3382
|
rules = {};
|
|
3303
3383
|
console.warn('[CONTROLLER]['+ local.options.conf.bundle +'][Backend validation] did not find matching rules for form.id `'+ form.id +'` for `'+ bundle+' bundle`. Do not Panic if you did not defined any.')
|
|
3304
3384
|
}
|
|
@@ -3307,40 +3387,40 @@ function SuperController(options) {
|
|
|
3307
3387
|
return;
|
|
3308
3388
|
}
|
|
3309
3389
|
}
|
|
3310
|
-
|
|
3390
|
+
|
|
3311
3391
|
return rules;
|
|
3312
3392
|
}
|
|
3313
|
-
|
|
3393
|
+
|
|
3314
3394
|
this.push = function(payload) {
|
|
3315
|
-
|
|
3395
|
+
|
|
3316
3396
|
var req = local.req, res = local.res;
|
|
3317
3397
|
var method = req.method.toLowerCase();
|
|
3318
3398
|
// if no session defined, will push to all active clients
|
|
3319
3399
|
var sessionId = ( typeof(req[method].sessionID) != 'undefined' ) ? req[method].sessionID : null;
|
|
3320
|
-
|
|
3400
|
+
|
|
3321
3401
|
// resume current session
|
|
3322
|
-
|
|
3323
|
-
if (!payload) {
|
|
3324
|
-
payload = null;
|
|
3402
|
+
|
|
3403
|
+
if (!payload) {
|
|
3404
|
+
payload = null;
|
|
3325
3405
|
if ( typeof(req[method]) != 'undefined' && typeof(req[method].payload) != 'undefined' ) {
|
|
3326
3406
|
if ( typeof(payload) == 'string' ) {
|
|
3327
3407
|
payload = decodeURIComponent(req[method].payload)
|
|
3328
3408
|
} else {
|
|
3329
3409
|
payload = JSON.stringify(req[method].payload)
|
|
3330
|
-
}
|
|
3410
|
+
}
|
|
3331
3411
|
}
|
|
3332
3412
|
} else if ( typeof(payload) == 'object' ) {
|
|
3333
3413
|
payload = JSON.stringify(payload)
|
|
3334
|
-
}
|
|
3335
|
-
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3336
3416
|
try {
|
|
3337
3417
|
var clients = null;
|
|
3338
3418
|
if (sessionId) {
|
|
3339
3419
|
clients = self.serverInstance.eio.getClientsBySessionId(sessionId);
|
|
3340
3420
|
if (clients)
|
|
3341
3421
|
clients.send(payload);
|
|
3342
|
-
}
|
|
3343
|
-
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3344
3424
|
// send to all clients if no specific sessionId defined
|
|
3345
3425
|
if (!sessionId) {
|
|
3346
3426
|
clients = self.serverInstance.eio.clients;
|
|
@@ -3348,14 +3428,14 @@ function SuperController(options) {
|
|
|
3348
3428
|
clients[id].send(payload)
|
|
3349
3429
|
}
|
|
3350
3430
|
}
|
|
3351
|
-
|
|
3431
|
+
|
|
3352
3432
|
res.end();
|
|
3353
3433
|
} catch(err) {
|
|
3354
3434
|
self.throwError(err);
|
|
3355
3435
|
return;
|
|
3356
|
-
}
|
|
3436
|
+
}
|
|
3357
3437
|
}
|
|
3358
|
-
|
|
3438
|
+
|
|
3359
3439
|
var getSession = function() {
|
|
3360
3440
|
var session = null;
|
|
3361
3441
|
if ( typeof(local.req.session) != 'undefined') {
|
|
@@ -3365,10 +3445,10 @@ function SuperController(options) {
|
|
|
3365
3445
|
if (!session && typeof(local.req.session) != 'undefined' && typeof(local.req.session.user) != 'undefined') {
|
|
3366
3446
|
session = local.req.session.user;
|
|
3367
3447
|
}
|
|
3368
|
-
|
|
3448
|
+
|
|
3369
3449
|
return session;
|
|
3370
3450
|
}
|
|
3371
|
-
|
|
3451
|
+
|
|
3372
3452
|
this.isHaltedRequest = function(session) {
|
|
3373
3453
|
// trying to retrieve session since it is optional
|
|
3374
3454
|
if ( typeof(session) == 'undefined' ) {
|
|
@@ -3381,24 +3461,24 @@ function SuperController(options) {
|
|
|
3381
3461
|
// session = local.req.session.user;
|
|
3382
3462
|
// }
|
|
3383
3463
|
if (
|
|
3384
|
-
!session
|
|
3385
|
-
||
|
|
3464
|
+
!session
|
|
3465
|
+
||
|
|
3386
3466
|
typeof(session) != 'undefined'
|
|
3387
3467
|
&& typeof(session.haltedRequest) == 'undefined'
|
|
3388
3468
|
) {
|
|
3389
3469
|
return false;
|
|
3390
3470
|
}
|
|
3391
3471
|
}
|
|
3392
|
-
|
|
3472
|
+
|
|
3393
3473
|
return (typeof(session.haltedRequest) != 'undefined' ) ? true : false;
|
|
3394
3474
|
}
|
|
3395
|
-
|
|
3396
|
-
|
|
3475
|
+
|
|
3476
|
+
|
|
3397
3477
|
local.haltedRequestUrlResumed = false;
|
|
3398
|
-
|
|
3478
|
+
|
|
3399
3479
|
this.pauseRequest = function(data, requestStorage) {
|
|
3400
|
-
|
|
3401
|
-
|
|
3480
|
+
|
|
3481
|
+
|
|
3402
3482
|
// saving halted request
|
|
3403
3483
|
var req = local.req
|
|
3404
3484
|
, res = local.res
|
|
@@ -3410,22 +3490,22 @@ function SuperController(options) {
|
|
|
3410
3490
|
data : JSON.clone(data)
|
|
3411
3491
|
}
|
|
3412
3492
|
;
|
|
3413
|
-
|
|
3493
|
+
|
|
3414
3494
|
if (
|
|
3415
3495
|
typeof(requestStorage) == 'undefined'
|
|
3416
3496
|
&& typeof(req.session) != 'undefined'
|
|
3417
3497
|
) {
|
|
3418
3498
|
requestStorage = req.session;
|
|
3419
3499
|
}
|
|
3420
|
-
|
|
3500
|
+
|
|
3421
3501
|
if (
|
|
3422
|
-
typeof(requestStorage) == 'undefined'
|
|
3502
|
+
typeof(requestStorage) == 'undefined'
|
|
3423
3503
|
) {
|
|
3424
3504
|
var error = new ApiError('`requestStorage` is required', 424);
|
|
3425
3505
|
self.throwError(error);
|
|
3426
3506
|
return;
|
|
3427
3507
|
}
|
|
3428
|
-
|
|
3508
|
+
|
|
3429
3509
|
var requestParams = {}, i = 0;
|
|
3430
3510
|
for (var p in req.params) {
|
|
3431
3511
|
if (i > 0) {
|
|
@@ -3436,13 +3516,13 @@ function SuperController(options) {
|
|
|
3436
3516
|
if (requestParams.count() > 0) {
|
|
3437
3517
|
haltedRequest.params = requestParams;
|
|
3438
3518
|
}
|
|
3439
|
-
|
|
3519
|
+
|
|
3440
3520
|
requestStorage.haltedRequest = haltedRequest;
|
|
3441
|
-
|
|
3521
|
+
|
|
3442
3522
|
return requestStorage;
|
|
3443
3523
|
}
|
|
3444
|
-
|
|
3445
|
-
|
|
3524
|
+
|
|
3525
|
+
|
|
3446
3526
|
/**
|
|
3447
3527
|
* resumeRequest
|
|
3448
3528
|
* Used to resume an halted request
|
|
@@ -3450,35 +3530,35 @@ function SuperController(options) {
|
|
|
3450
3530
|
* - a middleware attached `haltedRequest` to userSession
|
|
3451
3531
|
* OR
|
|
3452
3532
|
* - a persistant object where `haltedRequest` is attached
|
|
3453
|
-
*
|
|
3454
|
-
* @param {object} req
|
|
3455
|
-
* @param {object} res
|
|
3533
|
+
*
|
|
3534
|
+
* @param {object} req
|
|
3535
|
+
* @param {object} res
|
|
3456
3536
|
* @param {callback|null} next
|
|
3457
3537
|
* @param {object} [requestStorage] - Will try to use sessionStorage if not passed
|
|
3458
3538
|
*/
|
|
3459
3539
|
this.resumeRequest = function(requestStorage) {
|
|
3460
|
-
|
|
3540
|
+
|
|
3461
3541
|
if (local.haltedRequestUrlResumed)
|
|
3462
3542
|
return;
|
|
3463
|
-
|
|
3543
|
+
|
|
3464
3544
|
var haltedRequest = null
|
|
3465
3545
|
, req = local.req
|
|
3466
3546
|
, res = local.res
|
|
3467
3547
|
, next = local.next
|
|
3468
3548
|
;
|
|
3469
|
-
|
|
3549
|
+
|
|
3470
3550
|
if (
|
|
3471
3551
|
typeof(requestStorage) == 'undefined'
|
|
3472
3552
|
&& typeof(req.session) != 'undefined'
|
|
3473
3553
|
) {
|
|
3474
3554
|
requestStorage = req.session;
|
|
3475
3555
|
}
|
|
3476
|
-
|
|
3556
|
+
|
|
3477
3557
|
if (
|
|
3478
|
-
typeof(requestStorage) == 'undefined'
|
|
3558
|
+
typeof(requestStorage) == 'undefined'
|
|
3479
3559
|
||
|
|
3480
|
-
typeof(requestStorage) != 'undefined'
|
|
3481
|
-
&& typeof(requestStorage.haltedRequest) == 'undefined'
|
|
3560
|
+
typeof(requestStorage) != 'undefined'
|
|
3561
|
+
&& typeof(requestStorage.haltedRequest) == 'undefined'
|
|
3482
3562
|
) {
|
|
3483
3563
|
var error = new ApiError('`requestStorage.haltedRequest` is required', 424);
|
|
3484
3564
|
self.throwError(error);
|
|
@@ -3493,11 +3573,11 @@ function SuperController(options) {
|
|
|
3493
3573
|
if (req.method.toLowerCase() == method) {
|
|
3494
3574
|
data = merge(data, req[method])
|
|
3495
3575
|
}
|
|
3496
|
-
|
|
3497
|
-
delete req[method];
|
|
3576
|
+
|
|
3577
|
+
delete req[method];
|
|
3498
3578
|
}
|
|
3499
|
-
|
|
3500
|
-
|
|
3579
|
+
|
|
3580
|
+
|
|
3501
3581
|
var dataAsParams = {};
|
|
3502
3582
|
if (data.count() > 0) {
|
|
3503
3583
|
dataAsParams = JSON.clone(haltedRequest.data);
|
|
@@ -3509,25 +3589,45 @@ function SuperController(options) {
|
|
|
3509
3589
|
requiredController = self.requireController(haltedRequest.routing.namespace, self._options );
|
|
3510
3590
|
} catch (err) {
|
|
3511
3591
|
self.throwError(err);
|
|
3512
|
-
}
|
|
3592
|
+
}
|
|
3513
3593
|
}
|
|
3514
3594
|
req.routing = haltedRequest.routing;
|
|
3515
3595
|
req.method = haltedRequest.method;
|
|
3516
3596
|
req[haltedRequest.method] = data;
|
|
3517
|
-
|
|
3597
|
+
|
|
3518
3598
|
local.haltedRequestUrlResumed = true;
|
|
3519
|
-
if ( /GET/i.test(req.method) ) {
|
|
3599
|
+
if ( /GET/i.test(req.method) ) {
|
|
3520
3600
|
if ( typeof(requestStorage.haltedRequest) != 'undefined' ) {
|
|
3521
3601
|
delete requestStorage.haltedRequest;
|
|
3522
3602
|
}
|
|
3523
3603
|
delete requestStorage.haltedRequest;
|
|
3524
3604
|
delete requestStorage.inheritedData;
|
|
3525
3605
|
requestStorage.haltedRequestUrlResumed = url;
|
|
3526
|
-
|
|
3606
|
+
|
|
3607
|
+
if (
|
|
3608
|
+
typeof(req.routing.param.isPopinContext) != 'undefined'
|
|
3609
|
+
&& /^true$/i.test(req.routing.param.isPopinContext)
|
|
3610
|
+
&& self.isXMLRequest()
|
|
3611
|
+
) {
|
|
3612
|
+
return self.renderJSON({
|
|
3613
|
+
isXhrRedirect: true,
|
|
3614
|
+
popin: {
|
|
3615
|
+
url: url
|
|
3616
|
+
}
|
|
3617
|
+
})
|
|
3618
|
+
}
|
|
3619
|
+
else if (self.isXMLRequest() ) {
|
|
3620
|
+
return self.renderJSON({
|
|
3621
|
+
isXhrRedirect: true,
|
|
3622
|
+
location: url
|
|
3623
|
+
})
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3527
3626
|
requiredController.redirect(url, true);
|
|
3627
|
+
|
|
3528
3628
|
} else {
|
|
3529
3629
|
local.onHaltedRequestResumed = function(err) {
|
|
3530
|
-
if (!err) {
|
|
3630
|
+
if (!err) {
|
|
3531
3631
|
delete requestStorage.haltedRequest;
|
|
3532
3632
|
delete requestStorage.inheritedData;
|
|
3533
3633
|
}
|
|
@@ -3535,7 +3635,7 @@ function SuperController(options) {
|
|
|
3535
3635
|
if ( typeof(next) == 'function' ) {
|
|
3536
3636
|
console.warn('About to override `next` param');
|
|
3537
3637
|
}
|
|
3538
|
-
|
|
3638
|
+
|
|
3539
3639
|
try {
|
|
3540
3640
|
requiredController[req.routing.param.control](req, res, next);
|
|
3541
3641
|
// consuming it
|
|
@@ -3544,12 +3644,12 @@ function SuperController(options) {
|
|
|
3544
3644
|
console.error('[ BUNDLE ][ '+ local.options.conf.bundle +' ][ Controller ] Could not resume haltedRequest\n' + err.stack );
|
|
3545
3645
|
self.throwError(err);
|
|
3546
3646
|
}
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
}
|
|
3647
|
+
|
|
3648
|
+
|
|
3649
|
+
}
|
|
3550
3650
|
}
|
|
3551
|
-
|
|
3552
|
-
|
|
3651
|
+
|
|
3652
|
+
|
|
3553
3653
|
this.renderCustomError = function (req, res, next) {
|
|
3554
3654
|
|
|
3555
3655
|
// preventing multiple call of self.renderWithoutLayout() when controller is rendering from another required controller
|
|
@@ -3559,13 +3659,13 @@ function SuperController(options) {
|
|
|
3559
3659
|
local.options.isRenderingCustomError = true;
|
|
3560
3660
|
|
|
3561
3661
|
//local.options.isWithoutLayout = true;
|
|
3562
|
-
|
|
3662
|
+
|
|
3563
3663
|
var data = null;
|
|
3564
3664
|
if ( typeof(req.routing.param.error) != 'undefined' ) {
|
|
3565
3665
|
data = JSON.clone(req.routing.param.error) || {};
|
|
3566
3666
|
delete req.routing.param.error
|
|
3567
3667
|
}
|
|
3568
|
-
|
|
3668
|
+
|
|
3569
3669
|
var session = getSession();
|
|
3570
3670
|
if (session) {
|
|
3571
3671
|
data.session = JSON.clone(session)
|
|
@@ -3603,13 +3703,27 @@ function SuperController(options) {
|
|
|
3603
3703
|
//assets: {}
|
|
3604
3704
|
};
|
|
3605
3705
|
errOptions = merge(localOptions, local.options);
|
|
3606
|
-
|
|
3607
|
-
|
|
3706
|
+
|
|
3707
|
+
|
|
3608
3708
|
}
|
|
3609
3709
|
delete local.options.namespace;
|
|
3610
3710
|
self.render(data, displayToolbar, errOptions);
|
|
3611
3711
|
}
|
|
3612
|
-
|
|
3712
|
+
|
|
3713
|
+
var getResponseProtocol = function (response) {
|
|
3714
|
+
// var options = local.options;
|
|
3715
|
+
// var protocolVersion = ~~options.conf.server.protocol.match(/\/(.*)$/)[1].replace(/\.\d+/, '');
|
|
3716
|
+
|
|
3717
|
+
var protocol = 'http/'+ local.req.httpVersion; // inheriting request protocol version by default
|
|
3718
|
+
var bundleConf = options.conf;
|
|
3719
|
+
// switching protocol to h2 when possible
|
|
3720
|
+
if ( /http\/2/.test(bundleConf.server.protocol) && response.stream ) {
|
|
3721
|
+
protocol = bundleConf.server.protocol;
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3724
|
+
return protocol;
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3613
3727
|
|
|
3614
3728
|
/**
|
|
3615
3729
|
* Throw error
|
|
@@ -3621,9 +3735,14 @@ function SuperController(options) {
|
|
|
3621
3735
|
* @returns {void}
|
|
3622
3736
|
* */
|
|
3623
3737
|
this.throwError = function(res, code, msg) {
|
|
3738
|
+
|
|
3739
|
+
var protocol = getResponseProtocol(res);
|
|
3740
|
+
var stream = ( /http\/2/.test(protocol) && res.stream ) ? res.stream : null;
|
|
3741
|
+
var header = ( /http\/2/.test(protocol) && res.stream ) ? {} : null;
|
|
3742
|
+
|
|
3624
3743
|
self.isProcessingError = true;
|
|
3625
3744
|
var errorObject = null; // to be returned
|
|
3626
|
-
|
|
3745
|
+
|
|
3627
3746
|
// preventing multiple call of self.throwError() when controller is rendering from another required controller
|
|
3628
3747
|
if (local.options.renderingStack.length > 1) {
|
|
3629
3748
|
return false
|
|
@@ -3634,21 +3753,21 @@ function SuperController(options) {
|
|
|
3634
3753
|
// err.fallback must be a valide route object or a url string
|
|
3635
3754
|
var fallback = null;
|
|
3636
3755
|
var standardErrorMessage = null;
|
|
3637
|
-
if (
|
|
3638
|
-
arguments[0] instanceof Error
|
|
3756
|
+
if (
|
|
3757
|
+
arguments[0] instanceof Error
|
|
3639
3758
|
|| arguments.length == 1 && typeof(res) == 'object'
|
|
3640
3759
|
|| arguments[arguments.length-1] instanceof Error
|
|
3641
|
-
|| typeof(arguments[arguments.length-1]) == 'string' && !(arguments[0] instanceof Error)
|
|
3760
|
+
|| typeof(arguments[arguments.length-1]) == 'string' && !(arguments[0] instanceof Error)
|
|
3642
3761
|
) {
|
|
3643
|
-
|
|
3644
|
-
code = ( res && typeof(res.status) != 'undefined' ) ? res.status :
|
|
3645
|
-
|
|
3762
|
+
|
|
3763
|
+
code = ( res && typeof(res.status) != 'undefined' ) ? res.status : 500;
|
|
3764
|
+
|
|
3646
3765
|
if ( typeof(statusCodes[code]) != 'undefined' ) {
|
|
3647
3766
|
standardErrorMessage = statusCodes[code];
|
|
3648
3767
|
} else {
|
|
3649
3768
|
console.warn('[ ApiValidator ] statusCode `'+ code +'` not matching any definition in `'+_( getPath('gina').core + '/status.codes')+'`\nPlease contact the Gina dev team to add one if required');
|
|
3650
3769
|
}
|
|
3651
|
-
|
|
3770
|
+
|
|
3652
3771
|
errorObject = {
|
|
3653
3772
|
status : code,
|
|
3654
3773
|
error : res.error || res.message || standardErrorMessage
|
|
@@ -3663,17 +3782,17 @@ function SuperController(options) {
|
|
|
3663
3782
|
} else if (res.message) {
|
|
3664
3783
|
console.warn('[ Controller ] Ignoring message because of the format.\n'+res.message)
|
|
3665
3784
|
}
|
|
3666
|
-
|
|
3785
|
+
|
|
3667
3786
|
} else if ( typeof(arguments[arguments.length-1]) == 'string' ) {
|
|
3668
3787
|
// formated error
|
|
3669
3788
|
errorObject.message = arguments[arguments.length-1]
|
|
3670
3789
|
} else if (
|
|
3671
|
-
arguments[arguments.length-1] instanceof Error
|
|
3672
|
-
|| typeof(res) == 'object' && typeof(res.stack) != 'undefined'
|
|
3790
|
+
arguments[arguments.length-1] instanceof Error
|
|
3791
|
+
|| typeof(res) == 'object' && typeof(res.stack) != 'undefined'
|
|
3673
3792
|
) {
|
|
3674
3793
|
errorObject = merge(arguments[arguments.length-1], errorObject)
|
|
3675
3794
|
}
|
|
3676
|
-
|
|
3795
|
+
|
|
3677
3796
|
if ( typeof(res.fallback) != 'undefined' ) {
|
|
3678
3797
|
fallback = res.fallback
|
|
3679
3798
|
}
|
|
@@ -3685,27 +3804,33 @@ function SuperController(options) {
|
|
|
3685
3804
|
code = res || 500;
|
|
3686
3805
|
res = local.res;
|
|
3687
3806
|
}
|
|
3688
|
-
|
|
3689
|
-
var responseHeaders =
|
|
3807
|
+
|
|
3808
|
+
var responseHeaders = null;
|
|
3809
|
+
if ( typeof(res.getHeaders) == 'undefined' && typeof(res.stream) != 'undefined' ) {
|
|
3810
|
+
responseHeaders = res.stream.sentHeader;
|
|
3811
|
+
} else {
|
|
3812
|
+
responseHeaders = res.getHeaders() || local.res.getHeaders();
|
|
3813
|
+
}
|
|
3814
|
+
// var responseHeaders = res.getHeaders() || local.res.getHeaders();
|
|
3690
3815
|
var req = local.req;
|
|
3691
3816
|
var next = local.next;
|
|
3692
|
-
if (!
|
|
3817
|
+
if (!headersSent()) {
|
|
3693
3818
|
// DELETE request methods don't normaly use a view,
|
|
3694
3819
|
// but if we are calling it from a view, we should render the error back to the view
|
|
3695
|
-
if ( self.isXMLRequest() ||
|
|
3820
|
+
if ( self.isXMLRequest() || !hasViews() && !/delete/i.test(req.method) || !local.options.isUsingTemplate && !hasViews() || hasViews() && !local.options.isUsingTemplate ) {
|
|
3696
3821
|
// fallback interception
|
|
3697
|
-
if ( fallback ) {
|
|
3822
|
+
if ( fallback ) {
|
|
3698
3823
|
if ( typeof(fallback) == 'string' ){ // string url: user provided
|
|
3699
3824
|
return self.redirect( fallback, true )
|
|
3700
3825
|
} else {
|
|
3701
3826
|
// else, using url from route object
|
|
3702
3827
|
// Reminder
|
|
3703
3828
|
// Here, we use route.toUrl() intead of
|
|
3704
|
-
// route.url to support x-bundle com
|
|
3829
|
+
// route.url to support x-bundle com
|
|
3705
3830
|
return self.redirect( fallback.toUrl() );
|
|
3706
3831
|
}
|
|
3707
3832
|
}
|
|
3708
|
-
|
|
3833
|
+
|
|
3709
3834
|
// allowing this.throwError(err)
|
|
3710
3835
|
if ( typeof(code) == 'object' && !msg && typeof(code.status) != 'undefined' && typeof(code.error) != 'undefined' ) {
|
|
3711
3836
|
msg = code.error || code.message;
|
|
@@ -3717,7 +3842,7 @@ function SuperController(options) {
|
|
|
3717
3842
|
console.warn('[ ApiValidator ] statusCode `'+ code +'` not matching any definition in `'+_( getPath('gina').core + '/status.codes')+'`\nPlease contact the Gina dev team to add one if required');
|
|
3718
3843
|
}
|
|
3719
3844
|
|
|
3720
|
-
// if ( !local.res.getHeaders()['content-type'] /**!req.headers['content-type'] */
|
|
3845
|
+
// if ( !local.res.getHeaders()['content-type'] /**!req.headers['content-type'] */ ) {
|
|
3721
3846
|
// // Internet Explorer override
|
|
3722
3847
|
// if ( typeof(req.headers['user-agent']) != 'undefined' && /msie/i.test(req.headers['user-agent']) ) {
|
|
3723
3848
|
// res.writeHead(code, "content-type", "text/plain")
|
|
@@ -3725,7 +3850,7 @@ function SuperController(options) {
|
|
|
3725
3850
|
// res.writeHead(code, { 'content-type': bundleConf.server.coreConfiguration.mime['json']} );
|
|
3726
3851
|
// }
|
|
3727
3852
|
// }
|
|
3728
|
-
|
|
3853
|
+
|
|
3729
3854
|
// TODO - test with internet explorer then remove this if working
|
|
3730
3855
|
if ( typeof(req.headers['user-agent']) != 'undefined' ) {
|
|
3731
3856
|
if ( /msie/i.test(req.headers['user-agent']) ) {
|
|
@@ -3743,8 +3868,8 @@ function SuperController(options) {
|
|
|
3743
3868
|
res.writeHead(code, "content-type", bundleConf.server.coreConfiguration.mime['json']+ '; charset='+ bundleConf.encoding);
|
|
3744
3869
|
}
|
|
3745
3870
|
|
|
3746
|
-
|
|
3747
|
-
|
|
3871
|
+
|
|
3872
|
+
|
|
3748
3873
|
if (!errorObject) {
|
|
3749
3874
|
errorObject = {
|
|
3750
3875
|
status: code,
|
|
@@ -3754,7 +3879,7 @@ function SuperController(options) {
|
|
|
3754
3879
|
stack: msg.stack
|
|
3755
3880
|
}
|
|
3756
3881
|
}
|
|
3757
|
-
|
|
3882
|
+
|
|
3758
3883
|
var errOutput = null, output = errorObject.toString();
|
|
3759
3884
|
if ( output == '[object Object]' ) {
|
|
3760
3885
|
errOutput = JSON.stringify(errorObject);
|
|
@@ -3762,21 +3887,22 @@ function SuperController(options) {
|
|
|
3762
3887
|
errOutput = JSON.stringify(
|
|
3763
3888
|
{
|
|
3764
3889
|
status : errorObject.status,
|
|
3765
|
-
error : output
|
|
3890
|
+
error : output,
|
|
3891
|
+
stack : errorObject.stack || null
|
|
3766
3892
|
}
|
|
3767
3893
|
);
|
|
3768
3894
|
}
|
|
3769
|
-
|
|
3770
|
-
console.error('[ BUNDLE ][ '+ bundleConf.bundle +' ][ Controller ] '+ req.method +' ['+res.statusCode +'] '+ req.url +'\n'+
|
|
3895
|
+
|
|
3896
|
+
console.error('[ BUNDLE ][ '+ bundleConf.bundle +' ][ Controller ] '+ req.method +' ['+res.statusCode +'] '+ req.url +'\n'+ errorObject);
|
|
3771
3897
|
return res.end(errOutput);
|
|
3772
3898
|
} else {
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
console.error(req.method +' ['+ errorObject.status +'] '+ req.url);
|
|
3776
|
-
|
|
3777
|
-
|
|
3899
|
+
|
|
3900
|
+
|
|
3901
|
+
console.error(req.method +' ['+ errorObject.status +'] '+ req.url + '\n'+ (errorObject.stack||errorObject.message));
|
|
3902
|
+
|
|
3903
|
+
|
|
3778
3904
|
// intercept none HTML mime types
|
|
3779
|
-
var url =
|
|
3905
|
+
var url = decodeURI(local.req.url) /// avoid %20
|
|
3780
3906
|
, ext = null
|
|
3781
3907
|
, isHtmlContent = false
|
|
3782
3908
|
, hasCustomErrorFile = false
|
|
@@ -3788,9 +3914,12 @@ function SuperController(options) {
|
|
|
3788
3914
|
}
|
|
3789
3915
|
if ( !ext || /^(html|htm)$/i.test(ext) ) {
|
|
3790
3916
|
isHtmlContent = true;
|
|
3917
|
+
if (!ext) {
|
|
3918
|
+
ext = 'html'
|
|
3919
|
+
}
|
|
3791
3920
|
}
|
|
3792
|
-
|
|
3793
|
-
if (
|
|
3921
|
+
|
|
3922
|
+
if (
|
|
3794
3923
|
isHtmlContent
|
|
3795
3924
|
&& typeof(bundleConf.content.templates._common.errorFiles) != 'undefined'
|
|
3796
3925
|
&& typeof(bundleConf.content.templates._common.errorFiles[code]) != 'undefined'
|
|
@@ -3810,11 +3939,11 @@ function SuperController(options) {
|
|
|
3810
3939
|
//message : errorObject.message || msg || null,
|
|
3811
3940
|
pathname : url
|
|
3812
3941
|
};
|
|
3813
|
-
|
|
3942
|
+
|
|
3814
3943
|
if ( errorObject ) {
|
|
3815
3944
|
eData = merge(errorObject, eData);
|
|
3816
3945
|
}
|
|
3817
|
-
|
|
3946
|
+
|
|
3818
3947
|
if ( typeof(msg) == 'object' ) {
|
|
3819
3948
|
if ( typeof(msg.stack) != 'undefined' ) {
|
|
3820
3949
|
eData.stack = msg.stack
|
|
@@ -3823,8 +3952,8 @@ function SuperController(options) {
|
|
|
3823
3952
|
eData.message = msg.message
|
|
3824
3953
|
}
|
|
3825
3954
|
}
|
|
3826
|
-
if (
|
|
3827
|
-
code
|
|
3955
|
+
if (
|
|
3956
|
+
code
|
|
3828
3957
|
// See: framework/${version}/core/status.code
|
|
3829
3958
|
&& typeof(bundleConf.server.coreConfiguration.statusCodes[code]) != 'undefined'
|
|
3830
3959
|
) {
|
|
@@ -3834,33 +3963,33 @@ function SuperController(options) {
|
|
|
3834
3963
|
// if ( typeof(local.req.routing) != 'undefined' ) {
|
|
3835
3964
|
// eData.routing = local.req.routing;
|
|
3836
3965
|
// }
|
|
3837
|
-
|
|
3966
|
+
|
|
3838
3967
|
if (typeof(bundleConf.content.templates._common.errorFiles[code]) != 'undefined') {
|
|
3839
3968
|
eFilename = bundleConf.content.templates._common.errorFiles[code];
|
|
3840
3969
|
} else {
|
|
3841
3970
|
eFilename = bundleConf.content.templates._common.errorFiles[eCode];
|
|
3842
3971
|
}
|
|
3843
|
-
|
|
3972
|
+
|
|
3844
3973
|
if (!local.options.isRenderingCustomError) {
|
|
3845
3974
|
var eRule = 'custom-error-page@'+ bundle;
|
|
3846
3975
|
var routeObj = bundleConf.content.routing[eRule];
|
|
3847
3976
|
routeObj.rule = eRule;
|
|
3848
|
-
//routeObj.url =
|
|
3977
|
+
//routeObj.url = decodeURI(local.req.url);/// avoid %20
|
|
3849
3978
|
routeObj.param.title = ( typeof(eData.title) != 'undefined' ) ? eData.title : 'Error ' + eData.status;
|
|
3850
3979
|
routeObj.param.file = eFilename;
|
|
3851
3980
|
routeObj.param.error = eData;
|
|
3852
3981
|
routeObj.param.displayToolbar = self.isCacheless();
|
|
3853
3982
|
routeObj.param.isLocalOptionResetNeeded = true;
|
|
3854
|
-
|
|
3855
|
-
|
|
3983
|
+
|
|
3984
|
+
|
|
3856
3985
|
local.req.routing = routeObj;
|
|
3857
3986
|
local.req.params.errorObject = errorObject;
|
|
3858
3987
|
self.renderCustomError(local.req, res, local.next);
|
|
3859
3988
|
return;
|
|
3860
3989
|
}
|
|
3861
|
-
|
|
3990
|
+
|
|
3862
3991
|
}
|
|
3863
|
-
|
|
3992
|
+
|
|
3864
3993
|
// if (!errorObject) {
|
|
3865
3994
|
// errorObject = {
|
|
3866
3995
|
// status: code,
|
|
@@ -3871,7 +4000,7 @@ function SuperController(options) {
|
|
|
3871
4000
|
// }
|
|
3872
4001
|
// }
|
|
3873
4002
|
var msgString = '<h1 class="status">Error '+ code +'.</h1>';
|
|
3874
|
-
|
|
4003
|
+
|
|
3875
4004
|
console.error('[ BUNDLE ][ '+ local.options.conf.bundle +' ][ Controller ] `this.'+ req.routing.param.control +'(...)` ['+res.statusCode +'] '+ req.url);
|
|
3876
4005
|
if ( typeof(msg) == 'object' ) {
|
|
3877
4006
|
|
|
@@ -3913,7 +4042,7 @@ function SuperController(options) {
|
|
|
3913
4042
|
if (typeof(errorObject) != 'undefined' && errorObject && typeof(errorObject.stack) != 'undefined' ) {
|
|
3914
4043
|
stack = errorObject.stack
|
|
3915
4044
|
}
|
|
3916
|
-
|
|
4045
|
+
|
|
3917
4046
|
if (title) {
|
|
3918
4047
|
msgString += '<pre class="'+ eCode +' title">'+ title +'</pre>';
|
|
3919
4048
|
}
|
|
@@ -3922,7 +4051,7 @@ function SuperController(options) {
|
|
|
3922
4051
|
}
|
|
3923
4052
|
if (stack) {
|
|
3924
4053
|
msgString += '<pre class="'+ eCode +' stack">'+ stack +'</pre>';
|
|
3925
|
-
}
|
|
4054
|
+
}
|
|
3926
4055
|
}
|
|
3927
4056
|
res.writeHead(code, { 'content-type': bundleConf.server.coreConfiguration.mime[ext]+'; charset='+ bundleConf.encoding } );
|
|
3928
4057
|
// if ( isHtmlContent && hasCustomErrorFile ) {
|
|
@@ -3931,15 +4060,19 @@ function SuperController(options) {
|
|
|
3931
4060
|
//if ( isHtmlContent && !hasCustomErrorFile ) {
|
|
3932
4061
|
res.end(msgString);
|
|
3933
4062
|
//}
|
|
3934
|
-
|
|
4063
|
+
|
|
3935
4064
|
return;
|
|
3936
4065
|
}
|
|
3937
4066
|
} else {
|
|
3938
4067
|
if (typeof(next) != 'undefined')
|
|
3939
4068
|
return next();
|
|
3940
4069
|
}
|
|
3941
|
-
|
|
3942
|
-
|
|
4070
|
+
|
|
4071
|
+
if ( /http\/2/.test(protocol) ) {
|
|
4072
|
+
return stream.end();
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
return res.end();
|
|
3943
4076
|
}
|
|
3944
4077
|
|
|
3945
4078
|
// converting references to objects
|