{"size": 2625, "ext": "js", "max_stars_repo_path": "app.js", "max_stars_repo_name": "mbh1620/haywoods_propertiesv2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app.js", "max_issues_repo_name": "mbh1620/haywoods_propertiesv2", "max_issues_repo_issues_event_min_datetime": "2020-05-11T21:52:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-09T12:52:52.000Z", "max_forks_repo_path": "app.js", "max_forks_repo_name": "mbh1620/haywoods_propertiesv2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 36, "max_forks_count": null, "avg_line_length": 33.6538461538, "max_line_length": 258, "alphanum_fraction": 0.5786666667}
//=====================================================
//
//              Haywood's Properties app.js
//                
//=====================================================

//author: Matthew Haywood

// Module Imports
var dotenv = require("dotenv").config();
var express = require("express");
var app = express();
var mongoose = require("mongoose");
var bodyParser = require("body-parser");
var methodOverride = require("method-override");

// Route Imports 
var propertyroutes = require('./routes/propertyroutes');
var tenantroutes = require('./routes/tenantroutes');
var usersroutes = require('./routes/usersroutes');
var graphingroutes = require('./routes/graphingroutes').router;
var scheduler_monthly = require('./routes/graphingroutes').j;

//app config
app.use(methodOverride("_method"));

app.use(require("express-session")({
    secret: "Once again Rusty wins the cutest dog!",
    resave: false,
    saveUninitialized: false
}));

//=====================================================
app.set('views', './views');

app.use('/uploads', express.static('uploads'));
app.use(express.static(__dirname + "/public"));
app.use('/scripts', express.static(__dirname + "/views/manageproperties"));

//====================================================
//                 Database connection
//====================================================

if(process.env.NODE_ENV === 'production'){
    //Connect to Production Database
    mongoose.connect("mongodb+srv://" + process.env.DB_USER + ":" + process.env.DB_PASS + "@cluster0.drwm0.mongodb.net/Haywoods_properties?retryWrites=true&w=majority", { useUnifiedTopology:true, useNewUrlParser: true, useFindAndModify: false });
} else if (process.env.NODE_ENV === 'development'){
    //Connect to Development Database
    mongoose.connect("mongodb+srv://" + process.env.DB_USER + ":" + process.env.DB_PASS + "@cluster0.drwm0.mongodb.net/Haywoods_properties_development?retryWrites=true&w=majority", { useUnifiedTopology:true, useNewUrlParser: true, useFindAndModify: false });
} 

app.use(bodyParser.urlencoded({ extended: true }));

//=====================================================
//
//                   Main App Routes 
//
//=====================================================

app.use("/",usersroutes);
app.use("/",propertyroutes);
app.use("/",graphingroutes);
app.use("/",tenantroutes);

// Index route
app.get("/", function (req, res) {
    var page = "Home"
    res.render("home.ejs", {page:page});
});

// 404 - Error Route
app.get("/*", function (req, res){
    var page = "404 Error"
    res.render("error.ejs", {page:page});
})

app.listen("8080");
