Skip to content

Commit

Permalink
Merge pull request #741 from FgForrest/737-preconfigured-connection-i…
Browse files Browse the repository at this point in the history
…n-embedded-evitalab-are-sometimes-not-loaded

 fix(#737): proper cache control for evitaLab sources
  • Loading branch information
lukashornych authored Nov 8, 2024
2 parents fc3b876 + a5bab2a commit 9b45103
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.QueryParamsBuilder;
import com.linecorp.armeria.common.ServerCacheControl;
import com.linecorp.armeria.server.HttpService;
import com.linecorp.armeria.server.ServiceRequestContext;
import com.linecorp.armeria.server.file.HttpFile;
Expand Down Expand Up @@ -123,13 +124,23 @@ private HttpResponse serveRoot(@Nonnull ServiceRequestContext ctx,
return HttpResponse.builder()
.status(HttpStatus.SEE_OTHER)
.header(HttpHeaderNames.LOCATION, ctx.path() + "?" + newQueryString)
// we don't want to cache evitaLab index file because in development environments, developers often
// switch evitaDB server under same hostname and each evitaDB server may have different version or config
// therefore we need to make sure that the initialization of evitaLab is always fresh
.header(HttpHeaderNames.CACHE_CONTROL, ServerCacheControl.DISABLED.asHeaderValue())
.build();
}

return HttpFile.of(
return HttpFile.builder(
classLoader,
createJarResourceLocationWithForwardSlashes(fsPath.resolve("index.html"))
)
// we don't want to cache evitaLab index file because in development environments, developers often
// switch evitaDB server under same hostname and each evitaDB server may have different version or config
// therefore we need to make sure that the initialization of evitaLab is always fresh
.lastModified(false)
.cacheControl(ServerCacheControl.DISABLED)
.build()
.asService()
.serve(ctx, req);
}
Expand All @@ -140,12 +151,15 @@ private HttpResponse serveAssets(@Nonnull ServiceRequestContext ctx,
@Nonnull ClassLoader classLoader,
@Nonnull String path,
@Nonnull Path fsPath) throws Exception {
return HttpFile.of(
return HttpFile.builder(
classLoader,
createJarResourceLocationWithForwardSlashes(
fsPath.resolve(Paths.get(path.substring(1)))
)
)
// all assets are versioned so we can cache them for long and never change
.cacheControl(ServerCacheControl.IMMUTABLE)
.build()
.asService()
.serve(ctx, req);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b45103

Please sign in to comment.