Use typed express's app

This commit is contained in:
Daniel Lugo 2022-01-17 14:30:51 -04:00
parent 7ab0af1bad
commit 4fa886d8c6

View file

@ -43,7 +43,7 @@ const SESSION_ID = uuid()
// module.exports = (app) => { // module.exports = (app) => {
module.exports = async ( module.exports = async (
app, _app,
config, config,
mySocketsEvents, mySocketsEvents,
{ serverPort, CA, CA_KEY, useTLS } { serverPort, CA, CA_KEY, useTLS }
@ -52,7 +52,7 @@ module.exports = async (
* @typedef {import('express').Application} Application * @typedef {import('express').Application} Application
*/ */
const ap = /** @type {Application} */ (app) const app = /** @type {Application} */ (_app)
try { try {
const Http = Axios.create({ const Http = Axios.create({
@ -2120,7 +2120,7 @@ module.exports = async (
} }
} }
ap.get('/api/gun/initwall', async (req, res) => { app.get('/api/gun/initwall', async (req, res) => {
try { try {
await GunActions.initWall() await GunActions.initWall()
res.json({ ok: true }) res.json({ ok: true })
@ -2131,8 +2131,8 @@ module.exports = async (
}) })
} }
}) })
ap.put(`/api/gun/follows/:publicKey`, apiGunFollowsPut) app.put(`/api/gun/follows/:publicKey`, apiGunFollowsPut)
ap.delete(`/api/gun/follows/:publicKey`, apiGunFollowsDelete) app.delete(`/api/gun/follows/:publicKey`, apiGunFollowsDelete)
/** /**
* @type {RequestHandler<{}>} * @type {RequestHandler<{}>}
@ -2187,9 +2187,9 @@ module.exports = async (
} }
} }
ap.put(`/api/gun/me`, apiGunMePut) app.put(`/api/gun/me`, apiGunMePut)
ap.get(`/api/gun/auth`, (_, res) => { app.get(`/api/gun/auth`, (_, res) => {
const { isAuthenticated } = require('../services/gunDB/Mediator') const { isAuthenticated } = require('../services/gunDB/Mediator')
return res.status(200).json({ return res.status(200).json({
@ -2260,7 +2260,7 @@ module.exports = async (
*/ */
const EPUB_FOR_DECRYPT_HEADER = 'epub-for-decryption' const EPUB_FOR_DECRYPT_HEADER = 'epub-for-decryption'
ap.get('/api/gun/once/:path', async (req, res) => { app.get('/api/gun/once/:path', async (req, res) => {
try { try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2284,7 +2284,7 @@ module.exports = async (
} }
}) })
ap.get('/api/gun/specialOnce/:path', async (req, res) => { app.get('/api/gun/specialOnce/:path', async (req, res) => {
try { try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2308,7 +2308,7 @@ module.exports = async (
} }
}) })
ap.get('/api/gun/load/:path', async (req, res) => { app.get('/api/gun/load/:path', async (req, res) => {
try { try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2332,7 +2332,7 @@ module.exports = async (
} }
}) })
ap.get('/api/gun/user/once/:path', async (req, res) => { app.get('/api/gun/user/once/:path', async (req, res) => {
try { try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2356,7 +2356,7 @@ module.exports = async (
} }
}) })
ap.get('/api/gun/user/specialOnce/:path', async (req, res) => { app.get('/api/gun/user/specialOnce/:path', async (req, res) => {
try { try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2380,7 +2380,7 @@ module.exports = async (
} }
}) })
ap.get('/api/gun/user/load/:path', async (req, res) => { app.get('/api/gun/user/load/:path', async (req, res) => {
try { try {
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
@ -2404,7 +2404,7 @@ module.exports = async (
} }
}) })
ap.get('/api/gun/otheruser/:publicKey/:type/:path', async (req, res) => { app.get('/api/gun/otheruser/:publicKey/:type/:path', async (req, res) => {
try { try {
const allowedTypes = ['once', 'open', 'specialOnce'] const allowedTypes = ['once', 'open', 'specialOnce']
const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER) const publicKeyForDecryption = req.header(PUBKEY_FOR_DECRYPT_HEADER)
@ -2455,7 +2455,7 @@ module.exports = async (
} }
}) })
ap.post('/api/lnd/cb/:methodName', (req, res) => { app.post('/api/lnd/cb/:methodName', (req, res) => {
try { try {
const { lightning } = LightningServices.services const { lightning } = LightningServices.services
const { methodName } = req.params const { methodName } = req.params
@ -2486,7 +2486,7 @@ module.exports = async (
} }
}) })
ap.post('/api/gun/put', async (req, res) => { app.post('/api/gun/put', async (req, res) => {
try { try {
const { path, value } = req.body const { path, value } = req.body
logger.info(`gun PUT: ${path}`) logger.info(`gun PUT: ${path}`)
@ -2507,7 +2507,7 @@ module.exports = async (
} }
}) })
ap.post('/api/gun/set', async (req, res) => { app.post('/api/gun/set', async (req, res) => {
try { try {
const { path, value } = req.body const { path, value } = req.body
logger.info(`gun SET: ${path}`) logger.info(`gun SET: ${path}`)
@ -2529,7 +2529,7 @@ module.exports = async (
} }
}) })
ap.get('/api/log', async (_, res) => { app.get('/api/log', async (_, res) => {
try { try {
// https://github.com/winstonjs/winston#querying-logs // https://github.com/winstonjs/winston#querying-logs
/** /**
@ -2563,7 +2563,7 @@ module.exports = async (
} }
}) })
//this is for OBS notifications, not wired with UI. //this is for OBS notifications, not wired with UI.
ap.get('/api/subscribeStream', (req, res) => { app.get('/api/subscribeStream', (req, res) => {
try { try {
res.sendFile(path.join(__dirname, '../public/obsOverlay.html')) res.sendFile(path.join(__dirname, '../public/obsOverlay.html'))
} catch (e) { } catch (e) {
@ -2573,7 +2573,7 @@ module.exports = async (
}) })
} }
}) })
ap.post('/api/enableNotificationsOverlay', (req, res) => { app.post('/api/enableNotificationsOverlay', (req, res) => {
try { try {
const { postID } = req.body const { postID } = req.body
if (!postID) { if (!postID) {
@ -2593,7 +2593,7 @@ module.exports = async (
} }
}) })
//this is for wasLive/isLive status //this is for wasLive/isLive status
ap.post('/api/listenStream', (req, res) => { app.post('/api/listenStream', (req, res) => {
try { try {
startedStream(req.body) startedStream(req.body)
return res.status(200).json({ return res.status(200).json({
@ -2607,7 +2607,7 @@ module.exports = async (
}) })
} }
}) })
ap.post('/api/stopStream', (req, res) => { app.post('/api/stopStream', (req, res) => {
try { try {
endStream(req.body) endStream(req.body)
return res.status(200).json({ return res.status(200).json({
@ -2622,7 +2622,7 @@ module.exports = async (
} }
}) })
ap.get('/', (req, res) => { app.get('/', (req, res) => {
try { try {
res.sendFile(path.join(__dirname, '../public/localHomepage.html')) res.sendFile(path.join(__dirname, '../public/localHomepage.html'))
} catch (e) { } catch (e) {
@ -2633,7 +2633,7 @@ module.exports = async (
} }
}) })
ap.get('/qrCodeGenerator', (req, res) => { app.get('/qrCodeGenerator', (req, res) => {
console.log('/qrCodeGenerator') console.log('/qrCodeGenerator')
try { try {
res.sendFile(path.join(__dirname, '../public/qrcode.min.js')) res.sendFile(path.join(__dirname, '../public/qrcode.min.js'))
@ -2645,7 +2645,7 @@ module.exports = async (
} }
}) })
ap.get('/api/accessInfo', async (req, res) => { app.get('/api/accessInfo', async (req, res) => {
if (req.ip !== '127.0.0.1') { if (req.ip !== '127.0.0.1') {
res.json({ res.json({
field: 'origin', field: 'origin',
@ -2698,7 +2698,7 @@ module.exports = async (
} }
}) })
ap.post('/api/initUserInformation', async (req, res) => { app.post('/api/initUserInformation', async (req, res) => {
try { try {
const user = require('../services/gunDB/Mediator').getUser() const user = require('../services/gunDB/Mediator').getUser()
await UserInitializer.InitUserData(user) await UserInitializer.InitUserData(user)