Fix auth apollo link and big docker image size

This commit is contained in:
Simon Prévost 2019-12-04 12:35:52 -05:00
parent 2eae532580
commit 3d652a4a30
5 changed files with 22 additions and 11 deletions

View File

@ -26,7 +26,9 @@ webapp/node_modules
webapp/tmp
webapp/tests
webapp/dist
webapp/webapp-dist
jipt/node_modules
jipt/.cache
jipt/dist
jipt/webapp-dist
cli

View File

@ -67,8 +67,8 @@ WORKDIR /opt/accent
# Copy the OTP binary and assets deps from the build step
COPY --from=builder /opt/build .
COPY --from=webapp-builder /opt/build .
COPY --from=jipt-builder /opt/build .
COPY --from=webapp-builder /opt/build/webapp-dist ./webapp-dist
COPY --from=jipt-builder /opt/build/jipt-dist ./jipt-dist
RUN mv /opt/accent/webapp-dist /opt/accent/lib/accent-$APP_VERSION/priv/static/webapp && \
mv /opt/accent/jipt-dist /opt/accent/lib/accent-$APP_VERSION/priv/static/jipt

View File

@ -0,0 +1,3 @@
import Component from '@ember/component';
export default Component.extend();

View File

@ -0,0 +1,5 @@
import Component from '@ember/component';
export default Component.extend({
tagName: 'header'
});

View File

@ -41,17 +41,18 @@ const link = new BatchHttpLink({uri, batchInterval: 50, batchMax: 50});
const absintheBatchLink = new ApolloLink((operation, forward) => {
return forward(operation).map(response => response.payload);
});
const authLink = (session, router) => {
const authLink = (session) => {
return new ApolloLink((operation, forward) => {
const token = session.credentials.token;
if (!token) return router.transitionTo('login');
operation.setContext(({headers = {}}) => ({
headers: {
...headers,
authorization: `Bearer ${token}`
}
}));
if (token) {
operation.setContext(({headers = {}}) => ({
headers: {
...headers,
authorization: `Bearer ${token}`
}
}));
}
return forward(operation);
});
@ -67,8 +68,8 @@ export default Service.extend({
const client = new ApolloClient({
uri,
link: from([
authLink(this.session),
absintheBatchLink,
authLink(this.session, this.router),
link
]),
cache