Skip to content

Commit

Permalink
feat: Enable HttpServer on iOS when offline
Browse files Browse the repository at this point in the history
In iOS, we disabled HttpServer for all cozy-apps as the WebView API may
behave differently

The side effect is that we cannot open those app when offline as we
cannot inject minimal code to make them work without network access

So we want to enable HttpServer on those apps when we detect the app to
be offline

Related PR: #486
  • Loading branch information
Ldoppea committed Sep 24, 2024
1 parent 1218568 commit 2f518b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libs/httpserver/httpServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const HttpServerProvider = (
}

await setCookie(cookie, client)
const rawHtml = await getIndexForFqdnAndSlug(fqdn, slug)
const rawHtml = await getIndexForFqdnAndSlug(fqdn, slug, source)

if (!rawHtml) {
return {
Expand Down
11 changes: 9 additions & 2 deletions src/libs/httpserver/indexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
prepareAssets
} from '/libs/httpserver/copyAllFilesFromBundleAssets'
import { TemplateValues } from '/libs/httpserver/indexDataFetcher'
import { HtmlSource } from '/libs/httpserver/models'
import {
getCurrentAppConfigurationForFqdnAndSlug,
setCurrentAppVersionForFqdnAndSlug
Expand Down Expand Up @@ -87,11 +88,17 @@ const isSlugInBlocklist = (currentSlug: string): boolean =>

export const getIndexForFqdnAndSlug = async (
fqdn: string,
slug: string
slug: string,
source: HtmlSource
): Promise<string | false> => {
if (shouldDisableGetIndex()) return false // Make cozy-app hosted by webpack-dev-server work with HTTPServer

if (!isSlugInAllowlist(slug) || isSlugInBlocklist(slug)) return false
if (
(!isSlugInAllowlist(slug) || isSlugInBlocklist(slug)) &&
source !== 'cache'
) {
return false
}

await initLocalBundleIfNotExist(fqdn, slug)

Expand Down

0 comments on commit 2f518b6

Please sign in to comment.