Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Sep 8, 2024
1 parent b4558d3 commit fc50219
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:usesCleartextTraffic="true"
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">127.0.0.1</domain>
</domain-config>
</network-security-config>
16 changes: 6 additions & 10 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import clsx from 'clsx';
import {useEffect, useState} from 'react';
import {SafeAreaView, ScrollView, Text, View} from 'react-native';
import {BridgeServer} from 'react-native-http-bridge-refurbished';
import 'reflect-metadata';
import {constantsTests} from './tests/constants.spec';
import {registerHooksTests} from './tests/hooks.spec';
import {blobTests, dbSetupTests, queriesTests, runTests} from './tests/index';
import {preparedStatementsTests} from './tests/preparedStatements.spec';
import {reactiveTests} from './tests/reactive.spec';
import {setServerResults, startServer, stopServer} from './server';

export default function App() {
const [results, setResults] = useState<any>([]);
useEffect(() => {
setResults([]);
runTests(
dbSetupTests,
queriesTests,
Expand All @@ -21,18 +20,15 @@ export default function App() {
preparedStatementsTests,
constantsTests,
reactiveTests,
).then(setResults);

const server = new BridgeServer('http_service', true);

server.get('/test_results', async (_req, _res) => {
return {results};
).then(results => {
setServerResults(results as any);
setResults(results);
});

server.listen(10424);
startServer();

return () => {
server.stop();
stopServer();
};
}, []);

Expand Down
36 changes: 36 additions & 0 deletions example/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {BridgeServer} from 'react-native-http-bridge-refurbished';
let results: any[] = [];

const server = new BridgeServer('http_service', true);

server.get('/ping', async (_req, _res) => {
console.log("🟦 🟦🟦🟦🟦🟦🟦 🟦 Received request for '/ping'");
return {message: 'pong'};
});

server.get('/results', async (req, _res) => {

Check failure on line 11 in example/src/server.ts

View workflow job for this annotation

GitHub Actions / lint

'req' is declared but its value is never read.
// console.log("🟦 🟦🟦🟦🟦🟦🟦 🟦 Received request for '/test_results'");
// console.log(req.type);
// console.log(req.data);
// console.log(req.url);
// if (results.length > 0) {
// return {results};
// } else {
// return {};
// }
return {results};
});

server.listen(9000);

export function startServer() {
return server;
}

export function stopServer() {
server.stop();
}

export function setServerResults(r: any[]) {
results = r;
}
5 changes: 2 additions & 3 deletions scripts/poll-in-app-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ async function pollInAppServer() {

while (Date.now() - startTime < maxDuration) {
try {
const response = await makeHttpRequest(
'http://127.0.0.1:10424/test_results'
);
const response = await makeHttpRequest('http://127.0.0.1:9000/results');

if (response !== null) {
let parsed_response = JSON.parse(response);
const allTestsPassed = parsed_response.results.reduce((acc, r) => {
Expand Down
6 changes: 4 additions & 2 deletions scripts/test-android.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
JAVA_OPTS=-XX:MaxHeapSize=6g yarn turbo run run:android:release --cache-dir=.turbo/android
adb reverse tcp:10424 tcp:10424
echo "🟦 Android device address:"
adb forward tcp:9000 tcp:9000
# echo "🟦 Android device address:"
adb shell ip addr show
# echo "📱 Android Emulator IP Address:"
# adb shell ifconfig | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}'
echo "Polling in-app server..."
node ./scripts/poll-in-app-server.js

0 comments on commit fc50219

Please sign in to comment.