2024-12-24 13:25:36 +09:00
|
|
|
import express, { Request, Response } from 'express'
|
|
|
|
import { APIServer } from './APIServer'
|
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 13:25:36 +09:00
|
|
|
private readonly apiServer = new APIServer()
|
2024-12-23 21:52:08 +09:00
|
|
|
|
2024-12-24 13:25:36 +09:00
|
|
|
constructor (
|
|
|
|
private readonly port = 2424
|
|
|
|
) {
|
|
|
|
this.initRoutes()
|
|
|
|
this.app.listen(this.port, this.showBanner.bind(this))
|
2024-12-23 21:52:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
private initRoutes () {
|
2024-12-24 13:25:36 +09:00
|
|
|
this.app.use(express.static('./public'))
|
|
|
|
this.app.use('/api', this.apiServer.getRouter())
|
|
|
|
this.app.use(this.error404)
|
|
|
|
}
|
2024-12-23 21:52:08 +09:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|