Skip to content

Commit

Permalink
feat: add http pull feature
Browse files Browse the repository at this point in the history
  • Loading branch information
seo-rii committed Jan 6, 2022
1 parent 284c42e commit 17abb15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express'
import expressWs from 'express-ws'
import { v4 as uuid } from 'uuid'
import { init } from './socket'
import { getMessageList, init } from './socket'
import { requestJudge } from './judge'
import { JudgeRequest } from './types/request'
import { is } from 'typescript-is'
Expand All @@ -10,6 +10,12 @@ import bodyParser from 'body-parser'
import favicon from 'serve-favicon'
import path from 'path'

process.on('uncaughtException', (e) => {
console.log('uncaughtException:', e)
})

const PORT = 80

const app = expressWs(express()).app
init(app)
app.use(bodyParser.json())
Expand Down Expand Up @@ -39,38 +45,41 @@ app.post('/judge', (req, res) => {
}
})

app.get('/test', function (req, res) {
app.get('/pull', (req, res) => {
res.set('Cache-Control', 'no-store')
res.send({ success: true, data: getMessageList() })
})

app.get('/test', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'res', 'test.html'))
})

app.get('/res/logo', function (req, res) {
app.get('/res/logo', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'res', 'logo.png'))
})

app.get('/res/github', function (req, res) {
app.get('/res/github', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'res', 'github.png'))
})

app.get('/res/docs', function (req, res) {
app.get('/res/docs', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'res', 'docs.png'))
})

app.get('/res/test', function (req, res) {
app.get('/res/test', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'res', 'test.png'))
})

app.get('/', function (req, res) {
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'res', 'index.html'))
})

app.use(favicon(__dirname + '/../res/logo.ico'))

app.use('*', function (req, res) {
app.use('*', (req, res) => {
res.redirect('http://jungol.co.kr')
})

app.listen(80)

process.on('uncaughtException', (e) => {
console.log('uncaughtException:', e)
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`)
})
6 changes: 6 additions & 0 deletions src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { MultiJudgeCount } from './config'
let wsObject = null as WebSocket | null
let messageList = [] as string[]

export function getMessageList() {
const ret = messageList
messageList = []
return ret
}

export function sendWS(message: string) {
if (wsObject) {
wsObject.send(message, (e) => {
Expand Down

0 comments on commit 17abb15

Please sign in to comment.