UNPKG

sama-master

Version:

Sama Business Services® Master Node Library

171 lines (137 loc) • 4.23 kB
const express = require("express"); const socketio = require("socket.io"); const http = require("http"); const router = require("./router"); const path = require("path"); const publicIp = require("public-ip"); var os = require("os"); var ipAddress = require("ip"); var privateIP = ipAddress.address(); console.log(os.hostname()); const firebaseAdmin = require("firebase-admin"); // var ifaces = os.networkInterfaces(); // Object.keys(ifaces).forEach(function (ifname) { // var alias = 0; // ifaces[ifname].forEach(function (iface) { // if ("IPv4" !== iface.family || iface.internal !== false) { // // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses // return; // } // if (alias >= 1) { // // this single interface has multiple ipv4 addresses // console.log(ifname + ":" + alias, iface.address); // } else { // // this interface has only one ipv4 adress // console.log(ifname, iface.address); // } // ++alias; // }); // }); //const Request = require("./db-ct"); //const connection = require('./connect/connect2'); require("dotenv").config(); const authRoute = require("./routes/auth"); // const server = http.createServer((request, response) => { // response.writeHead(200, {"Content-Type": "text/plain"}); // response.end("Hello World!"); // }); const port = process.env.PORT; const hostname = process.env.HOST; const app = express(); const server = http.createServer(app); const io = socketio(server); server.listen(port, () => console.log("Server running at http://" + hostname + ":%s", port) ); //var micro = "I'm Micro Variable"; app.use(express.static(path.join(__dirname, "serve"))); io.on("connection", (socket) => { // Welcome current user publicIp.v4().then((ip) => { const IOV = { "IO-Version": process.env.IOVersion, Author: "~0x000001", IPv4: ip, }; const ppKeys = [ { "Private RSA Key": privateKey, }, { "Publick RSA Key": publicKey, }, ]; console.log("New Connection From:", ip, "on:", IOV); socket.emit("message", "Welcome to IO Systems" + IOV); socket.emit("message", "Server Name: " + os.hostname()); socket.emit("message", "Private IP Address: " + privateIP); socket.emit("message", "Public IP Address: " + ip); socket.emit("message", ppKeys); //console.log("your public ip address", ip); }); // Broadcast when user connects socket.broadcast.emit("message", "User has joined channel"); // Runs when client disconnects socket.on("disconnect", () => { io.emit("message", "User has left channel"); }); const crypto = require("crypto"); const { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", { modulusLength: 4096, publicKeyEncoding: { type: "spki", format: "pem", }, privateKeyEncoding: { type: "pkcs8", format: "pem", }, }); //console.log(privateKey); //console.log(publicKey); // socket; // const IOV = { // "IO-Version": "1.1.0", // Author: "~0x000001", // IPv4: null, // }; // socket.emit("message", IOV); // socket.emit("message", "Your ip address: " | ip); }); app.use("/api/user", authRoute); //console.log(router); //console.log(io); //publicIp.v4().then(ip); const IOV = { "IO-Version": "1.1.0", Author: "~0x000001", IPv4: null, }; //console.log(IOV); app.use(router); //("use strict"); // function getIP() { // => { // console.log("your public ip address", ip); // }); // } //alertSystem(router); // console.log("hello node"); function pressureFunction(options) {} //alertSystem(); function alertSystem(options) { //const options = { name: "option2", age: 22 }; console.log("hello node"); //console.log(router); } // console.log(` // Version: ${MBSV} // `); app.get("/route", (req, res) => { res.send("GET request to the homepage"); }); app.post("/post", function (req, res) { res.send("POST request to the homepage"); }); module.exports = alertSystem; // module.exports = MBSV;