Skip to content

Commit 4b1e965

Browse files
committed
fix(example): use dotenv for replications
1 parent 744e243 commit 4b1e965

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ android/keystores/debug.keystore
7878
lib/
7979

8080
.env*.local
81+
.env

example/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = getConfig(
2121
},
2222
},
2323
],
24+
['module:react-native-dotenv'],
2425
],
2526
},
2627
{ root, pkg }

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@react-native/eslint-config": "0.79.2",
3333
"@react-native/metro-config": "0.79.2",
3434
"@react-native/typescript-config": "0.79.2",
35-
"react-native-builder-bob": "^0.35.2"
35+
"react-native-builder-bob": "^0.35.2",
36+
"react-native-dotenv": "^3.4.11"
3637
},
3738
"op-sqlite": {
3839
"fts5": true

example/src/App.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const pouch = new PouchDB('mydb', {
2121
adapter: 'react-native-sqlite',
2222
revs_limit: 100,
2323
})
24+
// @ts-ignore
25+
globalThis.pouch = pouch
2426

2527
// async function run() {
2628
// const db = open({ name: 'test' })
@@ -127,14 +129,22 @@ export default function App() {
127129
}
128130
}
129131
const handleReplicate = async () => {
130-
setResult('Replicating from remote...')
132+
const remoteUrl = process.env.COUCHDB_URL
133+
setResult(`Replicating from remote...${remoteUrl}`)
134+
if (!remoteUrl) {
135+
setResult(
136+
'CouchDB URL is not set. Please set COUCHDB_URL environment variable in `.env.local`.'
137+
)
138+
return
139+
}
131140
try {
132141
const result = await pouch.replicate
133-
.from(process.env.EXPO_PUBLIC_COUCHDB_URL, { live: false })
142+
.from(remoteUrl, { live: false })
134143
.on('error', (err: any) => console.log('error:', err))
135144
console.log('ret:', result)
136145
setResult(JSON.stringify(result, null, 2))
137146
} catch (e: any) {
147+
console.error(e)
138148
setResult(e.name + ': ' + e.message)
139149
}
140150
}

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5880,6 +5880,13 @@ __metadata:
58805880
languageName: node
58815881
linkType: hard
58825882

5883+
"dotenv@npm:^16.4.5":
5884+
version: 16.5.0
5885+
resolution: "dotenv@npm:16.5.0"
5886+
checksum: 6543fe87b5ddf2d60dd42df6616eec99148a5fc150cb4530fef5bda655db5204a3afa0e6f25f7cd64b20657ace4d79c0ef974bec32fdb462cad18754191e7a90
5887+
languageName: node
5888+
linkType: hard
5889+
58835890
"dunder-proto@npm:^1.0.0, dunder-proto@npm:^1.0.1":
58845891
version: 1.0.1
58855892
resolution: "dunder-proto@npm:1.0.1"
@@ -11362,6 +11369,7 @@ __metadata:
1136211369
react: 19.0.0
1136311370
react-native: 0.79.2
1136411371
react-native-builder-bob: ^0.35.2
11372+
react-native-dotenv: ^3.4.11
1136511373
react-native-quick-crypto: ^0.7.8
1136611374
languageName: unknown
1136711375
linkType: soft
@@ -11917,6 +11925,17 @@ __metadata:
1191711925
languageName: node
1191811926
linkType: hard
1191911927

11928+
"react-native-dotenv@npm:^3.4.11":
11929+
version: 3.4.11
11930+
resolution: "react-native-dotenv@npm:3.4.11"
11931+
dependencies:
11932+
dotenv: ^16.4.5
11933+
peerDependencies:
11934+
"@babel/runtime": ^7.20.6
11935+
checksum: 3ebac2c2ed79dd7e4920fd3fc2da9187413b7190231618e4858b46c47833677838b96d531afe7bd5c4b0a60454dba40cb8708722210df5d522e30aefbf41da05
11936+
languageName: node
11937+
linkType: hard
11938+
1192011939
"react-native-quick-base64@npm:^2.0.5":
1192111940
version: 2.1.2
1192211941
resolution: "react-native-quick-base64@npm:2.1.2"

0 commit comments

Comments
 (0)