Skip to content

Commit

Permalink
1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Dana Roibu committed Oct 26, 2016
1 parent 7d83d60 commit 7c1934a
Show file tree
Hide file tree
Showing 108 changed files with 2,635 additions and 1,436 deletions.
9 changes: 8 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ The :prod parameter specifies which dynamic domain to connect with the api servi

Credential parameters also exist for automated build environments. With NPM 2.0, it is possible to pass in a Client_Id, Project_Id and Redirect_URI from npm run-script command line. For example, we can further automate the build system with these parameters (pid, cid and ruri) like this:

$ npm run-script singleProd -- --pid=abc --cid=123 --ruri=http://example.com
$ npm run-script singleProd -- --pid=abc --cid=123 --ruri=http://example.com

This allows for many different projects with many different clients to be configured. But remember that a minimum version of NPM 2.0 is required to pass the parameters, otherwise the Client_Id, Project_Id and Redirect_URI will be set by default to the build configuration variables in the gruntfile.

Additional parameter that can be provided is `--https` which will force https instead of http. Below this you can find an example:

$ npm run-script singleProd -- --pid=abc --cid=123 --ruri=http://example.com --https

Store can be used in different regions. Parameter that should be provided is `--region` which will run store in choosen region. Currently there is a default region (US) and optional region eu (EU). Below this you can find an example:

$ npm run-script singleProd -- --pid=abc --cid=123 --ruri=http://example.com --region=eu

**grunt build** will also optimize js and css in public/index.html. See the optimization section for more specific information.

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"angular-translate": "~2.8.0",
"angular-translate-loader-static-files": "~2.8.1",
"angular-stripe-js": "Venturocket/angular-stripe-js#0.0.6",
"ngInfiniteScroll": "1.0.0",
"ngInfiniteScroll": "1.1.0",
"bootstrap": "3.3.2",
"restangular": "~1.4.0",
"lodash": "~2.4.1",
Expand Down
6 changes: 5 additions & 1 deletion config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ module.exports = function(config){
'public/js/app/products/controllers/browse-products-ctrl.js',
'public/js/app/products/controllers/product-detail-ctrl.js',
'public/js/app/products/services/product-service.js',
'public/js/app/products/services/price-service.js',
'public/js/app/products/services/prices-rest.js',
'public/js/app/products/services/price-svc.js',
'public/js/app/products/services/price-product-rest.js',
'public/js/app/products/services/category-service.js',
'public/js/app/products/services/product-extension-service.js',
Expand Down Expand Up @@ -131,6 +132,9 @@ module.exports = function(config){
'public/js/app/account/controllers/dialogs/order-cancel-dialog-ctrl.js',
'public/js/app/account/controllers/modals/edit-user-email-dialog-ctrl.js',
'public/js/app/account/controllers/modals/edit-user-name-dialog-ctrl.js',
'public/js/app/account/controllers/delete-account-ctrl.js',
'public/js/app/account/controllers/dialogs/delete-account-dialog-ctrl.js',
'public/js/app/account/controllers/modals/delete-account-basic-ctrl.js',
'public/js/app/account/directives/customer-details/customer-details-directive.js',
'public/js/app/account/directives/customer-details/customer-details-ctrl.js',
'public/js/app/account/services/account-service.js',
Expand Down
4 changes: 2 additions & 2 deletions config/protractor-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports.config = {
'../test/e2e/checkout/checkout.mobile.spec.js',
'../test/e2e/coupon/coupon.spec.js',
'../test/e2e/account/account.spec.js',
'../test/e2e/product/product.spec.js'
'../test/e2e/product/product-list.spec.js'
],


Expand Down Expand Up @@ -40,7 +40,7 @@ exports.config = {
new jasmine.JUnitXmlReporter(null, true, true, 'coverage/')
);
// Add a screenshot reporter and store screenshots to `/tmp/screnshots`:

// jasmine.getEnv().addReporter(new ScreenShotReporter({
// baseDirectory: './tmp/screenshots',
// takeScreenShotsOnlyForFailedSpecs: true
Expand Down
136 changes: 91 additions & 45 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* [y] hybris Platform
*
* Copyright (c) 2000-2016 hybris AG
* All rights reserved.
*
* This software is the confidential and proprietary information of hybris
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the
* license agreement you entered into with hybris.
*/

'use strict';

var path = require('path');
Expand All @@ -12,20 +24,42 @@ module.exports = function (grunt) {
LESS_DIR = 'public/less',
TRANSLATIONS_DIR = 'public/js/app/shared/i18n/dev',

ALLOWED_REGIONS = ['eu'],
REGION_INVALID_MSG = 'Selected region is not valid, changing back to default region. Please provide one of valid regions: [' + ALLOWED_REGIONS.join(',') + ']',

//--Set Parameters for Server Configuration----------------------------------------------------
// Read npm argument and set the dynamic server environment or use default configuration.
// Syntax example for npm 2.0 parameters: $ npm run-script singleProd -- --pid=xxx --cid=123 --ruri=http://example.com
PROJECT_ID = grunt.option('pid') || 'defaultproj',
PROJECT_ID = grunt.option('pid') || 'saphybriscaas',
CLIENT_ID = grunt.option('cid') || 'hkpWzlQnCIe4MSTi1Ud94Q7O36aRrRrO',
REDIRECT_URI = grunt.option('ruri') || 'http://example.com',
USE_HTTPS = grunt.option('https') || false,
REGION_CODE = grunt.option('region') || '',

SERVER_FILES = ['./server.js', './server/singleProdServer.js', './multi-tenant/multi-tenant-server.js'],

PROJECT_ID_PATH = './public/js/app/shared/app-config.js',
PROD_DOMAIN = 'api.yaas.io',
PROD_DOMAIN = 'api{0}.yaas.io',
STAGE_DOMAIN = 'api.stage.yaas.io',
API_DOMAIN_PATH = './public/js/app/shared/app-config.js',
TRANSLATE_FILES_PATH = './public/js/app/shared/i18n/lang/lang_*.json',
DOMAIN_MSG = 'Could not find environment domain in build parameter. Site is built with default API domain. Use grunt build:prod [:stage] to specify.';

var getProdBaseUrl = function getProdBaseUrl(regionCode) {
if (!!regionCode && ALLOWED_REGIONS.indexOf(regionCode) < 0) {
grunt.option('force', true);
grunt.warn(REGION_INVALID_MSG);
regionCode = '';
}

if (!!regionCode) {
return PROD_DOMAIN.replace('{0}', '.' + regionCode);
}
else {
return PROD_DOMAIN.replace('{0}', '');
}
};

require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-angular-templates'); //combines templates into cache
Expand Down Expand Up @@ -215,7 +249,7 @@ module.exports = function (grunt) {
overwrite: true,
replacements: [{
from: /StartDynamicDomain(.*)EndDynamicDomain/g,
to: 'StartDynamicDomain*/ \'' + PROD_DOMAIN + '\' /*EndDynamicDomain'
to: 'StartDynamicDomain*/ \'' + getProdBaseUrl(REGION_CODE) + '\' /*EndDynamicDomain'
}]
},
projectId: {
Expand All @@ -241,6 +275,14 @@ module.exports = function (grunt) {
from: /StartRedirectURI(.*)EndRedirectURI/g,
to: 'StartRedirectURI*/ \'' + REDIRECT_URI + '\' /*EndRedirectURI'
}]
},
useHttps: {
src: SERVER_FILES,
overwrite: true,
replacements: [{
from: /StartUseHTTPS(.*)EndUseHTTPS/g,
to: 'StartUseHTTPS*/ ' + !!USE_HTTPS + ' /*EndUseHTTPS'
}]
}
},

Expand Down Expand Up @@ -290,78 +332,82 @@ module.exports = function (grunt) {
//--Convenience-Tasks-----------------------------------------------
// Wrap dev build task with parameters and dynamic domain warnings.
grunt.registerTask('default', 'Build parameters for default',
function () {
grunt.task.run('build');
});
function () {
grunt.task.run('build');
});

// Wrap build task with parameters and dynamic domain warnings.
grunt.registerTask('build', 'Build parameters for build',
function (domainParam) {
function (domainParam) {

grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:useHttps');

runDomainReplace(domainParam);
runDomainReplace(domainParam);

grunt.task.run('jshint');
grunt.task.run('less:dev');
grunt.task.run('optimizeCode');
});
grunt.task.run('jshint');
grunt.task.run('less:dev');
grunt.task.run('optimizeCode');
});

//--Tasks-With-Environment-Parameters----------------------------------------------
// Wrap build task with parameters and dynamic domain warnings.
grunt.registerTask('singleProject', 'Build parameters for singleProject build',
function (domainParam) {
function (domainParam) {

grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:useHttps');

runDomainReplace(domainParam);
runDomainReplace(domainParam);

grunt.task.run('singleProjectTask');
});
grunt.task.run('singleProjectTask');
});

// Wrap build task with parameters and dynamic domain warnings.
grunt.registerTask('multiProject', 'Build parameters for multiProject build',
function (domainParam) {
function (domainParam) {

grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:useHttps');

runDomainReplace(domainParam);
runDomainReplace(domainParam);

grunt.task.run('multiProjectTask');
});
grunt.task.run('multiProjectTask');
});

// Wrap build task with parameters and dynamic domain warnings.
grunt.registerTask('prepareBuild', 'Build parameters for optimized build',
function (domainParam) {
function (domainParam) {

grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:projectId');
grunt.task.run('replace:clientId');
grunt.task.run('replace:redirectURI');
grunt.task.run('replace:useHttps');

runDomainReplace(domainParam);
runDomainReplace(domainParam);

grunt.task.run('optimizeCode');
});
grunt.task.run('optimizeCode');
});

// Wrap build task with parameters and dynamic domain warnings.
grunt.registerTask('startServer', 'Start server within deploy environment',
function () {
if (grunt.option('single')) {
grunt.task.run('concurrent:singleProdServer'); // start a single server in deployed environment.
function () {
if (grunt.option('single')) {
grunt.task.run('concurrent:singleProdServer'); // start a single server in deployed environment.

} else if (grunt.option('multiple')) {
grunt.task.run('concurrent:multiProject'); // start a multi-project server in deployed environment.
} else if (grunt.option('multiple')) {
grunt.task.run('concurrent:multiProject'); // start a multi-project server in deployed environment.

} else {
grunt.task.run('concurrent:multiProject'); // default server if none is specified.
}
});
} else {
grunt.task.run('concurrent:multiProject'); // default server if none is specified.
}
});

//---Specialized-Build-Behaviors--------------------------------------------------------
grunt.registerTask('singleProjectTask', [
Expand Down
2 changes: 1 addition & 1 deletion manifest-demo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: teststore
command: npm run-script multiProd
command: npm run-script multiProdHttps
buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
memory: 1024M
disk_quota: 1024M
Expand Down
10 changes: 10 additions & 0 deletions manifest-eu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applications:
- name: shops-green
command: npm run-script multiProdHttpsEU
buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
memory: 1024M
disk_quota: 1024M
disk: 1024M
instances: 1
path: dist
2 changes: 1 addition & 1 deletion manifest-stage.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: shops
command: npm run-script multiStage
command: npm run-script multiStageHttps
buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
memory: 1024M
disk_quota: 1024M
Expand Down
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: shops-green
command: npm run-script multiProd
command: npm run-script multiProdHttps
buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
memory: 1024M
disk_quota: 1024M
Expand Down
48 changes: 43 additions & 5 deletions multi-tenant/multi-tenant-server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
/**
* [y] hybris Platform
*
* Copyright (c) 2000-2015 hybris AG
* All rights reserved.
*
* This software is the confidential and proprietary information of hybris
* ("Confidential Information"). You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the
* license agreement you entered into with hybris.
*/

'use strict';

var http = require('http');
var express = require('express');
var compression = require('compression');

Expand All @@ -10,19 +22,45 @@ var app = express();
var helmet = require('helmet');

// compress all requests
app.use(compression({level:6}));
app.use(compression({ level: 6 }));

// Don't allow anyone to put content in a frame.
app.use(helmet.frameguard('deny'));
app.use(helmet.xssFilter());
app.disable('x-powered-by');

app.use("/:storename/", express.static(__dirname + '/../public/'));
app.set('trust proxy', true); //for https redirect

var httpsRedirect = function (req, res, next) {
var host = req.get('host');

if (req.host === 'localhost') {
next();
}
else {
console.log('HTTPS REDIRECT: ', req.protocol);
if ('https' === req.protocol) {
next();
} else {
//redirect to https based url provided by ELB
console.log('INSECURE REDIRECTING TO: ' + 'https://' + host + req.url);
return res.redirect(301, 'https://' + host + req.url); //Infinite loop.
}
}
};

var useHttps = /*StartUseHTTPS*/ false /*EndUseHTTPS*/;

if (useHttps) {
app.use(httpsRedirect);
}

app.use('/:storename/', express.static(__dirname + '/../public/'));

// ANGULAR UI-ROUTER WORKAROUND - append trailing '/'
// Long-term, this should be fixed in app.js.
app.get(/^\/\w+$/, function(request, response){
var newUrl = request.url+'/';
app.get(/^\/\w+$/, function (request, response) {
var newUrl = request.url + '/';
//console.log('redirect to '+newUrl);
response.redirect(newUrl);
});
Expand Down
Loading

0 comments on commit 7c1934a

Please sign in to comment.