From b836780e335551b426868c5d030e6946dca998e1 Mon Sep 17 00:00:00 2001 From: dragongoose Date: Mon, 24 Apr 2023 11:14:57 -0400 Subject: [PATCH] Change version to last commit and have a root endpoint --- index.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 77e00a5..f0f541e 100644 --- a/index.ts +++ b/index.ts @@ -1,14 +1,18 @@ -import express, { Express } from 'express'; +import express, { Express, Request, Response } from 'express'; import dotenv from 'dotenv' import routes from './routes' import { errorHandler } from './util/errorHandler' import { wsServer } from './routes/proxyRoute'; import compression from 'compression' -import { version } from './package.json'; import { cors } from './util/cors'; +import { execSync } from 'child_process'; dotenv.config() +// define version as current commit +const version = execSync('git rev-parse HEAD') +.toString().trim() + const app: Express = express(); const port = process.env.PORT @@ -16,6 +20,15 @@ app.use(cors()) app.use(compression({})) 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 app.use((req, res) => { if (!res.headersSent) { @@ -27,7 +40,7 @@ app.use((req, res) => { app.use(errorHandler) 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) => {