Skip to content

feat: Initial #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}

62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Dynamic Link Function

This function is a handler for HTTP requests which redirects the user to a specific target URL based on their user-agent (which typically indicates their operating system and browser type). The redirection configuration is passed in through the `CONFIG` environment variable as a JSON string. The `CONFIG` variable is expected to contain an array of objects, where each object should have a `path` and `targets`.

Here are some example `CONFIG` environment variable settings and the corresponding use cases:

1. **Mobile vs. Desktop Redirection**

```json
[
{
"path": "/test",
"targets": {
"mobile": "https://m.example.com/test",
"desktop": "https://www.example.com/test",
"default": "https://www.example.com/test"
}
}
]
```

In this case, when a request comes to the `/test` path, users with a user-agent string indicating a mobile device will be redirected to `https://m.example.com/test`, while users on desktop devices will be directed to `https://www.example.com/test`. If the user-agent is not recognized or does not fall into these categories, the user will be directed to the default URL `https://www.example.com/test`.

2. **OS Specific Redirection**

```json
[
{
"path": "/app",
"targets": {
"android": "https://play.google.com/store/apps/details?id=com.example",
"ios": "https://apps.apple.com/app/example/id123456",
"default": "https://www.example.com/app"
}
}
]
```

In this case, when a request comes to the `/app` path, users on Android devices will be redirected to the app's page on Google Play, while iOS users will be directed to the app's page on the Apple App Store. Other users will be redirected to a general application page.

3. **Deep Link Redirection with Fallback**

```json
[
{
"path": "/deeplink",
"targets": {
"android": {
"deepLink": "example://details/123",
"fallback": "https://play.google.com/store/apps/details?id=com.example"
},
"ios": {
"deepLink": "example://details/123",
"fallback": "https://apps.apple.com/app/example/id123456"
},
"default": "https://www.example.com/details/123"
}
}
]
```

Here, when a request comes to the `/deeplink` path, Android and iOS users will be redirected to a deep link which opens a specific part of an app if they have it installed. If the app is not installed (the deep link fails), the fallback URL will open, leading them to the app's page on their respective app store. Other users will be redirected to a webpage with similar information.
42 changes: 42 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"path": "/dev",
"targets": {
"android": "https://developer.android.com/",
"ios": "https://developer.apple.com/",
"default": "https://developer.mozilla.org/"
}
},
{
"path": "/mobile",
"targets": {
"mobile": "https://cloud.appwrite.io",
"default": "https://appwrite.io"
}
},
{
"path": "/appstore",
"targets": {
"android": "https://play.google.com/store/apps/details?id=com.instagram.barcelona",
"ios": "https://apps.apple.com/us/app/threads-an-instagram-app/id6446901002",
"default": "https://www.threads.net/"
}
},
{
"path": "/deeplink",
"targets": {
"android": {
"appName": "twitter",
"appPackage": "com.twitter.android",
"appPath": "user?screen_name=appwrite",
"fallback": "https://play.google.com/store/apps/details?id=com.twitter.android"
},
"ios": {
"appName": "twitter",
"appPath": "user?screen_name=appwrite",
"fallback": "https://apps.apple.com/us/app/twitter/id333903271"
},
"default": "https://twitter.com/appwrite"
}
}
]
10 changes: 10 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
CONFIG?: string;
GOOGLE_ANALYTICS_API_KEY?: string;
}
}
}

export {};
Loading