Skip to content

Commit

Permalink
intro example: add query param to enable debug mode. (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
thruflo authored Sep 4, 2023
1 parent f52f25f commit 869084c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion examples/introduction/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ export const ELECTRIC_URL: string = __ELECTRIC_URL__
// Verify that the database URL does not contain credentials.
if (SANITISED_DATABASE_URL.includes('@')) {
throw new Error('DO NOT include user credentials in your `SANITISED_DATABASE_URL`!')
}
}

/* Call this in the browser to get the debug mode, optionally overriding
* the env var with a `debug=true` query param.
*/
export const debugMode = (): boolean => {
const search = window.location.search
const params = new URLSearchParams(search)

if (params.get('debug') === 'true') {
return true
}

return DEBUG_MODE
}
4 changes: 2 additions & 2 deletions examples/introduction/src/electric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ClientTables } from 'electric-sql/client/model'
import { uniqueTabId } from 'electric-sql/util'
import { Electric, schema } from './generated/client/index'
import { unsigned, userId } from './auth'
import { DEBUG_MODE, ELECTRIC_URL } from './config'
import { ELECTRIC_URL, debugMode } from './config'

export type {
Electric,
Expand All @@ -31,7 +31,7 @@ export const initElectric = async (name: string = 'intro') => {
token: unsigned(userId())
},
url: ELECTRIC_URL,
debug: DEBUG_MODE
debug: debugMode()
}

const electric = await electrify(conn, schema, config)
Expand Down

0 comments on commit 869084c

Please sign in to comment.