Skip to content

Commit

Permalink
print qr of ip on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Apr 20, 2020
1 parent 5029ad2 commit e186e24
Show file tree
Hide file tree
Showing 8 changed files with 4,426 additions and 2,253 deletions.
24 changes: 22 additions & 2 deletions api/utils/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { loadLightning } from './lightning'
import {sequelize, models} from '../models'
import { exec } from 'child_process'
import * as QRCode from 'qrcode'
import * as publicIp from 'public-ip'

const USER_VERSION = 1

Expand Down Expand Up @@ -80,7 +82,25 @@ const runMigrations = async () => {
});
}

export { setupDatabase, setupOwnerContact, runMigrations }

export { setupDatabase, setupOwnerContact, runMigrations, printQR }

async function printQR(){
const ip = process.env.NODE_IP
let public_ip
if(!ip) {
try {
public_ip = await publicIp.v4()
} catch(e){
console.log(e)
}
} else {
public_ip = ip
}
if(!ip) return

const b64 = Buffer.from(`ip:${public_ip}`).toString('base64')
console.log('Scan this QR in Sphinx app:')
QRCode.toString(b64,{type:'terminal'}, function (err, url) {
console.log(url)
})
}
3 changes: 2 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as crypto from 'crypto'
import {models} from './api/models'
import logger from './api/utils/logger'
import {pingHubInterval, checkInvitesHubInterval} from './api/hub'
import {setupDatabase} from './api/utils/setup'
import {setupDatabase, printQR} from './api/utils/setup'
import * as controllers from './api/controllers'
import * as socket from './api/utils/socket'

Expand Down Expand Up @@ -42,6 +42,7 @@ async function mainSetup(){
checkInvitesHubInterval(5000)
}
await setupApp()
printQR()
}

async function setupApp(){
Expand Down
27 changes: 27 additions & 0 deletions dist/api/utils/setup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/utils/setup.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/app.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e186e24

Please sign in to comment.