Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

[WIP] Brand chooser #90

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4180991
some basics for the brand choosing front end
jasonrichardsmith Jun 12, 2017
52fad63
updated package.json
jasonrichardsmith Jun 12, 2017
07aa115
changed build for better feedback
jasonrichardsmith Jun 12, 2017
9de89d3
added welcome so no redirects
jasonrichardsmith Jun 12, 2017
08fbfc2
dumping logs to test
jasonrichardsmith Jun 12, 2017
4a82e3e
removed logs dump added more time for service to come up?
jasonrichardsmith Jun 12, 2017
7519faa
user error
jasonrichardsmith Jun 12, 2017
ecaee9e
accidentaly removed sleep
jasonrichardsmith Jun 12, 2017
70a414b
switched to DOCKER_CMD
jasonrichardsmith Jun 12, 2017
373d42e
updated to express-busboy
jasonrichardsmith Jun 12, 2017
ab233a8
removed logs dump
jasonrichardsmith Jun 12, 2017
1455e31
added check before trying to set value, in attempt to stop crashing
jasonrichardsmith Jun 15, 2017
0c5b051
added disconnect functions to avoid crashing
jasonrichardsmith Jun 15, 2017
c8a94cd
added default branding so staging doesnt have to update
jasonrichardsmith Jun 19, 2017
eb14aa6
fixed default branding
jasonrichardsmith Jun 20, 2017
d04eb96
made some logic changes to insure user sets branding
jasonrichardsmith Jun 20, 2017
4f20950
started adding some additional fields for more branding, needs templa…
jasonrichardsmith Jun 20, 2017
ca761c3
added template for footer
jasonrichardsmith Jun 21, 2017
99ca61b
added ejs templates and package
jasonrichardsmith Jun 21, 2017
4b851a3
added the form values to the api/branding for other
jasonrichardsmith Jun 21, 2017
be6dab9
Fix formatting in some JS files
Aug 30, 2017
532aacc
Clean up branding JS code
Aug 31, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions api/branding/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
(function (){
'use strict';

var async = require("async")
, express = require("express")
, request = require("request")
, helpers = require("../../helpers")
, config = require("../../config")
, endpoints = require("../endpoints")
, app = express()
, fs = require('fs')
, busboy = require('express-busboy');

busboy.extend(app, {
upload: true,
path: '/tmp/logo',
allowedPath: /./
});

app.post("/branding", function (req, res, next) {
if (config.branding.set == true) {
res.redirect("/");
return;
} else {
console.log(req.body.brand);
if (req.body.brand !== undefined) {
var brand = req.body.brand;
var image;

if (brand == "cncf") {
image = "./public/img/cncf-logo.png";
config.branding.set = true;
config.branding.values.name = "cncf";
config.branding.values.company = "Cloud Native Computing Foundation c/o The Linux Foundation";
config.branding.values.street = "1 Letterman Drive Suite D4700";
config.branding.values.city = "San Francisco";
config.branding.values.state = "CA";
config.branding.values.zip = "94129";
config.branding.values.country = "USA";
} else if (brand == "weave") {
image = "./public/img/weave-logo.png";
config.branding.set = true;
config.branding.values.name = "weave";
config.branding.values.company = "Weaveworks Ltd.";
config.branding.values.street = "32 – 38 Scrutton Street";
config.branding.values.city = "London";
config.branding.values.zip = "EC2A 4RQ";
config.branding.values.country = "UK";
} else if (brand == "other") {
config.branding.set = true;
config.branding.values.name = "other";
console.log(req.files.logo.file);
if (req.files.logo == undefined) {
res.redirect("/welcome.html");
return;
}
image = req.files.logo.file;
config.branding.values.company = req.body.company;
config.branding.values.street = req.body.street;
config.branding.values.city = req.body.city;
config.branding.values.zip = req.body.zip;
config.branding.values.state = req.body.state;
config.branding.values.country = req.body.country;
}
else {
res.redirect("/welcome.html");
return;
}
config.branding.values.logo = fs.readFileSync(image).toString("base64");
res.redirect("/");
return;
} else {
res.redirect("/welcome.html");
return;
}
}
});

app.get("/img/logo*", function (req, res, next) {
console.log("fired")
var buf = new Buffer(config.branding.values.logo, 'base64');
res.writeHead(200, {
'Content-Type': "image/png",
'Content-disposition': 'attachment;filename=logo.png',
'Content-Length': buf.length
});
res.end(new Buffer(buf, 'binary'));
});

app.get('/footer.html', function (req, res) {
res.render('footer', config.branding.values);
});

module.exports = app;
}());
20 changes: 18 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(function (){
'use strict';

var session = require("express-session"),
RedisStore = require('connect-redis')(session)
var session = require("express-session")
, RedisStore = require('connect-redis')(session)
, redis = require("redis");

module.exports = {
session: {
Expand All @@ -18,6 +19,21 @@
secret: 'sooper secret',
resave: false,
saveUninitialized: true
},

redis_client: null,
branding: {
set: false,
values: {
name: "",
logo: "",
company: "",
street: "",
city: "",
zip: "",
state: "",
country: "",
}
}
};
}());
70 changes: 63 additions & 7 deletions helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(function (){
'use strict';

var request = require("request");
var helpers = {};
var request = require("request")
, config = require("../config")
, fs = require('fs')
, redis = require("redis")
, helpers = {}

/* Public: errorHandler is a middleware that handles your errors
*
Expand All @@ -11,7 +14,6 @@
* var app = express();
* app.use(helpers.errorHandler);
* */

helpers.errorHandler = function(err, req, res, next) {
var ret = {
message: err.message,
Expand Down Expand Up @@ -53,10 +55,10 @@

/* Rewrites and redirects any url that doesn't end with a slash. */
helpers.rewriteSlash = function(req, res, next) {
if(req.url.substr(-1) == '/' && req.url.length > 1)
res.redirect(301, req.url.slice(0, -1));
else
next();
if(req.url.substr(-1) == '/' && req.url.length > 1)
res.redirect(301, req.url.slice(0, -1));
else
next();
}

/* Public: performs an HTTP GET request to the given URL
Expand Down Expand Up @@ -102,5 +104,59 @@

return req.session.customerId;
}


helpers.getBrandingConfig = function(callback) {
if(process.env.SESSION_REDIS) {
config.redis_client = redis.createClient("redis://session-db:6379");
config.redis_client.on("error", function (err) {
console.log("Redis error encountered", err);
});

config.redis_client.on("end", function() {
console.log("Redis connection closed");
});

if(process.env.DEFAULT_BRANDING) {
var image = "./public/img/weave-logo.png";
config.branding.set = true;
config.branding.values.name = "weave";
config.branding.values.logo = fs.readFileSync(image).toString("base64");
callback(config.branding);
return
} else {
config.redis_client.get("branding_info", function(err, reply) {
if (reply !== null) {
config.branding.values = JSON.parse(reply);
config.branding.set = true;
callback(config.branding);
} else {
callback(config.branding);
}
});
}
} else {
if (fs.existsSync("./branding.json")) {
config.branding.values = JSON.parse(fs.readFileSync('./branding.json'));
config.branding.set = true;
callback(config.branding);
} else {
callback(config.branding);
}
}
};

helpers.setBrandingConfig = function() {
if(process.env.SESSION_REDIS) {
if (config.redis_client.connected) {
config.redis_client.set("branding_info", JSON.stringify(config.branding.values));
}
} else {
fs.writeFile("./branding.json", JSON.stringify(config.branding.values, null, 2), function(err) {
return err;
});
}
}

module.exports = helpers;
}());
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
"dependencies": {
"async": "^1.5.2",
"body-parser": "^1.15.1",
"connect-busboy": "0.0.2",
"connect-redis": "^3.2.0",
"cookie-parser": "^1.4.3",
"ejs": "^2.5.6",
"express": "^4.13.4",
"express-busboy": "^6.0.1",
"express-session": "^1.13.0",
"finalhandler": "^0.4.1",
"request": "^2.72.0",
"serve-static": "^1.10.2",
"prom-client": "^6.3.0",
"morgan": "^1.7.0",
"connect-redis": "^3.2.0"
"prom-client": "^6.3.0",
"redis": "^2.7.1",
"request": "^2.72.0",
"serve-static": "^1.10.2"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
Binary file added public/img/cncf-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/img/logo.png
Binary file not shown.
File renamed without changes
Loading