~ekez/negativefour

ce504e4a753a65e7880f9d224eee33834c3dd398 — Zeke Medley 3 months ago 8830972
Do db update in callback for readFiile
2 files changed, 13 insertions(+), 5 deletions(-)

M serve/app.js
M serve/package.json
M serve/app.js => serve/app.js +11 -4
@@ 22,7 22,7 @@ const axios = require('axios')

require('dotenv').config()

const db = require('helpers/db.js')
const db = require('./helpers/db.js')

const app = express()
const port = 2998;


@@ 102,9 102,16 @@ app.post('/deploy', requireAuth, function(req, res) {
	    console.log(jobStatusMap.get(childProcessID))
	} else {
	    const clearnet = `https://${name}.negativefour.app`
	    const darknet = 'http://' + (await fs.readFile(`/var/lib/tor/${name}.negativefour.app/hostname`)).toString()

	    await db.registerDeploy(user, name, clearnet, darknet)
	    fs.readFile(`/var/lib/tor/${name}.negativefour.app/hostname`, 'utf8', async (err, data) => {
		if (err) {
		    console.log(`error reading darknet url: ${err}`)
		} else {
		    const darknet = `http://${data.toString()}`
		    console.log(`darknet: ${darknet}`)
		    console.log(`clearnet: ${clearnet}`)
		    await db.registerDeploy(user, name, clearnet, darknet)
		}
	    })
	}
    })


M serve/package.json => serve/package.json +2 -1
@@ 11,6 11,7 @@
    "axios": "^0.21.4",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1"
    "jsonwebtoken": "^8.5.1",
    "pg": "^8.7.1"
  }
}