Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Quasar v0.16, enable vue-router history mode (#17)
Browse files Browse the repository at this point in the history
- Support history mode through the HABotHttpContext
- Reconfigure bundle splitting
- Cleanup the config
- Migrate the service worker to workbox
- Change default route (chat) to '/'
- Replace moment.js by date-fns (much smaller)

Temporary regressions:
Cannot use the service worker in dev mode to debug web push
Gzip compression is broken (some resources aren't gzipped)

Signed-off-by: Yannick Schaus <[email protected]>
  • Loading branch information
ghys authored Jun 20, 2018
1 parent b58bf1a commit c0fa4c8
Show file tree
Hide file tree
Showing 15 changed files with 4,908 additions and 4,104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getName() {

@Override
public String getUrl() {
return "../habot/index.html";
return "../habot/";
}

@Override
Expand All @@ -53,6 +53,7 @@ public String getImageUrl() {
}

public static final String HABOT_ALIAS = "/habot";
public static final String RESOURCES_BASE = "web/dist/pwa-mat";

private final Logger logger = LoggerFactory.getLogger(HABotDashboardTile.class);

Expand All @@ -62,12 +63,10 @@ public String getImageUrl() {
protected void activate(Map<String, Object> configProps, BundleContext context) {
try {
Object useGzipCompression = configProps.get("useGzipCompression");
HttpContext httpContext = (useGzipCompression != null
&& Boolean.parseBoolean(useGzipCompression.toString()))
? new HABotHttpContext(httpService.createDefaultHttpContext())
: null;
HttpContext httpContext = new HABotHttpContext(httpService.createDefaultHttpContext(), RESOURCES_BASE,
(useGzipCompression != null && Boolean.parseBoolean(useGzipCompression.toString())));

httpService.registerResources(HABOT_ALIAS, "web/dist/pwa-mat", httpContext);
httpService.registerResources(HABOT_ALIAS, RESOURCES_BASE, httpContext);
logger.info("Started HABot at " + HABOT_ALIAS);
} catch (NamespaceException e) {
logger.error("Error during HABot startup: {}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,59 @@

import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An implementation of {@link HttpContext} which will handle the gzip-compressed assets.
*
* @author Yannick Schaus
*/
public class HABotHttpContext implements HttpContext {
private final Logger logger = LoggerFactory.getLogger(HABotHttpContext.class);

private HttpContext defaultHttpContext;
private String resourcesBase;
private boolean useGzipCompression;

/**
* Constructs an {@link HABotHttpContext} with will another {@link HttpContext} as a base.
*
* @param defaultHttpContext the base {@link HttpContext} - use {@link HttpService#createDefaultHttpContext()} to
* create a default one
*/
public HABotHttpContext(HttpContext defaultHttpContext) {
public HABotHttpContext(HttpContext defaultHttpContext, String resourcesBase, boolean useGzipCompression) {
this.defaultHttpContext = defaultHttpContext;
this.resourcesBase = resourcesBase;
this.useGzipCompression = useGzipCompression;
}

@Override
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Add the Content-Encoding: gzip header to the response for selected resources
// (Disclaimer: I know, this is not the intended purpose of this method...)
if (request.getRequestURI().endsWith(".css")
|| (request.getRequestURI().endsWith(".js") && request.getRequestURI().contains("/js/"))) {
if (useGzipCompression && (request.getRequestURI().endsWith(".css")
|| (request.getRequestURI().endsWith(".js") && request.getRequestURI().contains("/js/")))) {
response.addHeader(HttpHeaders.CONTENT_ENCODING, "gzip");
}
return defaultHttpContext.handleSecurity(request, response);
}

@Override
public URL getResource(String name) {
logger.debug("Requesting resource " + name);
// Get the gzipped version for selected resources, built as static resources by webpack
URL defaultResource = defaultHttpContext.getResource(name);
if (name.endsWith(".css") || (name.endsWith(".js") && name.contains("/js/"))) {
if (useGzipCompression && (name.endsWith(".css") || (name.endsWith(".js") && name.contains("/js/")))) {
try {
return new URL(defaultResource.toString() + ".gz");
} catch (MalformedURLException e) {
return defaultResource;
}
} else {
if (name.equals(resourcesBase) || name.equals(resourcesBase + "/") || !name.contains(".")) {
return defaultHttpContext.getResource(resourcesBase + "/index.html");
}
return defaultResource;
}
}
Expand Down
27 changes: 23 additions & 4 deletions web/.babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
{
"presets": [
[ "env", {"modules": false} ],
"stage-2"
[
"@babel/preset-env", {
"modules": false,
"loose": false,
"useBuiltIns": "usage"
}
],
[
"@babel/preset-stage-2", {
"modules": false,
"loose": false,
"useBuiltIns": true,
"decoratorsLegacy": true
}
]
],
"plugins": ["transform-runtime"],
"comments": true
"plugins": [
[
"@babel/transform-runtime", {
"polyfill": false,
"regenerator": false
}
]
]
}
Loading

0 comments on commit c0fa4c8

Please sign in to comment.