Initial commit, frontend with PreactJS and hash routing, backend with PolkaJS

This commit is contained in:
2022-10-31 02:13:07 +01:00
commit 6c877eccf0
17 changed files with 1687 additions and 0 deletions
+35
View File
@@ -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}`)
}