0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 05:02:58 -05:00

Log errors and use compression

This commit is contained in:
dragongoose 2023-03-29 10:03:16 -04:00
parent a3602715d4
commit 41e925a5c3
5 changed files with 1114 additions and 1843 deletions

View file

@ -1,8 +1,9 @@
import express, { Express } from 'express';
import dotenv from 'dotenv'
import routes from './routes'
import { errorHandler, uuid } from './util/logger'
import { errorHandler, logger, uuid } from './util/logger'
import { wsServer } from './routes/proxyRoute';
import compression from 'compression'
dotenv.config()
@ -10,6 +11,7 @@ const app: Express = express();
const port = process.env.PORT
app.use(uuid)
app.use(compression({}))
app.use(routes)
// 404 handler
@ -31,3 +33,7 @@ server.on('upgrade', (request, socket, head) => {
wsServer.emit('connection', socket, request);
});
});
process.on('unhandledRejection', (reason: Error, p) => {
logger.error(reason)
});

2933
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,6 @@
{
"dependencies": {
"compression": "^1.7.4",
"connect-history-api-fallback": "^2.0.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
@ -9,6 +10,7 @@
"ws": "^8.13.0"
},
"devDependencies": {
"@types/compression": "^1.7.2",
"@types/connect-history-api-fallback": "^1.3.5",
"@types/express": "^4.17.17",
"@types/node": "^18.14.6",

View file

@ -15,7 +15,15 @@ profileRouter.get('/users/:username', async (req, res, next) => {
})
profileRouter.get('/discover', async (req, res, next) => {
let discoveryData = await twitch.getDirectory(50)
let cursor = req.query.cursor
let discoveryData;
if (cursor) {
cursor = cursor.toString()
discoveryData = await twitch.getDirectory(15, cursor)
} else {
discoveryData = await twitch.getDirectory(15)
}
res.send(discoveryData)
})

View file

@ -268,7 +268,7 @@ export class TwitchAPI {
* @param cursor The current page you're at (for pagination)
*/
public getDirectory = async (limit: number, cursor?: number) => {
public getDirectory = async (limit: number, cursor?: string) => {
const payload: any[] = [
{
"operationName": "BrowsePage_AllDirectories",
@ -316,7 +316,7 @@ export class TwitchAPI {
viewers: category.node.viewersCount,
tags: tags,
createdAt: category.node.originalReleaseDate,
cursor: category.node.cursor,
cursor: category.cursor,
image: `${process.env.URL}/proxy/img/${base64(category.node.avatarURL)}`
})
}