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:
parent
03474a422e
commit
b836780e33
1 changed files with 16 additions and 3 deletions
19
index.ts
19
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) => {
|
||||
|
|
Loading…
Reference in a new issue