Commit e2893c69 authored by lukas.burgey's avatar lukas.burgey

Enable local development using ng serve

This only works if the server allows non-https
parent f77d8d26
......@@ -11,7 +11,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"aot": true,
"aot": true,
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
......@@ -28,12 +28,12 @@
},
"configurations": {
"production": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
......@@ -49,17 +49,29 @@
"with": "src/environments/environment.prod.ts"
}
]
},
"local": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.local.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "feudal:build"
"browserTarget": "feudal:build",
"proxyConfig": "src/proxy.conf.js"
},
"configurations": {
"production": {
"browserTarget": "feudal:build:production"
},
"local": {
"browserTarget": "feudal:build:local"
}
}
},
......
......@@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --configuration=local",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
......
......@@ -10,6 +10,8 @@ import { Message } from '@stomp/stompjs';
import { SnackBarService } from './snackbar.service';
import { PreferencesService, Prefs } from './preferences/preferences.service';
import { environment } from '../environments/environment';
import {
VO, User, Update, State, Deployment, DeploymentState, SSHKey, NewSSHKey, IdP, Service, Site, Answers, IdPInfo
} from './types/types.module';
......@@ -128,9 +130,14 @@ export class UserService {
// handle with care
const login = userID;
const passcode = this.cookieService.get('sessionid');
let scheme = 'wss';
if ('webSocketScheme' in environment) {
scheme = environment['webSocketScheme'];
console.log('Using websocket scheme', scheme);
}
const stompConfig: StompConfig = {
// Which server?
url: 'wss://' + window.location.host + '/ws',
url: scheme + '://' + window.location.host + '/ws',
// Headers
// Typical keys: login, passcode, host
......@@ -304,7 +311,11 @@ export class UserService {
public login(idp?: IdP): void {
const redirect = (arg: IdP) => {
window.location.href = '/?idp=' + encodeURIComponent(arg.issuer_uri);
let authPath = '/';
if ('authPath' in environment) {
authPath = environment['authPath']
}
window.location.href = authPath + '?idp=' + encodeURIComponent(arg.issuer_uri);
};
// was there an argument?
......
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = {
production: false,
webSocketScheme: 'ws',
authPath: '/auth/request',
};
// onProxyRes removes the secure tag from sessionid cookie
// otherwise local ng serve + remote backend won't work
// https://github.com/http-party/node-http-proxy/issues/1165
let onProxyRes = (proxyRes, req, res) => {
const sc = proxyRes.headers['set-cookie'];
if (Array.isArray(sc)) {
proxyRes.headers['set-cookie'] = sc.map(sc => {
return sc.split(';')
.filter(v => v.trim().toLowerCase() !== 'secure')
.join('; ')
});
}
};
const PROXY_CONFIG = [
{
context: [
'/auth',
'/admin',
'/webpage',
'/user',
'/rest',
'/django-static',
],
target: 'http://feudal-dev.scc.kit.edu',
secure: false,
changeOrigin: true,
logLevel: 'debug',
onProxyRes: onProxyRes,
},
{
context: [
'/ws',
],
target: 'http://feudal-dev.scc.kit.edu',
secure: false,
changeOrigin: true,
logLevel: 'debug',
onProxyRes: onProxyRes,
ws: true,
},
]
module.exports = PROXY_CONFIG;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment