Skip to content
Snippets Groups Projects
Verified Commit 0f0a7652 authored by Park JongBeum's avatar Park JongBeum
Browse files

feat: add admin panel

parent ba71d450
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
"prettier": "^3.0.3" "prettier": "^3.0.3"
}, },
"dependencies": { "dependencies": {
"@socket.io/admin-ui": "^0.5.1",
"bcrypt": "^5.1.1",
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"cors": "^2.8.5", "cors": "^2.8.5",
......
...@@ -12,6 +12,8 @@ import cors from "cors"; ...@@ -12,6 +12,8 @@ import cors from "cors";
import http from "http"; import http from "http";
import socketHandler from "./socket/socketManager.js"; import socketHandler from "./socket/socketManager.js";
import { Server } from "socket.io"; import { Server } from "socket.io";
import { instrument } from "@socket.io/admin-ui";
import bcrypt from "bcrypt";
// import session from "express-session"; // import session from "express-session";
// Initialize Environment Variables // Initialize Environment Variables
...@@ -19,6 +21,31 @@ const __dirname = fileURLToPath(new URL(".", import.meta.url)); ...@@ -19,6 +21,31 @@ const __dirname = fileURLToPath(new URL(".", import.meta.url));
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
dotenv.config(); dotenv.config();
// Express Server
const app = express();
const server = http.createServer(app);
const io = new Server(server, {
cors: {
origin: ["http://localhost:3000", "https://admin.socket.io"],
methods: ["GET", "POST"],
},
});
instrument(io, {
auth: false,
// process.env.NODE_ENV === "development"
// ? false
// : {
// type: "basic",
// username: process.env.SOCKETIO_ADMIN_USERNAME,
// password: bcrypt.hashSync(process.env.SOCKETIO_PW_HASH_KEY, 10),
// },
mode: "development",
});
socketHandler(io);
// MongoDB Connection // MongoDB Connection
mongoose.Promise = global.Promise; mongoose.Promise = global.Promise;
mongoose mongoose
...@@ -30,10 +57,6 @@ mongoose ...@@ -30,10 +57,6 @@ mongoose
) )
.catch((err) => console.log("Could not connect to MongoDB", err)); .catch((err) => console.log("Could not connect to MongoDB", err));
// Express Server
const app = express();
const server = http.createServer(app);
app.set("views", path.join(__dirname, "../views")); app.set("views", path.join(__dirname, "../views"));
app.set("view engine", "pug"); app.set("view engine", "pug");
app.get("/", (req, res) => { app.get("/", (req, res) => {
...@@ -83,14 +106,6 @@ app.use((err, req, res, next) => { ...@@ -83,14 +106,6 @@ app.use((err, req, res, next) => {
}); });
}); });
const io = new Server(server, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"],
},
});
socketHandler(io);
server.listen(process.env.PORT, () => { server.listen(process.env.PORT, () => {
console.log(`Server is running on port ${process.env.PORT}`); console.log(`Server is running on port ${process.env.PORT}`);
}); });
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment