Skip to content
Snippets Groups Projects
Commit 05eda8d3 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

showcase: port to app config

parent b3bfbf8b
No related branches found
No related tags found
No related merge requests found
export default {
local: {
basePath: '/dist/',
entryPointURL: 'http://127.0.0.1:8000',
keyCloakBaseURL: 'https://auth-dev.tugraz.at/auth',
keyCloakClientId: 'auth-dev-mw-frontend-local',
matomoUrl: 'https://analytics.tugraz.at/',
matomoSiteId: 131,
nextcloudBaseURL: 'http://localhost:8081',
nextcloudName: 'TU Graz cloud',
},
development: {
basePath: '/apps/checkin/',
entryPointURL: 'https://mw-dev.tugraz.at',
keyCloakBaseURL: 'https://auth-dev.tugraz.at/auth',
keyCloakClientId: 'demo-dev_tugraz_at-DEMO',
matomoUrl: 'https://analytics.tugraz.at/',
matomoSiteId: 131,
nextcloudBaseURL: 'https://nc-dev.tugraz.at/pers',
nextcloudName: 'TU Graz cloud',
},
};
\ No newline at end of file
DirectoryIndex <%= getUrl(name + '.html') %> DirectoryIndex <%- getUrl(name + '.html') %>
<FilesMatch "^(de|en|)$"> <FilesMatch "^(de|en|)$">
FallbackResource <%= getUrl(name + '.html') %> FallbackResource <%- getUrl(name + '.html') %>
</FilesMatch> </FilesMatch>
Header set Cache-Control "must-revalidate, max-age=60" Header set Cache-Control "must-revalidate, max-age=60"
Header set Content-Security-Policy "default-src 'self' 'unsafe-eval' 'unsafe-inline' analytics.tugraz.at <%= keyCloakServer %> <%= entryPointURL %> httpbin.org <%= nextcloudBaseURL %> www.handy-signatur.at <%= pdfAsQualifiedlySigningServer %>; img-src * blob: data:" Header set Content-Security-Policy "<%- CSP %>"
# Apache adds a "-gzip" suffix to the etag when it uses gzip but doesn't # Apache adds a "-gzip" suffix to the etag when it uses gzip but doesn't
# take that into account when receiving requests. # take that into account when receiving requests.
......
...@@ -37,24 +37,16 @@ host('development') ...@@ -37,24 +37,16 @@ host('development')
->hostname('mw@mw01-dev.tugraz.at') ->hostname('mw@mw01-dev.tugraz.at')
->set('deploy_path', '/home/mw/dev/deploy/apps/demo'); ->set('deploy_path', '/home/mw/dev/deploy/apps/demo');
// Demo build task task('build', function () {
task('build-demo', function () { $stage = get('stage');
runLocally("yarn install"); runLocally("yarn install");
runLocally("yarn run build-demo"); runLocally("APP_ENV=$stage yarn run build");
})->onStage('demo'); });
// Demo dev task
task('build-development', function () {
runLocally("yarn install");
runLocally("yarn run build-dev");
})->onStage('development');
// Deploy task // Deploy task
task('deploy', [ task('deploy', [
'deploy:info', 'deploy:info',
'build-demo', 'build',
'build-development',
'deploy:prepare', 'deploy:prepare',
'deploy:lock', 'deploy:lock',
'deploy:release', 'deploy:release',
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"license": "LGPL-2.1-or-later", "license": "LGPL-2.1-or-later",
"private": true, "private": true,
"workspaces": [ "workspaces": [
"../packages/*" "../packages/*",
"."
], ],
"devDependencies": { "devDependencies": {
"@babel/core": "^7.10.3", "@babel/core": "^7.10.3",
...@@ -18,7 +19,6 @@ ...@@ -18,7 +19,6 @@
"@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0", "@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.0", "@rollup/plugin-node-resolve": "^11.0.0",
"@rollup/plugin-replace": "^2.3.3",
"@rollup/plugin-url": "^6.0.0", "@rollup/plugin-url": "^6.0.0",
"babel-eslint": "^10.0.3", "babel-eslint": "^10.0.3",
"chai": "^4.2.0", "chai": "^4.2.0",
...@@ -67,15 +67,14 @@ ...@@ -67,15 +67,14 @@
"webdav": "^3.3.0" "webdav": "^3.3.0"
}, },
"scripts": { "scripts": {
"build-dev": "rollup -c --environment BUILD:development", "build": "rollup -c",
"build-prod": "rollup -c --environment BUILD:production",
"build-demo": "rollup -c --environment BUILD:demo",
"i18next": "i18next-scanner", "i18next": "i18next-scanner",
"watch": "rollup -c --watch", "watch": "rollup -c --watch",
"watch-local": "yarn run watch", "watch-local": "yarn run watch",
"watch-full": "rollup -c --watch --environment FORCE_FULL", "watch-full": "rollup -c --watch --environment FORCE_FULL",
"test": "rollup -c --environment BUILD:test && karma start --singleRun", "watch-bs": "rollup -c --watch --environment APP_ENV:bs",
"test-full": "rollup -c --environment FORCE_FULL,BUILD:test && karma start --singleRun", "test": "rollup -c --environment APP_ENV:test && karma start --singleRun",
"test-full": "rollup -c --environment FORCE_FULL,APP_ENV:test && karma start --singleRun",
"lint": "eslint ." "lint": "eslint ."
} }
} }
...@@ -6,7 +6,6 @@ import commonjs from '@rollup/plugin-commonjs'; ...@@ -6,7 +6,6 @@ import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy'; import copy from 'rollup-plugin-copy';
import {terser} from "rollup-plugin-terser"; import {terser} from "rollup-plugin-terser";
import json from '@rollup/plugin-json'; import json from '@rollup/plugin-json';
import replace from "@rollup/plugin-replace";
import serve from 'rollup-plugin-serve'; import serve from 'rollup-plugin-serve';
import urlPlugin from "@rollup/plugin-url"; import urlPlugin from "@rollup/plugin-url";
import license from 'rollup-plugin-license'; import license from 'rollup-plugin-license';
...@@ -14,126 +13,65 @@ import del from 'rollup-plugin-delete'; ...@@ -14,126 +13,65 @@ import del from 'rollup-plugin-delete';
import md from 'rollup-plugin-md'; import md from 'rollup-plugin-md';
import emitEJS from 'rollup-plugin-emit-ejs' import emitEJS from 'rollup-plugin-emit-ejs'
import babel from '@rollup/plugin-babel' import babel from '@rollup/plugin-babel'
import {generateTLSConfig} from '../rollup.utils.js'; import appConfig from './app.config.js';
import {generateTLSConfig, getBuildInfo, getPackagePath, getDistPath} from '../rollup.utils.js';
// -------------------------------
// Some new web APIs are only available when HTTPS is active.
// Note that this only works with a Non-HTTPS API endpoint with Chrome,
// Firefox will emit CORS errors, see https://bugzilla.mozilla.org/show_bug.cgi?id=1488740
const USE_HTTPS = true;
// -------------------------------
const pkg = require('./package.json'); const pkg = require('./package.json');
const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local'; const appEnv = (typeof process.env.APP_ENV !== 'undefined') ? process.env.APP_ENV : 'local';
const watch = process.env.ROLLUP_WATCH === 'true'; const watch = process.env.ROLLUP_WATCH === 'true';
const buildFull = (!watch && build !== 'test') || (process.env.FORCE_FULL !== undefined); const buildFull = (!watch && appEnv !== 'test') || (process.env.FORCE_FULL !== undefined);
console.log("build: " + build);
let basePath = '';
let entryPointURL = '';
let nextcloudBaseURL = 'https://cloud.tugraz.at';
let nextcloudWebAppPasswordURL = nextcloudBaseURL + '/apps/webapppassword';
let nextcloudWebDavURL = nextcloudBaseURL + '/remote.php/dav/files';
let nextcloudName = 'TU Graz cloud';
let keyCloakServer = '';
let keyCloakBaseURL = '';
let keyCloakClientId = '';
let pdfAsQualifiedlySigningServer = '';
const matomoUrl = "https://analytics.tugraz.at/";
const matomoSiteId = 131;
let useTerser = buildFull; let useTerser = buildFull;
let useBabel = buildFull; let useBabel = buildFull;
let checkLicenses = buildFull; let checkLicenses = buildFull;
let useHTTPS = true;
switch (build) { console.log("APP_ENV: " + appEnv);
case 'local':
basePath = '/dist/';
entryPointURL = 'http://127.0.0.1:8000';
nextcloudBaseURL = 'http://localhost:8081';
nextcloudWebAppPasswordURL = nextcloudBaseURL + '/index.php/apps/webapppassword';
nextcloudWebDavURL = nextcloudBaseURL + '/remote.php/dav/files';
keyCloakServer = 'auth-dev.tugraz.at';
keyCloakBaseURL = 'https://' + keyCloakServer + '/auth';
keyCloakClientId = 'auth-dev-mw-frontend-local';
pdfAsQualifiedlySigningServer = 'sig-dev.tugraz.at';
break;
case 'development':
basePath = '/apps/demo/';
entryPointURL = 'https://mw-dev.tugraz.at';
// "/pers" can't go here because it's not allowed in the "Content-Security-Policy"
nextcloudBaseURL = 'https://nc-dev.tugraz.at';
// "/index.php" is needed to don't get a "This origin is not allowed!" because the "target-origin" get parameter can't be read
nextcloudWebAppPasswordURL = nextcloudBaseURL + '/pers/index.php/apps/webapppassword';
nextcloudWebDavURL = nextcloudBaseURL + '/pers/remote.php/dav/files';
keyCloakServer = 'auth-dev.tugraz.at';
keyCloakBaseURL = 'https://' + keyCloakServer + '/auth';
keyCloakClientId = 'demo-dev_tugraz_at-DEMO';
pdfAsQualifiedlySigningServer = 'sig-dev.tugraz.at';
break;
case 'demo':
basePath = '/apps/demo/';
entryPointURL = 'https://api-demo.tugraz.at';
// "/pers" can't go here because it's not allowed in the "Content-Security-Policy"
nextcloudBaseURL = 'https://nc-dev.tugraz.at';
// "/index.php" is needed to don't get a "This origin is not allowed!" because the "target-origin" get parameter can't be read
nextcloudWebAppPasswordURL = nextcloudBaseURL + '/pers/index.php/apps/webapppassword';
nextcloudWebDavURL = nextcloudBaseURL + '/pers/remote.php/dav/files';
keyCloakServer = 'auth-test.tugraz.at';
keyCloakBaseURL = 'https://' + keyCloakServer + '/auth';
keyCloakClientId = 'auth-dev-mw-frontend';
pdfAsQualifiedlySigningServer = 'sig-dev.tugraz.at';
break;
default: let config;
console.error('Unknown build environment: ' + build); if (appEnv in appConfig) {
config = appConfig[appEnv];
} else if (appEnv === 'test') {
config = {
basePath: '/',
entryPointURL: 'https://test',
keyCloakBaseURL: 'https://test',
keyCloakClientId: '',
matomoUrl: '',
matomoSiteId: -1,
nextcloudBaseURL: 'https://test',
nextcloudName: '',
};
} else {
console.error(`Unknown build environment: '${appEnv}', use one of '${Object.keys(appConfig)}'`);
process.exit(1); process.exit(1);
} }
let nextcloudFileURL = nextcloudBaseURL + '/apps/files/?dir='; if (config.nextcloudBaseURL) {
config.nextcloudFileURL = config.nextcloudBaseURL + '/index.php/apps/files/?dir=';
config.nextcloudWebAppPasswordURL = config.nextcloudBaseURL + '/index.php/apps/webapppassword';
config.nextcloudWebDavURL = config.nextcloudBaseURL + '/remote.php/dav/files';
} else {
config.nextcloudFileURL = '';
config.nextcloudWebAppPasswordURL = '';
config.nextcloudWebDavURL = '';
}
function getBuildInfo() { function getOrigin(url) {
const child_process = require('child_process'); if (url)
const url = require('url'); return new URL(url).origin;
return '';
}
let remote = child_process.execSync('git config --get remote.origin.url').toString().trim(); config.CSP = `default-src 'self' 'unsafe-eval' 'unsafe-inline' \
let commit = child_process.execSync('git rev-parse --short HEAD').toString().trim(); ${getOrigin(config.matomoUrl)} ${getOrigin(config.keyCloakBaseURL)} ${getOrigin(config.entryPointURL)} \
httpbin.org ${getOrigin(config.nextcloudBaseURL)}; \
img-src * blob: data:`;
let parsed = url.parse(remote);
// convert git urls
if (parsed.protocol === null) {
parsed = url.parse('git://' + remote.replace(":", "/"));
parsed.protocol = 'https:';
}
let newPath = parsed.path.slice(0, parsed.path.lastIndexOf('.'));
let newUrl = parsed.protocol + '//' + parsed.host + newPath + '/commit/' + commit;
export default (async () => {
let privatePath = await getDistPath(pkg.name)
return { return {
info: commit, input: (appEnv != 'test') ? glob.sync('src/dbp-*.js') : glob.sync('test/**/*.js'),
url: newUrl,
time: new Date().toISOString(),
env: build
}
}
export async function getPackagePath(packageName, assetPath) {
const r = resolve();
const resolved = await r.resolveId(packageName);
let packageRoot;
if (resolved !== null) {
const id = (await r.resolveId(packageName)).id;
const packageInfo = r.getPackageInfoForId(id);
packageRoot = packageInfo.root;
} else {
// Non JS packages
packageRoot = path.dirname(require.resolve(packageName + '/package.json'));
}
return path.relative(process.cwd(), path.join(packageRoot, assetPath));
}
export default (async () => {return {
input: (build != 'test') ? glob.sync('src/*.js') : glob.sync('test/**/*.js'),
output: { output: {
dir: 'dist', dir: 'dist',
entryFileNames: '[name].js', entryFileNames: '[name].js',
...@@ -154,11 +92,6 @@ export default (async () => {return { ...@@ -154,11 +92,6 @@ export default (async () => {return {
} }
warn(warning); warn(warning);
}, },
watch: {
chokidar: {
usePolling: true
}
},
plugins: [ plugins: [
del({ del({
targets: 'dist/*' targets: 'dist/*'
...@@ -168,26 +101,24 @@ export default (async () => {return { ...@@ -168,26 +101,24 @@ export default (async () => {return {
include: ['**/*.ejs', '**/.*.ejs'], include: ['**/*.ejs', '**/.*.ejs'],
data: { data: {
getUrl: (p) => { getUrl: (p) => {
return url.resolve(basePath, p); return url.resolve(config.basePath, p);
}, },
getPrivateUrl: (p) => { getPrivateUrl: (p) => {
return url.resolve(`${basePath}local/${pkg.name}/`, p); return url.resolve(`${config.basePath}${privatePath}/`, p);
}, },
name: pkg.name, name: pkg.name,
entryPointURL: entryPointURL, entryPointURL: config.entryPointURL,
nextcloudBaseURL: nextcloudBaseURL, nextcloudBaseURL: config.nextcloudBaseURL,
nextcloudWebAppPasswordURL: nextcloudWebAppPasswordURL, nextcloudWebAppPasswordURL: config.nextcloudWebAppPasswordURL,
nextcloudWebDavURL: nextcloudWebDavURL, nextcloudWebDavURL: config.nextcloudWebDavURL,
nextcloudFileURL: nextcloudFileURL, nextcloudFileURL: config.nextcloudFileURL,
nextcloudName: nextcloudName, nextcloudName: config.nextcloudName,
keyCloakServer: keyCloakServer, keyCloakBaseURL: config.keyCloakBaseURL,
keyCloakBaseURL: keyCloakBaseURL, keyCloakClientId: config.keyCloakClientId,
keyCloakClientId: keyCloakClientId, CSP: config.CSP,
pdfAsQualifiedlySigningServer: pdfAsQualifiedlySigningServer, matomoUrl: config.matomoUrl,
environment: build, matomoSiteId: config.matomoSiteId,
matomoUrl: matomoUrl, buildInfo: getBuildInfo(appEnv)
matomoSiteId: matomoSiteId,
buildInfo: getBuildInfo()
} }
}), }),
resolve({ resolve({
...@@ -234,34 +165,30 @@ Dependencies: ...@@ -234,34 +165,30 @@ Dependencies:
emitFiles: true, emitFiles: true,
fileName: 'shared/[name].[hash][extname]' fileName: 'shared/[name].[hash][extname]'
}), }),
replace({
"process.env.BUILD": '"' + build + '"',
}),
useTerser ? terser() : false, useTerser ? terser() : false,
copy({ copy({
targets: [ targets: [
{src: 'assets/silent-check-sso.html', dest:'dist'}, {src: 'assets/*.css', dest: 'dist/' + await getDistPath(pkg.name)},
{src: 'assets/*.ico', dest: 'dist/' + await getDistPath(pkg.name)},
{src: 'assets/*.metadata.json', dest: 'dist'},
{src: 'assets/*.svg', dest: 'dist/' + await getDistPath(pkg.name)},
{src: 'assets/htaccess-shared', dest: 'dist/shared/', rename: '.htaccess'}, {src: 'assets/htaccess-shared', dest: 'dist/shared/', rename: '.htaccess'},
{src: 'assets/*.css', dest: 'dist/local/' + pkg.name}, {src: 'assets/icon-*.png', dest: 'dist/' + await getDistPath(pkg.name)},
{src: 'assets/*.ico', dest: 'dist/local/' + pkg.name}, {src: 'assets/manifest.json', dest: 'dist', rename: pkg.name + '.manifest.json'},
{src: 'assets/*.svg', dest: 'dist/local/' + pkg.name}, {src: 'assets/silent-check-sso.html', dest:'dist'},
{ {
src: 'node_modules/pdfjs-dist/build/pdf.worker.min.js', src: await getPackagePath('pdfjs-dist', 'es5/build/pdf.worker.js'),
dest: 'dist/local/' + pkg.name + '/pdfjs', dest: 'dist/' + await getDistPath(pkg.name, 'pdfjs'),
// enable signatures in pdf preview // enable signatures in pdf preview
transform: (contents) => contents.toString().replace('if("Sig"===a.fieldType){a.fieldValue=null;this.setFlags(r.AnnotationFlag.HIDDEN)}', '') transform: (contents) => contents.toString().replace('"Sig"', '"Sig-patched-show-anyway"')
}, },
{src: 'node_modules/pdfjs-dist/cmaps/*', dest: 'dist/local/' + pkg.name + '/pdfjs'}, // do we want all map files? {src: await getPackagePath('pdfjs-dist', 'cmaps/*'), dest: 'dist/' + await getDistPath(pkg.name, 'pdfjs')}, // do we want all map files?
{src: await getPackagePath('@dbp-toolkit/font-source-sans-pro', 'files/*'), dest: 'dist/local/' + pkg.name + '/fonts/source-sans-pro'}, {src: await getPackagePath('@dbp-toolkit/font-source-sans-pro', 'files/*'), dest: 'dist/' + await getDistPath(pkg.name, 'fonts/source-sans-pro')},
{src: 'node_modules/@dbp-toolkit/common/src/spinner.js', dest: 'dist/local/' + pkg.name, rename: 'spinner.js'}, {src: await getPackagePath('@dbp-toolkit/common', 'src/spinner.js'), dest: 'dist/' + await getDistPath(pkg.name)},
{src: 'node_modules/@dbp-toolkit/common/misc/browser-check.js', dest: 'dist/local/' + pkg.name, rename: 'browser-check.js'}, {src: await getPackagePath('@dbp-toolkit/common', 'misc/browser-check.js'), dest: 'dist/' + await getDistPath(pkg.name)},
{src: 'assets/icon-*.png', dest: 'dist/local/' + pkg.name}, {src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'), dest: 'dist/' + await getDistPath('@dbp-toolkit/common', 'icons')},
{src: 'assets/*-placeholder.png', dest: 'dist/local/' + pkg.name}, {src: await getPackagePath('tabulator-tables', 'dist/css'), dest: 'dist/' + await getDistPath('@dbp-toolkit/file-handling', 'tabulator-tables')},
{src: 'assets/manifest.json', dest: 'dist', rename: pkg.name + '.manifest.json'}, {src: await getPackagePath('qr-scanner', 'qr-scanner-worker.*'), dest: 'dist/' + await getDistPath('@dbp-toolkit/qr-code-scanner')},
{src: 'assets/*.metadata.json', dest: 'dist'},
{src: 'node_modules/@dbp-toolkit/common/assets/icons/*.svg', dest: 'dist/local/@dbp-toolkit/common/icons'},
{src: 'node_modules/tabulator-tables/dist/css', dest: 'dist/local/@dbp-toolkit/file-handling/tabulator-tables'},
{src: 'node_modules/qr-scanner/qr-scanner-worker.*', dest: 'dist/local/qr-code-scanner'},
], ],
}), }),
useBabel && babel({ useBabel && babel({
...@@ -293,10 +220,10 @@ Dependencies: ...@@ -293,10 +220,10 @@ Dependencies:
contentBase: '.', contentBase: '.',
host: '127.0.0.1', host: '127.0.0.1',
port: 8001, port: 8001,
historyApiFallback: basePath + pkg.name + '.html', historyApiFallback: config.basePath + pkg.name + '.html',
https: USE_HTTPS ? await generateTLSConfig() : false, https: useHTTPS ? await generateTLSConfig() : false,
headers: { headers: {
'Content-Security-Policy': `default-src 'self' 'unsafe-eval' 'unsafe-inline' analytics.tugraz.at ${keyCloakServer} ${entryPointURL} httpbin.org ${nextcloudBaseURL} www.handy-signatur.at ${pdfAsQualifiedlySigningServer} ; img-src * blob: data:` 'Content-Security-Policy': config.CSP
}, },
}) : false }) : false
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment