2024-12-24 13:25:36 +09:00
|
|
|
import express, { Request, Response } from 'express'
|
2024-12-24 15:25:16 +09:00
|
|
|
import { BPManager } from './BPManager'
|
|
|
|
import { BPSetMetadata } from './types'
|
2024-12-23 21:52:08 +09:00
|
|
|
|
2024-12-24 13:25:36 +09:00
|
|
|
export class WebServer {
|
2024-12-23 21:52:08 +09:00
|
|
|
private readonly app = express()
|
2024-12-24 15:25:16 +09:00
|
|
|
private readonly bpManager =
|
|
|
|
BPManager.getInstance()
|
2024-12-23 21:52:08 +09:00
|
|
|
|
2024-12-24 13:25:36 +09:00
|
|
|
constructor (
|
|
|
|
private readonly port = 2424
|
|
|
|
) {
|
2024-12-24 15:25:16 +09:00
|
|
|
this.app.set('view engine', 'ejs')
|
|
|
|
this.app.set('views', './views');
|
|
|
|
this.app.use(express.static('./public'))
|
|
|
|
|
|
|
|
this.app.get('/', this.getMainPage.bind(this))
|
2024-12-26 13:06:44 +09:00
|
|
|
this.app.get('/check_all', this.runCheck.bind(this))
|
2024-12-24 15:25:16 +09:00
|
|
|
this.app.use(this.error404)
|
|
|
|
|
2024-12-24 13:25:36 +09:00
|
|
|
this.app.listen(this.port, this.showBanner.bind(this))
|
2024-12-23 21:52:08 +09:00
|
|
|
}
|
|
|
|
|
2024-12-24 15:25:16 +09:00
|
|
|
private getMainPage(_: Request, res: Response) {
|
|
|
|
const bpStatus: {
|
|
|
|
category: string,
|
|
|
|
metadatas: BPSetMetadata[]
|
|
|
|
}[] = []
|
|
|
|
|
|
|
|
const bpMetadatas = this.bpManager.getBPSetMetadatas()
|
|
|
|
const categories = new Set(bpMetadatas.map((v) => v?.awsService))
|
|
|
|
|
|
|
|
for (const category of categories)
|
|
|
|
bpStatus.push({
|
|
|
|
category,
|
|
|
|
metadatas: bpMetadatas.filter((v) => v.awsService === category)
|
|
|
|
})
|
|
|
|
|
|
|
|
res.render('index', {
|
|
|
|
bpStatus,
|
|
|
|
bpLength: bpMetadatas.length
|
|
|
|
})
|
2024-12-24 13:25:36 +09:00
|
|
|
}
|
2024-12-23 21:52:08 +09:00
|
|
|
|
2024-12-26 13:06:44 +09:00
|
|
|
|
|
|
|
private runCheck(_: Request, res: Response) {
|
|
|
|
void this.bpManager.runCheck()
|
|
|
|
res.redirect('/')
|
|
|
|
}
|
|
|
|
|
2024-12-24 13:25:36 +09:00
|
|
|
private error404 (_: Request, res: Response) {
|
|
|
|
res.status(404).send({ success: false, message: 'Page not found' })
|
2024-12-23 21:52:08 +09:00
|
|
|
}
|
|
|
|
|
2024-12-24 13:25:36 +09:00
|
|
|
private showBanner () {
|
|
|
|
console.log(`
|
|
|
|
|
|
|
|
_______ _______ _______ _______ _______ _______
|
|
|
|
| _ || || || || || |
|
|
|
|
| |_| || _ || _____|| ___||_ _|| _____|
|
|
|
|
| || |_| || |_____ | |___ | | | |_____
|
|
|
|
| _ | | ___||_____ || ___| | | |_____ |
|
|
|
|
| |_| || | _____| || |___ | | _____| |
|
|
|
|
|_______||___| |_______||_______| |___| |_______|
|
|
|
|
Created By Minhyeok Park
|
|
|
|
|
|
|
|
Server is now on http://127.0.0.1:${this.port}
|
|
|
|
|
|
|
|
`
|
|
|
|
.split('\n')
|
|
|
|
.map((v) => v.replace(/ /, ''))
|
|
|
|
.join('\n')
|
|
|
|
)
|
2024-12-23 21:52:08 +09:00
|
|
|
}
|
|
|
|
}
|