Skip to content

Commit 3d9d372

Browse files
author
Jan Mikolajczak
committed
Host the static website separately from api in the LIVE environment
This simplifies routing and the deployment structure and makes the dev env more similar to the production ones.
1 parent a27d673 commit 3d9d372

File tree

7 files changed

+15
-31
lines changed

7 files changed

+15
-31
lines changed

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Aviary
22
There are two components, aviary-api and aviary-angular with the front-end code.
3-
They are designed to run together as a single
4-
[gae](https://cloud.google.com/appengine/docs/standard/java/runtime-java8)
5-
app, currently available at https://aviary-130922.appspot.com
3+
The aviary-angular module is an angular website, hosted on a static-files bucket.
4+
The aviary-api module is a [gae app](https://cloud.google.com/appengine/docs/standard/java/runtime-java8).
65

76
## Releasing
8-
1. Build the frontend (see its README)
9-
2. Deploy the backend (see its README), the deployment will include the front-end build
7+
The two modules need to be released separately, see respective READMES for instructions
108

119
## Services used
1210
Aviary uses
@@ -36,4 +34,4 @@ To provide a range of sign-in options for users, aviary utilises firebase.
3634
### A user authentication flow:
3735
1. Front-end talks directly to firebase to login a user, obtaining an auth token
3836
1. It passes the firebase id and token to the backend with requests
39-
1. The backed uses firebase sdk to authenticate the token
37+
1. The backed uses authenticates the token

aviary-angular/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Run `ng generate component component-name` to generate a new component. You can
1212

1313
## Build
1414
Run `ng build` to build the project into the `dist/` directory.
15-
`dist/` will be included in the server deployment as the frontend resources. Run before deploying.
15+
This `dist/` should be deployed to one of the website-hosting buckets in Google storage under the appropriate name.
1616
Use the `--env=prod` flag for a production build. Ideally we'd use the `--prod` flag which also turns AOT compilation
1717
on, but this throws an error at the time of writing.
1818

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// noinspection JSUnusedGlobalSymbols
22
export const environment = {
33
production: true,
4-
apiAddress: "/api/"
4+
apiAddress: "https://aviary-130922.appspot.com/api/"
55
};

aviary-api/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ To run the application:`mvn appengine:run`
4444
To use visit: http://localhost:8080/
4545

4646
### Deploying
47-
1. First, make sure aviary-angular has been built into its /dist folder.
48-
2. Set up a Google App Enginge Deployment (Tools -> Google Cloud Tools -> Deploy to App Engine)
47+
Set up a Google App Enginge Deployment (Tools -> Google Cloud Tools -> Deploy to App Engine)
4948
* As `Deployment:` select `Maven Build: aviary-api`
5049
* Log in to your google account and select the `aviary-130922` project
5150

5251
(This may not be possible without the plugin at the moment. If it is, something along the lines of
5352
`mvn package appengine:deploy`
5453
might work, but it's not tested)
5554

56-
To use vist: https://aviary-130922.appspot.com
55+
The api gets deployed to: https://aviary-130922.appspot.com.
5756

5857
## Testing
5958

aviary-api/pom.xml

-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ limitations under the License.
3232

3333
<dependencies>
3434
<dependency>
35-
<!--TODO update and see if servlets 3.0 work on deployment -->
3635
<groupId>com.google.appengine</groupId>
3736
<artifactId>appengine-api-1.0-sdk</artifactId>
3837
<version>1.9.54</version>
@@ -211,13 +210,6 @@ limitations under the License.
211210
<configuration>
212211
<archiveClasses>true</archiveClasses>
213212
<failOnMissingWebXml>false</failOnMissingWebXml>
214-
<webResources>
215-
<resource>
216-
<!-- Would be good to add a step capable of building this - rn it needs `ng build -prod -e` run-->
217-
<!-- this is relative to the pom.xml directory -->
218-
<directory>../aviary-angular/dist/</directory>
219-
</resource>
220-
</webResources>
221213
</configuration>
222214
</plugin>
223215
<!-- [START cloudplugin] -->

aviary-api/src/main/kotlin/eu/bluehawkqs/aviary/api/controllers/ApiResponseFilter.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package eu.bluehawkqs.aviary.api.controllers
22

3+
import com.google.appengine.api.utils.SystemProperty
34
import javax.ws.rs.container.ContainerRequestContext
45
import javax.ws.rs.container.ContainerResponseContext
56
import javax.ws.rs.container.ContainerResponseFilter
67

78
class ApiResponseFilter : ContainerResponseFilter {
89
override fun filter(requestContext: ContainerRequestContext, responseContext: ContainerResponseContext) {
910
responseContext.headers.apply {
10-
// TODO Investigate setting up a proxy in dev angular to remove all cross-origin stuff. either way tighten this up
11-
add("Access-Control-Allow-Origin", "*")
11+
add("Access-Control-Allow-Origin", when(SystemProperty.environment.value()) {
12+
SystemProperty.Environment.Value.Production -> "http://aviary.bluehawkqs.eu"
13+
SystemProperty.Environment.Value.Development -> "http://localhost:4200"
14+
else -> throw Exception("Environment not recognised")
15+
})
1216
add("Access-Control-Allow-Headers", "Authorization")
1317
add("Access-Control-Allow-Headers", "Content-Type")
1418
}

aviary-api/src/main/webapp/WEB-INF/web.xml

+1-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
<listener-class>eu.bluehawkqs.aviary.api.di.DaggerServletContextListener</listener-class>
55
</listener>
66

7-
8-
<servlet>
9-
<servlet-name>Index</servlet-name>
10-
<jsp-file>/index.html</jsp-file>
11-
</servlet>
12-
<servlet-mapping>
13-
<servlet-name>Index</servlet-name>
14-
<url-pattern>/</url-pattern>
15-
</servlet-mapping>
16-
177
<servlet>
188
<servlet-name>Jersey Web Application</servlet-name>
199
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
@@ -40,4 +30,5 @@
4030
<servlet-name>Jersey Web Application</servlet-name>
4131
<url-pattern>/api/*</url-pattern>
4232
</servlet-mapping>
33+
4334
</web-app>

0 commit comments

Comments
 (0)