order sharing

This commit is contained in:
tim
2025-04-22 16:15:14 -04:00
parent 0b29539e0a
commit ff0d71054b
6 changed files with 1973 additions and 10 deletions

35
io.js
View File

@@ -2,13 +2,38 @@ import {createServer} from "http";
import {Server} from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import {redis} from "./cache.js";
import {fileURLToPath} from "url";
import path from "path";
import express from "express";
import {engine} from "express-handlebars";
import {initSnapShare} from "./snapshare.js";
import cors from "cors";
const options = {
const socketIoOptions = {
}
if( process.env.DEXORDER_CORS )
options['cors'] = {origin:process.env.DEXORDER_CORS}
export const httpServer = createServer()
export const io = new Server(httpServer, options)
if( process.env.DEXORDER_APP_URL )
socketIoOptions['cors'] = {origin:process.env.DEXORDER_APP_URL}
// Setup Express
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.engine('handlebars', engine({
defaultLayout: false,
}
));
app.set('view engine', 'handlebars');
app.set('views', path.join(__dirname, 'views')); // Set the views directory
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors())
initSnapShare(app)
export const httpServer = createServer(app)
export const io = new Server(httpServer, socketIoOptions)
const pubClient = redis.duplicate();
await pubClient.connect()
const adapter = createAdapter(pubClient, redis, {/*key:'socket.io'*/})