· 7 years ago · Aug 29, 2018, 05:58 AM
1<div *ngIf="theRoute">
2 <iframe [src]="myUrl" appHeght id="myIFrame"></iframe>
3</div>
4
5ngOnInit() {
6 // The Router is correct, and so are the params.
7 this.myRouter = this.route.params.subscribe(
8 params => {
9 ...
10 this.myUrl = this.sanitizer.bypassSecurityTrustResourceUrl('http://127.0.0.1:8201/'); // location of the child
11 ... // more stuff, including change detection
12
13 }
14 );
15 }
16
17import os
18import datetime
19
20BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
21
22SECRET_KEY = 'my parent secret'
23
24DEBUG = True
25
26
27ALLOWED_HOSTS = '*'
28
29INSTALLED_APPS = [
30 'rest_framework',
31 'corsheaders',
32 'django.contrib.admin',
33 'django.contrib.auth',
34 'django.contrib.contenttypes',
35 'django.contrib.sessions',
36 'django.contrib.messages',
37 'django.contrib.staticfiles',
38 'django.contrib.sites',
39]
40
41MIDDLEWARE = [
42 'corsheaders.middleware.CorsMiddleware',
43 'django.middleware.security.SecurityMiddleware',
44 'django.contrib.sessions.middleware.SessionMiddleware',
45 'django.middleware.common.CommonMiddleware',
46 'django.middleware.csrf.CsrfViewMiddleware',
47 'django.contrib.auth.middleware.AuthenticationMiddleware',
48 'django.contrib.messages.middleware.MessageMiddleware',
49 'django.middleware.clickjacking.XFrameOptionsMiddleware',
50 'whitenoise.middleware.WhiteNoiseMiddleware',
51 'spa.middleware.SPAMiddleware',
52]
53
54
55ROOT_URLCONF = 'my_project_proj.urls'
56
57TEMPLATES = [
58 {
59 'BACKEND': 'django.template.backends.django.DjangoTemplates',
60 'DIRS': [os.path.join(BASE_DIR, 'templates')],
61 'APP_DIRS': True,
62 'OPTIONS': {
63 'context_processors': [
64 'django.template.context_processors.debug',
65 'django.template.context_processors.request',
66 'django.contrib.auth.context_processors.auth',
67 'django.contrib.messages.context_processors.messages',
68 ],
69 },
70 },
71]
72
73WSGI_APPLICATION = 'my_project_proj.wsgi.application'
74
75
76# Database
77DATABASES = {
78 'default': {
79 'ENGINE': 'django.db.backends.sqlite3',
80 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81 }
82}
83
84AUTH_PASSWORD_VALIDATORS = [
85 {
86 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
87 },
88 {
89 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
90 },
91 {
92 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
93 },
94 {
95 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
96 },
97]
98
99
100# Internationalization
101# https://docs.djangoproject.com/en/2.0/topics/i18n/
102
103LANGUAGE_CODE = 'en-us'
104
105TIME_ZONE = 'America/Chicago' #'UTC'
106
107USE_I18N = True
108
109USE_L10N = True
110
111USE_TZ = True
112
113STATIC_URL = '/static/'
114
115STATIC_ROOT = './frontend/dist/parent-app'
116
117CORS_ORIGIN_ALLOW_ALL = True
118CORS_ALLOW_CREDENTIALS = True
119CORS_ORIGIN_WHITELIST = (
120 'http://localhost:8000',
121 'http://127.0.0.1:8000',
122 'http://127.0.0.1:8201',
123 'http://localhost:8201'
124)
125CORS_ALLOW_METHODS = (
126 'DELETE',
127 'GET',
128 'OPTIONS',
129 'PATCH',
130 'POST',
131 'PUT',
132)
133CORS_ALLOW_HEADERS = (
134 'accept',
135 'accept-encoding',
136 'authorization',
137 'content-type',
138 'dnt',
139 'origin',
140 'user-agent',
141 'x-csrftoken',
142 'x-requested-with',
143)
144
145X_FRAME_OPTIONS = 'ALLOW'
146
147import os
148import datetime
149BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
150SECRET_KEY = 'my child secret'
151
152DEBUG = True
153ALLOWED_HOSTS = '*'
154
155INSTALLED_APPS = [
156 'rest_framework',
157 'corsheaders',
158 'django.contrib.admin',
159 'django.contrib.auth',
160 'django.contrib.contenttypes',
161 'django.contrib.sessions',
162 'django.contrib.messages',
163 'django.contrib.staticfiles',
164 'django.contrib.sites',
165]
166
167MIDDLEWARE = [
168 'corsheaders.middleware.CorsMiddleware',
169 'django.middleware.security.SecurityMiddleware',
170 'django.contrib.sessions.middleware.SessionMiddleware',
171 'django.middleware.common.CommonMiddleware',
172 'django.middleware.csrf.CsrfViewMiddleware',
173 'django.contrib.auth.middleware.AuthenticationMiddleware',
174 'django.contrib.messages.middleware.MessageMiddleware',
175 'django.middleware.clickjacking.XFrameOptionsMiddleware',
176 'whitenoise.middleware.WhiteNoiseMiddleware',
177 'spa.middleware.SPAMiddleware',
178]
179
180ROOT_URLCONF = 'my_child.urls'
181
182TEMPLATES = [
183 {
184 'BACKEND': 'django.template.backends.django.DjangoTemplates',
185 'DIRS': [os.path.join(BASE_DIR, 'templates')],
186 'APP_DIRS': True,
187 'OPTIONS': {
188 'context_processors': [
189 'django.template.context_processors.debug',
190 'django.template.context_processors.request',
191 'django.contrib.auth.context_processors.auth',
192 'django.contrib.messages.context_processors.messages',
193 ],
194 },
195 },
196]
197
198WSGI_APPLICATION = 'my_child.wsgi.application'
199
200
201# Database
202# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
203DATABASES = {
204 'default': {
205 'ENGINE': 'django.db.backends.sqlite3',
206 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
207 }
208}
209
210AUTH_PASSWORD_VALIDATORS = [
211 {
212 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
213 },
214 {
215 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
216 },
217 {
218 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
219 },
220 {
221 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
222 },
223]
224
225LANGUAGE_CODE = 'en-us'
226
227TIME_ZONE = 'America/Chicago' #'UTC'
228
229USE_I18N = True
230
231USE_L10N = True
232
233USE_TZ = True
234
235STATIC_URL = '/static/'
236STATIC_ROOT = './frontend/dist/child-one-app'
237
238CORS_ORIGIN_ALLOW_ALL = True
239CORS_ALLOW_CREDENTIALS = True
240CORS_ORIGIN_WHITELIST = (
241 'http://localhost:8000',
242 'http://127.0.0.1:8000',
243 'http://127.0.0.1:8201',
244 'http://localhost:8201'
245)
246CORS_ALLOW_METHODS = (
247 'DELETE',
248 'GET',
249 'OPTIONS',
250 'PATCH',
251 'POST',
252 'PUT',
253)
254CORS_ALLOW_HEADERS = (
255 'accept',
256 'accept-encoding',
257 'authorization',
258 'content-type',
259 'dnt',
260 'origin',
261 'user-agent',
262 'x-csrftoken',
263 'x-requested-with',
264)
265X_FRAME_OPTIONS = 'ALLOW'
266
267Invalid 'X-Frame-Options' header encountered when loading 'http://127.0.0.1:8201/': 'ALLOW' is not a recognized directive. The header will be ignored.
268
269ERROR DOMException: Blocked a frame with origin "http://127.0.0.1:8000" from accessing a cross-origin frame.
270
271import { Component, OnInit } from '@angular/core';
272import { LoaderService } from './services/loader.service';
273
274@Component({
275 selector: 'app-root',
276 templateUrl: './app.component.html',
277 styleUrls: ['./app.component.css']
278})
279export class AppComponent implements OnInit {
280 private loaderService: LoaderService = LoaderService.getInstance();
281 constructor() {
282 window.addEventListener('message', this.receiveMessage, false);
283 }
284
285 ngOnInit() {
286 this.loaderService.removeSpinner();
287 }
288
289 private receiveMessage(event) {
290 console.log("event origin:" , event.origin);
291
292 event.source.postMessage('verified', event.origin);
293 }
294}