mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
Move Stream routes to seperate API file
This commit is contained in:
+2
-13
@@ -20,6 +20,7 @@ import api from './homebrew.api.js';
|
||||
const { homebrewApi, getBrew, getCSS } = api;
|
||||
import adminApi from './admin.api.js';
|
||||
import vaultApi from './vault.api.js';
|
||||
import streamApi from './stream.api.js';
|
||||
import pageRoutes from './page-routes.js';
|
||||
|
||||
import serveCompressedStaticAssets from './static-assets.mv.js';
|
||||
@@ -32,7 +33,6 @@ import bodyParser from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import forceSSL from './forcessl.mw.js';
|
||||
|
||||
import Stream from './eventStreamSource.js';
|
||||
import dbCheck from './middleware/dbCheck.js';
|
||||
|
||||
import cors from 'cors';
|
||||
@@ -115,6 +115,7 @@ export default async function createApp(vite) {
|
||||
app.use(homebrewApi);
|
||||
app.use(adminApi(vite));
|
||||
app.use(vaultApi);
|
||||
app.use(streamApi);
|
||||
|
||||
String.prototype.replaceAll = function(s, r){return this.split(s).join(r);};
|
||||
|
||||
@@ -194,18 +195,6 @@ export default async function createApp(vite) {
|
||||
}
|
||||
});
|
||||
|
||||
// Create Event Stream source for pages to listen to
|
||||
app.get('/stream/:id', (req, res)=>{
|
||||
res.writeHead(200, {
|
||||
'Content-Type' : 'text/event-stream',
|
||||
'Cache-Control' : 'no-cache',
|
||||
'Connection' : 'keep-alive',
|
||||
'Content-Encoding' : 'none'
|
||||
});
|
||||
;
|
||||
Stream.subscribe(req.params.id, res);
|
||||
});
|
||||
|
||||
|
||||
// Local only
|
||||
if(isLocalEnvironment){
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import express from 'express';
|
||||
|
||||
import Stream from './eventStreamSource.js';
|
||||
|
||||
const app = express.Router();
|
||||
|
||||
// Create Event Stream source for pages to listen to
|
||||
app.get('/api/stream/:id', (req, res)=>{
|
||||
res.writeHead(200, {
|
||||
'Content-Type' : 'text/event-stream',
|
||||
'Cache-Control' : 'no-cache',
|
||||
'Connection' : 'keep-alive',
|
||||
'Content-Encoding' : 'none'
|
||||
});
|
||||
;
|
||||
Stream.subscribe(req.params.id, res);
|
||||
});
|
||||
|
||||
app.get('/api/stream/unsubscribe/:id', (req, res)=>{
|
||||
Stream.unsubscribe(req.params?.id);
|
||||
res.status(200).send();
|
||||
});
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user