-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
76 lines (60 loc) · 2.4 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const passport = require("passport");
const session = require("express-session");// allows me to saty signed in
const MongoStore = require("connect-mongo")(session);//stored in mongo data base or for your browser to be consistent and stay logged in
const methodOverride = require("method-override"); //enables any type of request from the browser for any request
const flash = require("express-flash");// sends notifications that a message exists
const logger = require("morgan");//connecting diff code together
const connectDB = require("./config/database");//load database
const mainRoutes = require("./routes/main");//then connect my routes
const journalsRoutes = require("./routes/journals");
const path = require('path');//
const i18n=require("i18n-express"); // <-- require the module
//Use .env file in config folder , so my secrets dont go up w password to gtihub
require("dotenv").config({ path: "./config/.env" });
// Passport config
require("./config/passport")(passport);
//Connect To Database
connectDB();
//Using EJS for views
app.set("view engine", "ejs");
//Static Folder
app.use(express.static("public"));
//Body Parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Logging
app.use(logger("dev"));//morgan to llogin
//Use forms for put / delete
app.use(methodOverride("_method"));//
// Setup Sessions - stored in MongoDB
app.use(
session({
secret: "keyboard cat",
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
})
);
//Setup for Lang in json i18n
app.use(i18n({
translationsPath: path.join(__dirname, 'i18n'), // finds the directory name folder for i18n that stores es , en json
siteLangs: ["en","es"],//i18n tells me to define the lang this way
textsVarName: 'translation',//this variable represents what u see in the ejs file
paramLangName: 'lang',//parameter lang in url
}));
// Passport middleware
app.use(passport.initialize());
app.use(passport.session());
//Use flash messages for errors, info, ect...
app.use(flash());
//Setup Routes For Which The Server Is Listening
app.use("/", mainRoutes);
app.use("/journals", journalsRoutes);
//Server Running
app.listen(process.env.PORT, () => {
console.log("Port number : ",process.env.PORT)
console.log("Server is running, you better catch it!");
});