Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import express from 'express'
import adminRouter from './admin'
import mappingRouter from './mapping'
import sshKeyRouter from './sshKeys'
import statusRouter from './serverStatus'
import { getAvailableDomains } from '../lib/data'

const apiRouter = express.Router()

apiRouter.use('/admin', adminRouter.app)
apiRouter.use('/mappings', mappingRouter)
apiRouter.use('/sshKeys', sshKeyRouter)
apiRouter.use('/statuses', statusRouter)

apiRouter.get('/availableDomains', (req, res) => {
const domains = getAvailableDomains()
Expand Down
25 changes: 23 additions & 2 deletions src/api/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,30 @@ mappingRouter.post('/', async (req, res) => {
})
})

mappingRouter.get('/', (req, res) => {
mappingRouter.get('/', async (req, res) => {
const domains = getMappings()
res.json(domains)
if (isProduction()) {
const data = await exec('su - myproxy -c "pm2 jlist"')

const statusData = JSON.parse(data.stdout).reduce(
(statusObj, el) => ({
...statusObj,
[el.name]: el.pm2_env.status
}),
{}
)
const fullDomainStatusMapping = domains.map(el => {
if (statusData[el.fullDomain]) {
return { ...el, status: statusData[el.fullDomain] }
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this else cuz you are returning.

return { ...el, status: 'not started' }
}
})

res.json(fullDomainStatusMapping)
} else {
res.json(domains.map(el => ({ ...el, status: 'not started' })))
}
})

mappingRouter.delete('/:id', async (req, res) => {
Expand Down
33 changes: 0 additions & 33 deletions src/api/serverStatus.ts

This file was deleted.

26 changes: 13 additions & 13 deletions src/public/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ class MappingItem {
}
}

Promise.all([
fetch('/api/mappings').then(r => r.json()),
fetch('/api/statuses').then(r => r.json())
]).then(([mappings, statuses]: [Mapping[], Status[]]) => {
domainList.innerHTML = ''
mappings
.reverse()
.filter(e => e.domain && e.port && e.id && e.gitLink && e.fullDomain)
.forEach(e => {
e.status = statuses[e.fullDomain] || 'not started'
new MappingItem(e)
})
})
fetch('/api/mappings')
.then(r => r.json())
.then(mappings => {
domainList.innerHTML = ''
mappings
.reverse()
.filter(
e => e.domain && e.port && e.id && e.gitLink && e.fullDomain && e.status
)
.forEach(e => {
new MappingItem(e)
})
})

create.onclick = (): void => {
const subDomain = helper.getElement('.subDomain') as HTMLInputElement
Expand Down
17 changes: 17 additions & 0 deletions src/tests/integration/mapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,21 @@ describe('/api', () => {
await mappingAdapter(`/${match1.id}`, 'DELETE')
await mappingAdapter(`/${match2.id}`, 'DELETE')
})

it('checks status is returned when querying mappings', async () => {
const subDomain = uuidv4()
const domain = 'VinDiesel'
const port = '3533'
await mappingAdapter('/', 'POST', {
domain,
subDomain,
port
})

const getResponse = await mappingAdapter('/', 'GET')
const getMappings = await getResponse.json()

expect(getMappings[0].status).toEqual('not started')
await mappingAdapter(`/${getMappings[0].id}`, 'DELETE')
})
})
32 changes: 0 additions & 32 deletions src/tests/integration/status.test.ts

This file was deleted.