mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-22 05:12:57 -05:00
Change routes folder and get ready to implement websockets
This commit is contained in:
parent
3a09ec5112
commit
65d7f3f297
4 changed files with 26 additions and 8 deletions
|
@ -2,7 +2,8 @@ import express, { Express, NextFunction, Request, Response } from 'express';
|
|||
import dotenv from 'dotenv'
|
||||
import history from 'connect-history-api-fallback'
|
||||
import routes from './routes'
|
||||
import { logger, errorHandler, uuid } from './util/logger'
|
||||
import { errorHandler, uuid } from './util/logger'
|
||||
import { wsServer } from './routes/proxyRoute';
|
||||
|
||||
dotenv.config()
|
||||
|
||||
|
@ -25,7 +26,11 @@ app.use((req, res) => {
|
|||
// handle errors
|
||||
app.use(errorHandler)
|
||||
|
||||
|
||||
app.listen(port, () => {
|
||||
const server = app.listen(port, () => {
|
||||
console.log('Server up')
|
||||
})
|
||||
server.on('upgrade', (request, socket, head) => {
|
||||
wsServer.handleUpgrade(request, socket, head, socket => {
|
||||
wsServer.emit('connection', socket, request);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Router } from 'express';
|
||||
import profileRoute from './routes/profile/profileRoute'
|
||||
import proxyRoute from './routes/proxy/proxyRoute'
|
||||
import profileRoute from './routes/profileRoute'
|
||||
import proxyRoute from './routes/proxyRoute'
|
||||
|
||||
const routes = Router();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Router } from 'express'
|
||||
import { TwitchScraper } from '../../util/scraping/extractors'
|
||||
import { TwitchScraper } from '../util/scraping/extractors'
|
||||
|
||||
const profileRouter = Router()
|
||||
const scraper = new TwitchScraper()
|
|
@ -1,8 +1,10 @@
|
|||
import { Streamlink } from '@dragongoose/streamlink';
|
||||
import { Socket } from 'dgram';
|
||||
import { Router, Response, Request, NextFunction } from 'express'
|
||||
import ws from 'ws';
|
||||
|
||||
const proxyRouter = Router();
|
||||
|
||||
|
||||
proxyRouter.get('/img', async (req: Request, res: Response, next: NextFunction) => {
|
||||
const imageUrl = req.query.imageUrl?.toString()
|
||||
if(!imageUrl) return;
|
||||
|
@ -46,7 +48,7 @@ proxyRouter.get('/stream/:username/hls.m3u8', (req: Request, res: Response, next
|
|||
|
||||
for (let url of matches) {
|
||||
const base64data = Buffer.from(url).toString('base64url')
|
||||
//m3u8Data = m3u8Data.replace(url, `${process.env.URL}/proxy/hls/${base64data}`)
|
||||
m3u8Data = m3u8Data.replace(url, `${process.env.URL}/proxy/hls/${base64data}`)
|
||||
}
|
||||
|
||||
res.setHeader('Content-type','application/vnd.apple.mpegurl')
|
||||
|
@ -74,4 +76,15 @@ proxyRouter.get('/hls/:encodedUrl' , (req: Request, res: Response, next: NextFun
|
|||
.catch((err) => next(err))
|
||||
})
|
||||
|
||||
|
||||
|
||||
// IRC PROXY
|
||||
export const wsServer = new ws.Server({ noServer: true });
|
||||
wsServer.on('connection', (socket: Socket) => {
|
||||
socket.send('Welcome! Send a comma seperated list to get the IRC')
|
||||
socket.on('message', message => console.log(message.toString()));
|
||||
});
|
||||
|
||||
|
||||
|
||||
export default proxyRouter
|
Loading…
Reference in a new issue