Skip to content

Commit 11d3528

Browse files
committed
VIDSOL-134 add route to handle assetlinks request
1 parent 80c118e commit 11d3528

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

backend/.well-known/assetlinks.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

backend/routes/assetlinks.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Request, Response, Router } from 'express';
2+
3+
const assetLinksRouter = Router();
4+
5+
/**
6+
* tl:dr: Serve the static file needed for mobile deep linking
7+
* more info: https://developer.android.com/training/app-links/verify-android-applinks#publish-json
8+
*/
9+
assetLinksRouter.get('/assetlinks.json', (_req: Request, res: Response) => {
10+
res.json([
11+
{
12+
// Grants the target permission to handle all URLs that the source can handle
13+
relation: ['delegate_permission/common.handle_all_urls'],
14+
target: {
15+
namespace: 'android_app',
16+
// Package name for the Android app
17+
package_name: 'com.vonage.android',
18+
// SHA-256 certificate fingerprints for the Android app
19+
sha256_cert_fingerprints: [
20+
'A4:26:72:80:DA:75:99:75:ED:D2:32:ED:0A:DC:2C:7C:27:78:6A:8C:9A:37:22:41:23:CF:9E:DB:03:78:FC:6C',
21+
],
22+
},
23+
},
24+
]);
25+
});
26+
27+
export default assetLinksRouter;

backend/routes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { Router } from 'express';
22
import healthRoute from './health';
33
import sessionRouter from './session';
44
import feedbackRouter from './feedback';
5+
import assetLinksRouter from './assetlinks';
56

67
const router = Router();
78

89
router.use('/_', healthRoute);
910
router.use('/session', sessionRouter);
1011
router.use('/feedback', feedbackRouter);
12+
router.use('/.well-known', assetLinksRouter);
1113

1214
export default router;

backend/server.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ app.use((_req, res, next) => {
2727

2828
app.use(express.static(path.join(dirName, './dist')));
2929

30-
/**
31-
* tl:dr: Serve the static file needed for mobile deep linking
32-
* more info: https://developer.android.com/training/app-links/verify-android-applinks#publish-json
33-
*/
34-
app.get('/.well-known/assetlinks.json', (_req: Request, res: Response) => {
35-
res.sendFile(path.join(dirName, '.well-known', 'assetlinks.json'));
36-
});
37-
3830
app.get('/*', (_req: Request, res: Response) => {
3931
res.sendFile(path.join(dirName, 'dist', 'index.html'));
4032
});

backend/tests/assetlinks.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,30 @@ describe('GET /.well-known/assetlinks.json', () => {
2323

2424
it('returns the correct Content-Type header', async () => {
2525
const res = await request(server).get('/.well-known/assetlinks.json');
26-
expect(res.headers['content-type']).toEqual('application/json; charset=UTF-8');
26+
expect(res.headers['content-type']).toEqual('application/json; charset=utf-8');
2727
});
2828

2929
it('returns valid JSON content', async () => {
3030
const res = await request(server).get('/.well-known/assetlinks.json');
3131
expect(() => JSON.parse(res.text)).not.toThrow();
3232
});
3333

34-
it('returns the same content as the static assetlinks.json file', async () => {
34+
it('returns the correct structure for asset links', async () => {
3535
const res = await request(server).get('/.well-known/assetlinks.json');
36-
const expectedContent = (await import('../.well-known/assetlinks.json')).default;
37-
expect(JSON.parse(res.text)).toEqual(expectedContent);
36+
const json = JSON.parse(res.text);
37+
expect(json).toEqual(
38+
expect.arrayContaining([
39+
expect.objectContaining({
40+
relation: expect.arrayContaining(['delegate_permission/common.handle_all_urls']),
41+
target: expect.objectContaining({
42+
namespace: 'android_app',
43+
package_name: 'com.vonage.android',
44+
sha256_cert_fingerprints: expect.arrayContaining([
45+
'A4:26:72:80:DA:75:99:75:ED:D2:32:ED:0A:DC:2C:7C:27:78:6A:8C:9A:37:22:41:23:CF:9E:DB:03:78:FC:6C',
46+
]),
47+
}),
48+
}),
49+
])
50+
);
3851
});
3952
});

0 commit comments

Comments
 (0)