first commit to new repo

This commit is contained in:
Daniel Ledda
2020-05-10 15:16:01 +02:00
commit a57ad3af42
478 changed files with 90510 additions and 0 deletions

47
src/index.ts Executable file
View File

@@ -0,0 +1,47 @@
import express from "express";
import {initialisePassport, requireAuthenticated, requireNotAuthenticated} from "./passport-config";
import mongoose from "mongoose";
import Settings from "./server-config.json";
import flash from "express-flash";
import passport from "passport";
import session from "express-session";
import * as path from "path";
import MainRouter from "./routers/mainRouter";
// MongoDB Setup
mongoose.connect(Settings.mongodb_uri, (err: any) => {
if (err) {
console.log(err.message);
}
else {
console.log("Successfully connected to mongoDB!");
}
});
// Express app config
const app = express();
app.use(express.json());
app.set("port", process.env.PORT || 3000);
app.set("view-engine", "ejs");
app.use(express.urlencoded({ extended: false}));
app.use(flash());
app.use(session({
// TODO hide the secret
secret: "secret",
saveUninitialized: false,
resave: false
}));
app.locals = {
rootUrl: Settings.serverRoot
};
// Passport init
initialisePassport();
app.use(passport.initialize());
app.use(passport.session());
app.use(Settings.serverRoot, MainRouter);
const server = app.listen(app.get("port"), () => {
console.log("App is running on http://localhost:%d", app.get("port"));
});