{"size": 1263, "ext": "js", "max_stars_repo_path": "server.js", "max_stars_repo_name": "rooneyrulz/reactjs_user_login", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server.js", "max_issues_repo_name": "rooneyrulz/reactjs_user_login", "max_issues_repo_issues_event_min_datetime": "2020-09-06T13:17:51.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T15:24:33.000Z", "max_forks_repo_path": "server.js", "max_forks_repo_name": "rooneyrulz/reactjs_user_login", "max_forks_repo_forks_event_min_datetime": "2019-07-18T03:31:54.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-18T03:31:54.000Z"}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": 1, "avg_line_length": 23.8301886792, "max_line_length": 81, "alphanum_fraction": 0.67695962}
import { createServer } from "http";
import express from "express";
import logger from "morgan";

//  Import MongoDB Connection
import db from "./config/db";

// Import Routes
import testRoute from "./routes";
import signUpRoute from "./routes/user";
import authRoute from "./routes/auth";

const app = express();
const server = createServer(app);

// Use Mongo Connection
db();

// Use Http-Logger Middleware
app.use(logger("dev"));

// Use Express Middleware Functions for Parsing JSON Body
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// Handle CORS
app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header(
    "Access-Control-Allow-Headers",
    "Origin, Content-Type, X-Requested-With, Accept, Authorization, x-auth-token"
  );

  if (req.method === "OPTIONS") {
    res.header("Access-Control-Allow-Methods", "PUT POST PATCH GET DELETE");
    return res.status(200).json({});
  }
  next();
});

// Implement Routes
app.use("/api", testRoute);
app.use("/api", signUpRoute);
app.use("/api/auth", authRoute);

// Setup Port
app.set("port", process.env.PORT || 5000);

// Listening to Server
server.listen(app.get("port"), () =>
  console.log(`server listening on port ${app.get("port")}`)
);
