const express = require("express");
const app = express();
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const cors = require('cors');
app.use(cors({
    origin: 'https://p2share.me:3000'
}));
//Import Routes
const authRoute = require("./routes/auth.js");
const postRoute = require("./routes/posts");

dotenv.config();

//Connect to DB
mongoose.connect(process.env.DB_CONNECT, { useNewUrlParser: true  }, () =>
  console.log("connected to DB!")
);

//Middleware
app.use(express.json());

//Route Middlewares
app.use("/api/user", authRoute);
app.use("/api/posts", postRoute);

const https = require('https');
const fs = require('fs');
const server = https.createServer({

        cert: fs.readFileSync("/home/ferrane/claus/fullchain.pem"),

        key: fs.readFileSync("/home/ferrane/claus/privkey.pem"),

}, app).listen(3333, function() { console.log('Server up and running')});
