order sharing
This commit is contained in:
35
io.js
35
io.js
@@ -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'*/})
|
||||
|
||||
Reference in New Issue
Block a user