0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-03 03:10:05 -05:00

Change version to last commit and have a root endpoint

This commit is contained in:
dragongoose 2023-04-24 11:14:57 -04:00
parent 03474a422e
commit b836780e33
No known key found for this signature in database
GPG key ID: 50DB99B921579009

View file

@ -1,14 +1,18 @@
import express, { Express } from 'express'; import express, { Express, Request, Response } from 'express';
import dotenv from 'dotenv' import dotenv from 'dotenv'
import routes from './routes' import routes from './routes'
import { errorHandler } from './util/errorHandler' import { errorHandler } from './util/errorHandler'
import { wsServer } from './routes/proxyRoute'; import { wsServer } from './routes/proxyRoute';
import compression from 'compression' import compression from 'compression'
import { version } from './package.json';
import { cors } from './util/cors'; import { cors } from './util/cors';
import { execSync } from 'child_process';
dotenv.config() dotenv.config()
// define version as current commit
const version = execSync('git rev-parse HEAD')
.toString().trim()
const app: Express = express(); const app: Express = express();
const port = process.env.PORT const port = process.env.PORT
@ -16,6 +20,15 @@ app.use(cors())
app.use(compression({})) app.use(compression({}))
app.use(routes) app.use(routes)
// main endpoint
app.get('/', (req: Request, res: Response) => {
res.send({
status: 'ok',
message: `SafeTwitch Backend on commit ${version}. If you meant to use SafeTwitch, you're at the wrong URL`
})
})
// 404 handler // 404 handler
app.use((req, res) => { app.use((req, res) => {
if (!res.headersSent) { if (!res.headersSent) {
@ -27,7 +40,7 @@ app.use((req, res) => {
app.use(errorHandler) app.use(errorHandler)
const server = app.listen(port, () => { const server = app.listen(port, () => {
console.log(`SafeTwitch v${version} started on port ${port}`) console.log(`SafeTwitch commit ${version} started on port ${port}`)
}) })
server.on('upgrade', (request, socket, head) => { server.on('upgrade', (request, socket, head) => {