summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--gulpfile.js26
-rw-r--r--sample_config.json3
-rw-r--r--src/404.html2
-rw-r--r--src/index.html4
-rw-r--r--src/scripts/controllers/connection/socket.ts2
-rw-r--r--src/scripts/splash.entry.ts4
-rw-r--r--src/scripts/user.ts17
-rw-r--r--tslint.json2
9 files changed, 35 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 49684fa2..11181e8c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,6 @@ yarn.lock
# WebStorm
.idea/
+
+# Standard config file
+config.json
diff --git a/gulpfile.js b/gulpfile.js
index e57c31d6..579e795f 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -4,6 +4,9 @@
* Usage:
* $ gulp --config=config.json # for a single build
* $ gulp watch --config=config.json # to run once, watch for changes, and rebuild when something changed
+ *
+ * If the `config` argument is omitted, the config file is assumed to be named `config.json` and present in this
+ * directory.
*/
'use strict';
@@ -16,6 +19,7 @@ const gulpUtil = require('gulp-util');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const del = require('del');
+const fs = require('fs');
const runSequence = require('run-sequence');
const source = require('vinyl-source-stream');
const es = require('event-stream');
@@ -35,12 +39,17 @@ const bower = require('gulp-bower');
* @returns {Object} the config file contents.
*/
function getConfigFile() {
- const configInput = argv.config;
+ let configInput = argv.config;
if (configInput === undefined) {
- gulpUtil.log(gulpUtil.colors.red('Config file argument missing\n'), 'Usage:\n' +
- ' $ gulp --config=config.json');
- throw new Exception();
+ if (!fs.existsSync("./config.json")) {
+ gulpUtil.log(gulpUtil.colors.red('Config file argument missing\n'), 'Usage:\n' +
+ ' $ gulp --config=config.json');
+ throw new Exception();
+ } else {
+ gulpUtil.log(gulpUtil.colors.magenta('No config file argument, assuming `config.json`.'));
+ configInput = "config.json";
+ }
}
try {
@@ -91,6 +100,8 @@ const scriptsFilePaths = scriptsFileNames.map(function (fileName) {
});
gulp.task('scripts', function () {
+ const configFile = getConfigFile();
+
const tasks = scriptsFilePaths.map(function (entry, index) {
return browserify({
entries: [entry],
@@ -102,6 +113,7 @@ gulp.task('scripts', function () {
.plugin(tsify)
.bundle()
.pipe(source(scriptsFileNames[index] + postfix + '.js'))
+ .pipe(replace('SERVER_BASE_URL', configFile.SERVER_BASE_URL))
.pipe(gulp.dest(scriptsDestDir));
});
return es.merge.apply(null, tasks)
@@ -109,11 +121,14 @@ gulp.task('scripts', function () {
});
function getWatchifyHandler(bundler, fileName) {
+ const configFile = getConfigFile();
+
return () => {
- gulpUtil.log("Beginning build for " + fileName);
+ gulpUtil.log('Beginning build for ' + fileName);
return bundler
.bundle()
.pipe(source(fileName + postfix + '.js'))
+ .pipe(replace('SERVER_BASE_URL', configFile.SERVER_BASE_URL))
.pipe(gulp.dest(scriptsDestDir));
};
}
@@ -166,6 +181,7 @@ gulp.task('html', function () {
return gulp.src(htmlFilePaths)
.pipe(replace('GOOGLE_OAUTH_CLIENT_ID', configFile.GOOGLE_OAUTH_CLIENT_ID))
+ .pipe(replace('SERVER_BASE_URL', configFile.SERVER_BASE_URL))
.pipe(processHTML())
.pipe(gulp.dest(htmlDestDir))
.pipe(notify({message: 'HTML task complete', onLast: true}));
diff --git a/sample_config.json b/sample_config.json
index 628476ed..58ff0e72 100644
--- a/sample_config.json
+++ b/sample_config.json
@@ -1,3 +1,4 @@
{
- "GOOGLE_OAUTH_CLIENT_ID": "the-google-oauth-client-id"
+ "GOOGLE_OAUTH_CLIENT_ID": "the-google-oauth-client-id",
+ "SERVER_BASE_URL": "http://localhost:8081"
}
diff --git a/src/404.html b/src/404.html
index 84182341..10f79525 100644
--- a/src/404.html
+++ b/src/404.html
@@ -20,7 +20,7 @@
</div>
<div class="code-block"></div>
<div class="sub-title">Got lost?<span class="cursor">_</span></div>
- <a class="home-btn" href="https://opendc.ewi.tudelft.nl">GET ME BACK TO OPENDC</a>
+ <a class="home-btn" href="SERVER_BASE_URL">GET ME BACK TO OPENDC</a>
</div>
</div>
diff --git a/src/index.html b/src/index.html
index 8ea4ce49..c58aaf01 100644
--- a/src/index.html
+++ b/src/index.html
@@ -11,8 +11,8 @@
<!-- OpenGraph meta tags -->
<meta property="og:title" content="OpenDC: Collaborative Datacenter Simulation and Exploration for Everybody">
<meta property="og:type" content="website">
- <meta property="og:image" content="https://opendc.ewi.tudelft.nl/img/opendc-splash.png">
- <meta property="og:url" content="https://opendc.ewi.tudelft.nl">
+ <meta property="og:image" content="SERVER_BASE_URL/img/opendc-splash.png">
+ <meta property="og:url" content="SERVER_BASE_URL">
<meta property="og:description"
content="OpenDC provides collaborative online datacenter modeling, diverse and effective datacenter
simulation, and exploratory datacenter performance feedback.">
diff --git a/src/scripts/controllers/connection/socket.ts b/src/scripts/controllers/connection/socket.ts
index c23495f1..91a0f9e4 100644
--- a/src/scripts/controllers/connection/socket.ts
+++ b/src/scripts/controllers/connection/socket.ts
@@ -15,7 +15,7 @@ export class SocketController {
this.callbacks = {};
this._cacheController = new CacheController();
- this._socket = io.connect('https://opendc.ewi.tudelft.nl:443');
+ this._socket = io.connect('SERVER_BASE_URL');
this._socket.on('connect', onConnect);
this._socket.on('response', (jsonResponse: string) => {
diff --git a/src/scripts/splash.entry.ts b/src/scripts/splash.entry.ts
index 700f52bb..6abd9518 100644
--- a/src/scripts/splash.entry.ts
+++ b/src/scripts/splash.entry.ts
@@ -119,7 +119,7 @@ window["renderButton"] = () => {
// Calculate token expiration time (in seconds since epoch)
const expirationTime = (new Date()).getTime() / 1000 + googleUser.getAuthResponse().expires_in - 5;
- $.post('https://opendc.ewi.tudelft.nl/tokensignin', {
+ $.post('SERVER_BASE_URL/tokensignin', {
idtoken: id_token
}, (data: any) => {
// Save user information in session storage for later use on other pages
@@ -146,7 +146,7 @@ window["renderButton"] = () => {
});
},
'onfailure': () => {
- console.log("Oops, something went wrong with your Google signin... Try again?")
+ console.log("Oops, something went wrong with your Google signin... Try again?");
}
});
};
diff --git a/src/scripts/user.ts b/src/scripts/user.ts
index 66e44b21..e9d13091 100644
--- a/src/scripts/user.ts
+++ b/src/scripts/user.ts
@@ -2,24 +2,11 @@
import * as $ from "jquery";
-const LOCAL_MODE = (document.location.hostname === "localhost");
-
// Redirect the user to the splash page, if not signed in
-if (!LOCAL_MODE && localStorage.getItem("googleToken") === null) {
+if (localStorage.getItem("googleToken") === null) {
window.location.replace("/");
}
-// Fill session storage with mock data during LOCAL_MODE
-if (LOCAL_MODE) {
- localStorage.setItem("googleToken", "");
- localStorage.setItem("googleTokenExpiration", "2000000000");
- localStorage.setItem("googleName", "John Doe");
- localStorage.setItem("googleEmail", "john@doe.com");
- localStorage.setItem("userId", "2");
- localStorage.setItem("simulationId", "1");
- localStorage.setItem("simulationAuthLevel", "OWN");
-}
-
// Set the username in the navbar
$("nav .user .username").text(localStorage.getItem("googleName"));
@@ -59,7 +46,7 @@ window["gapiSigninButton"] = () => {
},
'onfailure': () => {
window.location.href = "/";
- console.log("Oops, something went wrong with your Google signin... Try again?")
+ console.log("Oops, something went wrong with your Google signin... Try again?");
}
});
};
diff --git a/tslint.json b/tslint.json
index b2c0ac60..75b8d041 100644
--- a/tslint.json
+++ b/tslint.json
@@ -32,7 +32,7 @@
"no-eval": true,
"no-inferrable-types": true,
"no-shadowed-variable": true,
- "no-string-literal": true,
+ "no-string-literal": false,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,