Skip to content

Instantly share code, notes, and snippets.

@oivoodoo
Created November 7, 2023 16:11
Show Gist options
  • Save oivoodoo/d8a55416482cc6538acdd7816e00cf38 to your computer and use it in GitHub Desktop.
Save oivoodoo/d8a55416482cc6538acdd7816e00cf38 to your computer and use it in GitHub Desktop.
deno example to verify and deep link
// Follow this setup guide to integrate the Deno language server with your editor:
// https://deno.land/manual/getting_started/setup_your_environment
// This enables autocomplete, go to definition, etc.
import { config } from "https://deno.land/x/[email protected]/mod.ts";
import { Application, Context, Router } from "https://deno.land/x/oak/mod.ts";
import userAgent from "https://deno.land/x/[email protected]/mod.ts";
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import { Status } from "https://deno.land/x/[email protected]/deps.ts";
import { appStore, googlePlay } from "./linking.ts";
// The directory of this module
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
// The public directory (with "index.html" in it)
const publicDir = path.join(moduleDir, "public");
config({ export: true });
type Platform = "iOS" | "Android";
const Links: {
iOS: string;
Android: string;
} = {
iOS: "itms://apps.apple.com/us/app/pushup-challenges/id6450053262",
Android: "https://play.google.com/store/apps/details?id=co.bitscorp.pushup",
};
const DEFAULT_LINK = "https://pushup.bitscorp.co";
const router = new Router();
const read = (...filePath: string[]): Promise<Uint8Array> => {
return Deno.readFile(path.join(publicDir, ...filePath));
};
router.get("/invitations/:code", (context) => {
const ua = userAgent(context.request.headers.get("user-agent") as string);
context.response.redirect(Links[ua.os.name as Platform] || DEFAULT_LINK);
});
router.get("/", async (context) => {
context.response.body = await read("index.html");
context.response.type = "text/html";
});
router.get("/.well-known/apple-app-site-association", (context) => {
context.response.type = "json";
context.response.body = appStore;
});
router.get("/apple-app-site-association", (context) => {
context.response.type = "json";
context.response.body = appStore;
});
router.get("/.well-known/assetlinks.json", (context) => {
context.response.type = "json";
context.response.body = googlePlay;
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
// static content
app.use(async (context, next) => {
const root = `${Deno.cwd()}/public`;
try {
await context.send({ root });
} catch {
next();
}
});
// page not found
app.use(async (context) => {
context.response.status = Status.NotFound;
context.response.body = `"${context.request.url}" not found`;
});
const port = parseInt(Deno.env.get("PORT") || "8000");
await app.listen({ port });
const linking = {
prefixes: ["pushup://", "https://pushup.bitscorp.co"],
config: {
screens: {
InvitationsHomeScreen: "invitations/:code",
Main: {
screens: {
HomeScreen: "HomeScreen",
},
},
},
},
};
return (
<NavigationContainer
linking={linking}
ref={navigationRef}
theme={(theme === "light" ? LightTheme : DarkTheme) as unknown as Theme}
onReady={() => {
routeNameRef.current = navigationRef?.current?.getCurrentRoute()?.name;
}}
onStateChange={onChangeState}
>
<Nav />
<StatusBar barStyle={theme === "light" ? "dark-content" : "light-content"} />
</NavigationContainer>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment