Initial commit, frontend with PreactJS and hash routing, backend with PolkaJS
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import polka from 'polka'
|
||||
import send from '@polka/send-type'
|
||||
|
||||
import chalk from 'chalk'
|
||||
import { toLocalISO } from '../utils/util.js'
|
||||
|
||||
export const StatusRouter = polka()
|
||||
|
||||
StatusRouter.get('/status', (req, res) => {
|
||||
send(res, 200, { status: 'ok' })
|
||||
})
|
||||
|
||||
export const PingRouter = polka()
|
||||
|
||||
PingRouter.post('/ping', (req, res) => {
|
||||
if (req.body?.message === 'ping') {
|
||||
send(res, 200, 'pong')
|
||||
} else {
|
||||
send(res, 400, 'Invalid request')
|
||||
}
|
||||
})
|
||||
|
||||
export const LoggingMiddleware = (req, res, next) => {
|
||||
next()
|
||||
|
||||
const coloredStatusCode = [
|
||||
chalk.gray,
|
||||
chalk.green,
|
||||
chalk.blueBright,
|
||||
chalk.red,
|
||||
chalk.redBright,
|
||||
][Math.floor(res.statusCode / 100) - 1](res.statusCode)
|
||||
|
||||
console.log(`${toLocalISO(new Date())} | ${req.method} ${req.originalUrl} ${coloredStatusCode}`)
|
||||
}
|
||||
Reference in New Issue
Block a user