feat: add api server class

This commit is contained in:
2024-12-24 13:25:36 +09:00
parent cc655ac864
commit a06e72d24a
124 changed files with 460 additions and 413 deletions

View File

@ -1,17 +1,45 @@
import express from 'express'
import express, { Request, Response } from 'express'
import { APIServer } from './APIServer'
export class WebServer {
export class WebServer {
private readonly app = express()
public WebServer () {
private readonly apiServer = new APIServer()
constructor (
private readonly port = 2424
) {
this.initRoutes()
this.app.listen(this.port, this.showBanner.bind(this))
}
private initRoutes () {
this.app.use(express.static('./public'))
this.app.use('/api', this.apiServer.getRouter())
this.app.use(this.error404)
}
public listen() {
this.app.listen()
private error404 (_: Request, res: Response) {
res.status(404).send({ success: false, message: 'Page not found' })
}
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')
)
}
}