Skip to content

Commit 2b924b7

Browse files
author
chiku
committed
Make main frontend selectable between ember-osf-web and angular-osf
1 parent 36d2ca9 commit 2b924b7

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,23 @@ services:
284284
- ember_osf_web_dist_vol:/code/dist
285285
stdin_open: true
286286

287+
#################
288+
# Anguler OSF #
289+
#################
290+
291+
angular_osf:
292+
image: chiku314/angular-osf:latest
293+
ports:
294+
- '4300:4300'
295+
depends_on:
296+
- api
297+
- web
298+
environment:
299+
- CHOKIDAR_USEPOLLING=true
300+
- WATCHPACK_POLLING=true
301+
- NG_CLI_ANALYTICS=false
302+
command: ['npx', 'ng', 'serve', '--host', '0.0.0.0', '--port', '4300', '--poll', '2000']
303+
287304
#############
288305
# Preprints #
289306
#############

website/ember_osf_web/views.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,33 @@
55

66
from website.settings import EXTERNAL_EMBER_APPS
77

8-
ember_osf_web_dir = os.path.abspath(os.path.join(os.getcwd(), EXTERNAL_EMBER_APPS['ember_osf_web']['path']))
8+
def get_primary_app_config():
9+
from website.settings import PRIMARY_WEB_APP
10+
return EXTERNAL_EMBER_APPS.get(PRIMARY_WEB_APP, {})
11+
12+
def get_primary_app_dir():
13+
app_config = get_primary_app_config()
14+
if 'path' in app_config:
15+
return os.path.abspath(os.path.join(os.getcwd(), app_config['path']))
16+
return None
917

1018
routes = [
1119
'/institutions/',
1220
]
1321

1422
def use_ember_app(**kwargs):
23+
from rest_framework import status as http_status
24+
from framework.exceptions import HTTPError
1525
from website.views import stream_emberapp
16-
resp = stream_emberapp(EXTERNAL_EMBER_APPS['ember_osf_web']['server'], ember_osf_web_dir)
26+
27+
app_config = get_primary_app_config()
28+
if not app_config:
29+
raise HTTPError(
30+
http_status.HTTP_500_INTERNAL_SERVER_ERROR,
31+
data={'message': 'Primary web app not configured'}
32+
)
33+
34+
resp = stream_emberapp(app_config['server'], get_primary_app_dir())
1735
messages = pop_status_messages()
1836
if messages:
1937
try:

website/routes.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ def ember_app(path=None):
265265
raise HTTPError(http_status.HTTP_404_NOT_FOUND)
266266

267267
if settings.PROXY_EMBER_APPS:
268-
path = request.path[len(ember_app['path']):]
268+
strip_prefix = ember_app.get('strip_prefix')
269+
if strip_prefix or strip_prefix is None:
270+
path = request.path[len(ember_app['path']):]
271+
else:
272+
path = request.path
269273
url = urljoin(ember_app['server'], path)
270274
resp = requests.get(url, stream=True, timeout=EXTERNAL_EMBER_SERVER_TIMEOUT, headers={'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'})
271275
excluded_headers = ['content-encoding', 'content-length', 'transfer-encoding', 'connection']
@@ -378,7 +382,11 @@ def make_url_map(app):
378382
),
379383
], prefix='/' + prefix)
380384

381-
if EXTERNAL_EMBER_APPS.get('ember_osf_web'):
385+
# Import PRIMARY_WEB_APP setting
386+
from website.settings import PRIMARY_WEB_APP
387+
388+
primary_app_config = EXTERNAL_EMBER_APPS.get(PRIMARY_WEB_APP)
389+
if primary_app_config:
382390
process_rules(app, [
383391
Rule(
384392
ember_osf_web_views.routes,
@@ -387,8 +395,8 @@ def make_url_map(app):
387395
notemplate
388396
)
389397
])
390-
if 'routes' in EXTERNAL_EMBER_APPS['ember_osf_web']:
391-
for route in EXTERNAL_EMBER_APPS['ember_osf_web']['routes']:
398+
if 'routes' in primary_app_config:
399+
for route in primary_app_config['routes']:
392400
process_rules(app, [
393401
Rule(
394402
[

website/settings/local-ci.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'suffix': ':4201/'
2828
}
2929
USE_EXTERNAL_EMBER = True
30+
PRIMARY_WEB_APP = 'ember_osf_web'
3031
EXTERNAL_EMBER_APPS = {
3132
'ember_osf_web': {
3233
'server': 'http://localhost:4200',

website/settings/local-dist.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
PROXY_EMBER_APPS = True
3434
EMBER_DOMAIN = environ.get('EMBER_DOMAIN', 'localhost')
3535
LIVE_RELOAD_DOMAIN = f'http://{EMBER_DOMAIN}:4200' # Change port for the current app
36+
# Primary web frontend app configuration - change this to switch between ember and angular
37+
PRIMARY_WEB_APP = 'angular_osf'
3638
EXTERNAL_EMBER_APPS = {
3739
'ember_osf_web': {
3840
'server': f'http://{EMBER_DOMAIN}:4200/',
@@ -43,6 +45,16 @@
4345
'handbook',
4446
],
4547
},
48+
'angular_osf': {
49+
'server': f'http://{EMBER_DOMAIN}:4300/',
50+
'path': '/angular_osf/',
51+
'strip_prefix': False,
52+
'routes': [
53+
'collections',
54+
'registries',
55+
'handbook',
56+
],
57+
},
4658
'preprints': {
4759
'server': f'http://{EMBER_DOMAIN}:4201/',
4860
'path': '/preprints/'

website/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@
3535
from api.waffle.utils import storage_i18n_flag_active, flag_is_active
3636

3737
logger = logging.getLogger(__name__)
38-
ember_osf_web_dir = os.path.abspath(os.path.join(os.getcwd(), EXTERNAL_EMBER_APPS['ember_osf_web']['path']))
38+
def get_primary_web_app_dir():
39+
from website.settings import PRIMARY_WEB_APP
40+
primary_app_config = EXTERNAL_EMBER_APPS.get(PRIMARY_WEB_APP, {})
41+
if 'path' in primary_app_config:
42+
return os.path.abspath(os.path.join(os.getcwd(), primary_app_config['path']))
43+
return None
44+
45+
primary_web_app_dir = get_primary_web_app_dir()
3946

4047

4148
def serialize_contributors_for_summary(node, max_count=3):

0 commit comments

Comments
 (0)