├── .gitignore
├── idea-settings.jar
├── LICENSE
└── README.adoc
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 |
--------------------------------------------------------------------------------
/idea-settings.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mraible/idea-live-templates/HEAD/idea-settings.jar
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | = Matt Raible's IntelliJ IDEA Live Templates
2 |
3 | These are the https://www.jetbrains.com/help/idea/using-live-templates.html[IntelliJ IDEA Live Templates] that I've used in many demos and screencasts over the years.
4 |
5 | I used IntelliJ's https://www.jetbrains.com/help/idea/sharing-live-templates.html[sharing live templates] feature, to create `idea-settings.jar`. You should be able to import "Matt Raible's Shortcuts" using the following steps:
6 |
7 | 1. On the **File** menu, click **Import Settings**.
8 | 2. Specify the path to the JAR file with the exported live template configuration.
9 | 3. In the **Import Settings** dialog box, select the **Live templates** check box and click **OK**.
10 | 4. After restarting IntelliJ IDEA, you will see the imported live templates on the Live Templates page of the Settings / Preferences Dialog.
11 |
12 | https://www.jetbrains.com/idea/download/[Download IntelliJ IDEA] today! It's a spectacular IDEA for Java, Kotlin, TypeScript, JavaScript, S/CSS, and HTML.
13 |
14 | If you'd rather not import _all_ of my templates, you can clone this project and open it in IntelliJ (with the Asciidoctor plugin installed). You should be able to edit this file and add the shortcuts below as live templates (**Tools** > **Save as Live Template**). Make sure to set the file type to match the language.
15 |
16 | == Spring Boot
17 |
18 | **boot-entity**
19 | [source,java]
20 | ----
21 | @javax.persistence.Entity
22 | class $entity$ {
23 |
24 | @javax.persistence.Id
25 | @javax.persistence.GeneratedValue
26 | private java.lang.Long id;
27 | private java.lang.String name;
28 |
29 | public $entity$() {}
30 |
31 | public $entity$(String name) {
32 | this.name = name;
33 | }
34 |
35 | public java.lang.Long getId() {
36 | return id;
37 | }
38 |
39 | public void setId(java.lang.Long id) {
40 | this.id = id;
41 | }
42 |
43 | public java.lang.String getName() {
44 | return name;
45 | }
46 |
47 | public void setName(java.lang.String name) {
48 | this.name = name;
49 | }
50 |
51 | @java.lang.Override
52 | public java.lang.String toString() {
53 | return "$entity${" +
54 | "id=" + id +
55 | ", name='" + name + '\'' +
56 | '}';
57 | }
58 | }
59 | ----
60 |
61 | **boot-entity-lombok**
62 | [source,java]
63 | ----
64 | @lombok.Data
65 | @lombok.AllArgsConstructor
66 | @lombok.NoArgsConstructor
67 | @javax.persistence.Entity
68 | class $name$ {
69 |
70 | public $name$(java.lang.String name) {
71 | this.name = name;
72 | }
73 |
74 | @javax.persistence.Id
75 | @javax.persistence.GeneratedValue
76 | private java.lang.Long id;
77 |
78 | private java.lang.String name;
79 | }
80 | ----
81 |
82 | **boot-h2**
83 | [source,xml]
84 | ----
85 |
86 | com.h2database
87 | h2
88 |
89 | ----
90 |
91 | **boot-sql**
92 | [source,sql]
93 | ----
94 | insert into $entity$ (name) values ('First');
95 | insert into $entity$ (name) values ('Second');
96 | ----
97 |
98 | **boot-repository**
99 | [source,java]
100 | ----
101 | interface $entity$Repository extends JpaRepository<$entity$, java.lang.Long> {}
102 | ----
103 |
104 | **boot-command**
105 | [source,java]
106 | ----
107 | @org.springframework.stereotype.Component
108 | class $entity$CommandLineRunner implements org.springframework.boot.CommandLineRunner {
109 |
110 | private final $entity$Repository repository;
111 |
112 | public $entity$CommandLineRunner($entity$Repository repository) {
113 | this.repository = repository;
114 | }
115 |
116 | @java.lang.Override
117 | public void run(java.lang.String... strings) throws java.lang.Exception {
118 | repository.findAll().forEach(System.out::println);
119 | }
120 | }
121 | ----
122 |
123 | **boot-add**
124 | [source,java]
125 | ----
126 | // Top beers from https://www.beeradvocate.com/lists/top/
127 | Stream.of("Kentucky Brunch Brand Stout", "Good Morning", "Very Hazy", "King Julius",
128 | "Budweiser", "Coors Light", "PBR").forEach(name ->
129 | repository.save(new Beer(name))
130 | );
131 | ----
132 |
133 | **boot-controller**
134 | [source,java]
135 | ----
136 | @org.springframework.web.bind.annotation.RestController
137 | class $entity$Controller {
138 |
139 | private $entity$Repository repository;
140 |
141 | public $entity$Controller($entity$Repository repository) {
142 | this.repository = repository;
143 | }
144 |
145 | @org.springframework.web.bind.annotation.GetMapping("/$uriMapping$")
146 | java.util.Collection<$entity$> list() {
147 | return repository.findAll();
148 | }
149 | }
150 | ----
151 |
152 | **boot-good**
153 | [source,java]
154 | ----
155 | @GetMapping("/good-beers")
156 | public Collection goodBeers() {
157 |
158 | return repository.findAll().stream()
159 | .filter(this::isGreat)
160 | .collect(Collectors.toList());
161 | }
162 |
163 | private boolean isGreat(Beer beer) {
164 | return !beer.getName().equals("Budweiser") &&
165 | !beer.getName().equals("Coors Light") &&
166 | !beer.getName().equals("PBR");
167 | }
168 | ----
169 |
170 | **okta-maven-boot**
171 | [source,xml]
172 | ----
173 |
174 | com.okta.spring
175 | okta-spring-boot-starter
176 | $version$
177 |
178 | ----
179 |
180 | **spring-oauth2-yaml**
181 | [source,yaml]
182 | ----
183 | spring:
184 | security:
185 | oauth2:
186 | client:
187 | registration:
188 | okta:
189 | client-id: $clientId$
190 | client-secret: $clientSecret$
191 | provider:
192 | okta:
193 | authorization-uri: https://$yourOktaDomain$/oauth2/v1/authorize
194 | token-uri: https://$yourOktaDomain$/oauth2/v1/token
195 | user-info-uri: https://$yourOktaDomain$/oauth2/v1/userinfo
196 | jwk-set-uri: https://$yourOktaDomain$/oauth2/v1/keys
197 | ----
198 |
199 | **okta-oauth2**
200 | [source,yaml]
201 | ----
202 | okta.oauth2.issuer=https://$youtOktaDomain$/oauth2/default
203 | okta.oauth2.clientId=$clientId$
204 | ----
205 |
206 | **cors-filter**
207 | [source,java]
208 | ----
209 | @org.springframework.context.annotation.Bean
210 | public org.springframework.boot.web.servlet.FilterRegistrationBean simpleCorsFilter() {
211 | org.springframework.web.cors.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.UrlBasedCorsConfigurationSource();
212 | org.springframework.web.cors.CorsConfiguration config = new org.springframework.web.cors.CorsConfiguration();
213 | config.setAllowCredentials(true);
214 | config.setAllowedOrigins(java.util.Collections.singletonList("http://localhost:4200"));
215 | config.setAllowedMethods(java.util.Collections.singletonList("*"));
216 | config.setAllowedHeaders(java.util.Collections.singletonList("*"));
217 | source.registerCorsConfiguration("/**", config);
218 | org.springframework.boot.web.servlet.FilterRegistrationBean bean = new org.springframework.boot.web.servlet.FilterRegistrationBean(new org.springframework.web.filter.CorsFilter(source));
219 | bean.setOrder(org.springframework.core.Ordered.HIGHEST_PRECEDENCE);
220 | return bean;
221 | }
222 | ----
223 |
224 | == Angular
225 |
226 | **ng-giphy-service**
227 | [source,typescript]
228 | ----
229 | import { Injectable } from '@angular/core';
230 | import { HttpClient } from '@angular/common/http';
231 | import 'rxjs/add/operator/map';
232 |
233 | @Injectable()
234 | // http://tutorials.pluralsight.com/front-end-javascript/getting-started-with-angular-2-by-building-a-giphy-search-application
235 | export class GiphyService {
236 |
237 | // Public beta key: https://github.com/Giphy/GiphyAPI#public-beta-key
238 | giphyApi = '//api.giphy.com/v1/gifs/search?api_key=dc6zaTOxFJmzC&limit=1&q=';
239 |
240 | constructor(public http: HttpClient) {
241 | }
242 |
243 | get(searchTerm) {
244 | const apiLink = this.giphyApi + searchTerm;
245 | return this.http.get(apiLink).map((response: any) => {
246 | if (response.data.length > 0) {
247 | return response.data[0].images.original.url;
248 | } else {
249 | return 'https://media.giphy.com/media/YaOxRsmrv9IeA/giphy.gif'; // dancing cat for 404
250 | }
251 | });
252 | }
253 | }
254 | ----
255 |
256 | **ng-giphy-foreach**
257 | [source,typescript]
258 | ----
259 | for (const $item$ of this.$item$s) {
260 | this.giphyService.get($item$.name).subscribe(url => $item$.giphyUrl = url);
261 | }
262 | ----
263 |
264 | **ng-okta-service**
265 | [source,typescript]
266 | ----
267 | import { Injectable } from '@angular/core';
268 | import * as OktaSignIn from '@okta/okta-signin-widget/dist/js/okta-sign-in.min.js'
269 | import { ReplaySubject } from 'rxjs/ReplaySubject';
270 | import { Observable } from 'rxjs/Observable';
271 |
272 | @Injectable()
273 | export class OktaAuthService {
274 |
275 | signIn = new OktaSignIn({
276 | baseUrl: 'https://$yourOktaDomain$',
277 | clientId: '$clientId$',
278 | authParams: {
279 | issuer: 'https://$yourOktaDomain$',
280 | responseType: ['id_token', 'token'],
281 | scopes: ['openid', 'email', 'profile']
282 | }
283 | });
284 |
285 | public user$: Observable;
286 | public userSource: ReplaySubject;
287 |
288 | constructor() {
289 | this.userSource = new ReplaySubject(1);
290 | this.user$ = this.userSource.asObservable();
291 | }
292 |
293 | isAuthenticated() {
294 | // Checks if there is a current accessToken in the TokenManger.
295 | return !!this.signIn.tokenManager.get('accessToken');
296 | }
297 |
298 | login() {
299 | // Launches the widget and stores the tokens.
300 | this.signIn.renderEl({el: '#okta-signin-container'}, response => {
301 | if (response.status === 'SUCCESS') {
302 | response.forEach(token => {
303 | if (token.idToken) {
304 | this.signIn.tokenManager.add('idToken', token);
305 | }
306 | if (token.accessToken) {
307 | this.signIn.tokenManager.add('accessToken', token);
308 | }
309 | this.userSource.next(this.idTokenAsUser);
310 | this.signIn.hide();
311 | });
312 | } else {
313 | console.error(response);
314 | }
315 | });
316 | }
317 |
318 | get idTokenAsUser() {
319 | const token = this.signIn.tokenManager.get('idToken');
320 | return {
321 | name: token.claims.name,
322 | email: token.claims.email,
323 | username: token.claims.preferred_username
324 | }
325 | }
326 |
327 | async logout() {
328 | // Terminates the session with Okta and removes current tokens.
329 | this.signIn.tokenManager.clear();
330 | await this.signIn.signOut();
331 | this.signIn.remove();
332 | this.userSource.next(undefined);
333 | }
334 | }
335 | ----
336 |
337 | **ng-okta-headers**
338 | [source,ts]
339 | ----
340 | const headers: Headers = new Headers();
341 | if (this.oktaService.isAuthenticated()) {
342 | const accessToken = this.oktaService.signIn.tokenManager.get('accessToken');
343 | headers.append('Authorization', accessToken.tokenType + ' ' + accessToken.accessToken);
344 | }
345 | const options = new RequestOptions({ headers: headers });
346 | ----
347 |
348 | **ng-okta-oninit**
349 | [source,ts]
350 | ----
351 | user;
352 |
353 | constructor(public oktaService: OktaAuthService, private changeDetectorRef: ChangeDetectorRef) {
354 | }
355 |
356 | ngOnInit() {
357 | // 1. for initial load and browser refresh
358 | if (this.oktaService.isAuthenticated()) {
359 | this.user = this.oktaService.idTokenAsUser;
360 | } else {
361 | this.oktaService.login();
362 | }
363 |
364 | // 2. register a listener for authentication and logout
365 | this.oktaService.user$.subscribe(user => {
366 | this.user = user;
367 | if (!user) {
368 | this.oktaService.login();
369 | }
370 | // Let Angular know that model changed.
371 | // See https://github.com/okta/okta-signin-widget/issues/268 for more info.
372 | this.changeDetectorRef.detectChanges();
373 | });
374 | }
375 | ----
376 |
377 | **ng-okta-login**
378 | [source,html]
379 | ----
380 |
381 |
382 |
383 |
384 |
385 | Welcome {{user?.name}}!
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 | ----
394 |
395 | **ng-okta-css**
396 | [source,css]
397 | ----
398 | @import '~https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.1.0/css/okta-sign-in.min.css';
399 | @import '~https://ok1static.oktacdn.com/assets/js/sdk/okta-signin-widget/2.1.0/css/okta-theme.css';
400 | ----
401 |
402 | == Cloud Foundry
403 |
404 | **cf-manifest**
405 | [source,yaml]
406 | ----
407 | applications:
408 |
409 | - name: beer-server
410 | host: beer-server
411 | path: ./server/target/demo-0.0.1-SNAPSHOT.jar
412 | env :
413 | FORCE_HTTPS: true
414 |
415 | - name: beer-client
416 | host: beer-client
417 | path: ./client/dist/
418 | env :
419 | FORCE_HTTPS: true
420 | ----
421 |
422 | **cf-build**
423 | [source,yaml]
424 | ----
425 | #!/bin/bash
426 |
427 | # set origin for client on server
428 | sed -i -e "s|http://localhost:4200|https://beer-server.cfapps.io|g" $start/server/src/main/java/com/okta/developer/demo/DemoApplication.java
429 |
430 | mvn clean package -f $start/server/pom.xml
431 |
432 | cd $start/client
433 | rm -rf dist
434 | # set API URL
435 | sed -i -e "s|http://localhost:8080|https://beer-server.cfapps.io|g" $start/client/src/app/shared/beer/beer.service.ts
436 | # set redirectURI to client URI
437 | sed -i -e "s|http://localhost:4200|https://beer-client.cfapps.io|g" $start/client/src/app/shared/okta/okta.service.ts
438 | yarn && ng build -prod --aot
439 | touch dist/Staticfile
440 | # enable pushstate so no 404s on refresh
441 | echo 'pushstate: enabled' > dist/Staticfile
442 |
443 | cd $start
444 | cf push
445 |
446 | # reset and remove changed files
447 | git checkout $start
448 | rm -rf $start/server/src/main/java/com/okta/developer/demo/DemoApplication.java-e
449 | rm -rf $start/client/src/app/shared/beer/beer.service.ts-e
450 | rm -rf $start/client/src/app/shared/okta/okta.service.ts-e
451 | ----
452 |
453 | **cf-react**
454 | [source,bash]
455 | ----
456 | #!/bin/bash
457 | # Warning: this script has only been tested on macOS Sierra. There's a good chance
458 | # it won't work on other operating systems. If you get it working on another OS,
459 | # please send a pull request with any changes required. Thanks!
460 | set -e
461 |
462 | ### CloudFoundry CLI utilities
463 | CLOUD_DOMAIN=${DOMAIN:-run.pivotal.io}
464 | CLOUD_TARGET=api.${DOMAIN}
465 |
466 | function login(){
467 | cf api | grep ${CLOUD_TARGET} || cf api ${CLOUD_TARGET} --skip-ssl-validation
468 | cf apps | grep OK || cf login
469 | }
470 |
471 | function app_domain(){
472 | D=`cf apps | grep $1 | tr -s ' ' | cut -d' ' -f 6 | cut -d, -f1`
473 | echo $D
474 | }
475 |
476 | function deploy_service(){
477 | N=$1
478 | D=`app_domain $N`
479 | JSON='{"uri":"http://'$D'"}'
480 | cf create-user-provided-service $N -p $JSON
481 | }
482 |
483 | ### Installation
484 |
485 | cd `dirname $0`
486 | r=`pwd`
487 | echo $r
488 |
489 | ## Reset
490 | cf d -f react-client
491 | cf d -f good-beer-server
492 |
493 | cf a
494 |
495 | # Deploy the server
496 | cd $r/server
497 | mvn clean package
498 | cf push -p target/*jar good-beer-server --no-start --random-route
499 | cf set-env good-beer-server FORCE_HTTPS true
500 |
501 | # Get the URL for the server
502 | serverUri=https://`app_domain good-beer-server`
503 |
504 | # Deploy the client
505 | cd $r/client
506 | rm -rf build
507 | # replace the server URL in the client
508 | sed -i -e "s|http://localhost:8080|$serverUri|g" $r/client/src/BeerList.tsx
509 | yarn && yarn build
510 | cd build
511 | touch Staticfile
512 | echo 'pushstate: enabled' > Staticfile
513 | cf push react-client --no-start --random-route
514 | cf set-env react-client FORCE_HTTPS true
515 | cf start react-client
516 |
517 | # Get the URL for the client
518 | clientUri=https://`app_domain react-client`
519 |
520 | # replace the client URL in the server
521 | sed -i -e "s|http://localhost:3000|$clientUri|g" $r/server/src/main/java/com/example/demo/DemoApplication.java
522 |
523 | # redeploy the server
524 | cd $r/server
525 | mvn package -DskipTests
526 | cf push -p target/*jar good-beer-server
527 |
528 | # cleanup changed files
529 | git checkout $r/client
530 | git checkout $r/server
531 | rm $r/client/src/BeerList.tsx-e
532 | rm $r/server/src/main/java/com/example/demo/DemoApplication.java-e
533 |
534 | # show apps and URLs
535 | cf apps
536 | ----
537 |
538 | == Heroku
539 |
540 | **heroku-react**
541 | [source,bash]
542 | ----
543 | #!/bin/bash
544 | # Warning: this script has only been tested on macOS Sierra. There's a good chance
545 | # it won't work on other operating systems. If you get it working on another OS,
546 | # please send a pull request with any changes required. Thanks!
547 | set -e
548 |
549 | cd `dirname $0`
550 | r=`pwd`
551 | echo $r
552 |
553 | if [ -z "$(which heroku)" ]; then
554 | echo "You must install the Heroku CLI first!"
555 | echo "https://devcenter.heroku.com/articles/heroku-cli"
556 | exit 1
557 | fi
558 |
559 | if ! echo "$(heroku plugins)" | grep -q heroku-cli-deploy; then
560 | heroku plugins:install heroku-cli-deploy
561 | fi
562 |
563 | if ! echo "$(git remote -v)" | grep -q good-beer-server-; then
564 | server_app=good-beer-server-$RANDOM
565 | heroku create -r server $server_app
566 | else
567 | server_app=$(heroku apps:info -r server --json | python -c 'import json,sys;print json.load(sys.stdin)["app"]["name"]')
568 | fi
569 | serverUri="https://$server_app.herokuapp.com"
570 |
571 | if ! echo "$(git remote -v)" | grep -q react-client-; then
572 | client_app=react-client-$RANDOM
573 | heroku create -r client $client_app
574 | else
575 | client_app=$(heroku apps:info -r client --json | python -c 'import json,sys;print json.load(sys.stdin)["app"]["name"]')
576 | fi
577 | clientUri="https://$client_app.herokuapp.com"
578 |
579 | # replace the client URL in the server
580 | sed -i -e "s|http://localhost:3000|$clientUri|g" $r/server/src/main/java/com/example/demo/DemoApplication.java
581 |
582 | # Deploy the server
583 | cd $r/server
584 | mvn clean package -DskipTests
585 |
586 | heroku deploy:jar target/*jar -r server -o "--server.port=\$PORT"
587 | heroku config:set -r server FORCE_HTTPS="true"
588 |
589 | # Deploy the client
590 | cd $r/client
591 | rm -rf build
592 | # replace the server URL in the client
593 | sed -i -e "s|http://localhost:8080|$serverUri|g" $r/client/src/BeerList.tsx
594 | yarn && yarn build
595 | cd build
596 |
597 | cat << EOF > static.json
598 | {
599 | "https_only": true,
600 | "root": ".",
601 | "routes": {
602 | "/**": "index.html"
603 | }
604 | }
605 | EOF
606 |
607 | rm -f ../dist.tgz
608 | tar -zcvf ../dist.tgz .
609 |
610 | # TODO replace this with the heroku-cli-static command `heroku static:deploy`
611 | source=$(curl -n -X POST https://api.heroku.com/apps/$client_app/sources -H 'Accept: application/vnd.heroku+json; version=3')
612 | get_url=$(echo "$source" | python -c 'import json,sys;print json.load(sys.stdin)["source_blob"]["get_url"]')
613 | put_url=$(echo "$source" | python -c 'import json,sys;print json.load(sys.stdin)["source_blob"]["put_url"]')
614 | curl "$put_url" -X PUT -H 'Content-Type:' --data-binary @../dist.tgz
615 | cat << EOF > build.json
616 | {
617 | "buildpacks": [{ "url": "https://github.com/heroku/heroku-buildpack-static" }],
618 | "source_blob": { "url" : "$get_url" }
619 | }
620 | EOF
621 | build_out=$(curl -n -s -X POST https://api.heroku.com/apps/$client_app/builds \
622 | -d "$(cat build.json)" \
623 | -H 'Accept: application/vnd.heroku+json; version=3' \
624 | -H "Content-Type: application/json")
625 | output_stream_url=$(echo "$build_out" | python -c 'import json,sys;print json.load(sys.stdin)["output_stream_url"]')
626 | curl -s -L "$output_stream_url"
627 |
628 | rm build.json
629 | rm ../dist.tgz
630 |
631 | # cleanup changed files
632 | git checkout $r/client
633 | git checkout $r/server
634 | rm $r/client/src/BeerList.tsx-e
635 | rm $r/server/src/main/java/com/example/demo/DemoApplication.java-e
636 |
637 | # show apps and URLs
638 | heroku open -r client
639 | ----
640 |
641 | == JHipster
642 |
643 | **jh-findBy**
644 | [source,java]
645 | ----
646 | findByBlogUserLoginOrderByDateDesc(
647 | org.jhipster.blog.security.SecurityUtils.getCurrentUserLogin().orElse(null), pageable);
648 | ----
649 |
650 | **jh-get**
651 | [source,ts]
652 | ----
653 | if (blog.isPresent() && blog.get().getUser() != null &&
654 | !blog.get().getUser().getLogin().equals(org.jhipster.blog.security.SecurityUtils.getCurrentUserLogin().orElse(""))) {
655 | return new org.springframework.http.ResponseEntity<>("Unauthorized", org.springframework.http.HttpStatus.UNAUTHORIZED);
656 | }
657 | ----
658 |
659 | **jh-entries**
660 | [source,html]
661 | ----
662 |