-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
33 lines (29 loc) · 1.19 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { HistorySocket } from './src/Sockets/HistorySocket'
import { ClickHistoryManager } from './src/ClickHistoryManager'
import { redirectRequestHandler } from './src/Routes/Redirect'
import { Server } from './src/Server'
import { UrlManager } from './src/UrlManager'
import { logger } from './src/Logger'
import { createRequestHandler } from './src/Routes/Create'
import { deleteRequestHandler } from './src/Routes/Delete'
import { historyRequestHandler } from './src/Routes/History'
import 'dotenv/config'
// Instantiate servers
const server = new Server(logger)
const historySocket = new HistorySocket(server.createWSS('/api/history'))
// Instantiate database managers
const urlManager = new UrlManager(logger)
const clickHistoryManager = new ClickHistoryManager(historySocket)
// Initialize servers
server.api.post('/', createRequestHandler(urlManager, clickHistoryManager))
server.api.put(
'/:shortUrlId',
redirectRequestHandler(urlManager, clickHistoryManager)
)
server.api.delete(
'/:shortUrlId',
deleteRequestHandler(urlManager, clickHistoryManager)
)
server.api.post('/history', historyRequestHandler(clickHistoryManager))
// Start
server.start(parseInt(process.env.PORT ?? String(8080)))