const express = require("express"); const path = require("path"); const app = express(); //const cors = require("cors"); const morgan = require("morgan"); const socketio = require("socket.io"); const pg = require("pg"); delete pg.native; const db = require("./db"); const chalk = require("chalk"); //const passport = require('passport') //const LocalStrategy = require('passport-local') //const session = require('express-session') //const SequelizeStore = require('connect-session-sequelize')(session.Store) //const sessionStore = new SequelizeStore({ db }) //const bot = require('../ircbot') const PORT = process.env.PORT || 3500; //const URL = ["http://localhost:3400"]; app.use(morgan("dev")); //app.use(cors({ credentials: true, origin: URL })) // passport.use( // new LocalStrategy(async (username, password, done) => { // const user = await db.models.user.findOne({ where: { username } }) // if (!user) { // return done(null, false, { message: 'Incorrect username.' }) // } // if (!user.correctPassword(password)) { // return done(null, false, { message: 'Incorrect password.' }) // } // return done(null, user) // }) // ) //passport.serializeUser((user, cb) => cb(null, user.id)) // passport.deserializeUser(async (id, cb) => { // try { // const user = await db.models.user.findByPk(id) // if (!user) return cb(null, { id: 0 }) // const idType = user.isAdmin ? 'trainerId' : 'userId' // const { sessions, reviews, notes, referrers } = await user.fetchMyData( // idType // ) // user.setDataValue('sessions', sessions) // user.setDataValue('reviews', reviews) // user.setDataValue('notes', notes) // user.setDataValue('referrers', referrers) // cb(null, user) // } catch (err) { // console.log('error', err) // cb(err) // } // }) // app.use( // session({ // secret: process.env.SESSION_SECRET || 'LAKaLIHWIUH9*&h3ISVAEOIUFHAW83w', // store: sessionStore, // resave: false, // saveUninitialized: false, // cookie: { maxAge: 3600000 }, // }) // ) // // app.use(passport.initialize()) // app.use(passport.session()) // body parsing middleware app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(require("body-parser").text()); //app.use("/api", require("./api")); //app.use('/auth', require('./auth')) app.use( "/static", express.static(path.resolve(__dirname, "..", "build", "static")) ); app.get("/manifest.json", (req, res) => { res.sendFile(path.resolve(__dirname, "..", "build", "manifest.json")); }); app.get("/favicon.png", (req, res) => { res.sendFile(path.resolve(__dirname, "..", "build", "favicon.png")); }); app.use("*", express.static(path.resolve(__dirname, "..", "build"))); // error handling endware app.use((err, req, res, next) => { console.error(err); console.error(err.stack); res.status(err.status || 500).send(err.message || "Internal server error."); next(); }); const startListening = () => { const server = app.listen(PORT, () => { console.log(chalk.blue(`[Express] Listening on port ${PORT}`)); }); const io = socketio(server); require("./socket")(io); }; const startApp = async () => { //await sessionStore.sync(); await startListening(); }; startApp();