Skip to content
Permalink
c63a8ed595
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
85 lines (76 sloc) 2.21 KB
import express from "express";
import "dotenv/config.js";
import bodyParser from "body-parser";
import chalk from "chalk";
import cors from "cors";
import cfg from "config";
import compression from "compression";
import session from "express-session";
import errorHandler from "errorhandler";
import connectMongo from "connect-mongo";
import registerRoutes from "./routes/register.js";
import verificationRoutes from "./routes/verification.js";
import dbConnection from "./helpers/db.js";
const app = express();
const mode = process.env.NODE_ENV || "dev";
const config = cfg.get(mode);
app.use(
cors({
origin: [config.siteUrl, "localhost"],
credentials: true,
allowedHeaders: [
"Content-Type",
"Authorization",
"X-Requested-With",
"X-Forwarded-Proto",
"Cookie",
"Set-Cookie",
],
exposedHeaders: [
"Content-Type",
"Authorization",
"X-Requested-With",
"X-Forwarded-Proto",
"Cookie",
"Set-Cookie",
],
})
);
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(bodyParser.json());
app.use(compression());
const MongoStore = connectMongo(session);
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
store: new MongoStore({ mongooseConnection: dbConnection.connection }),
saveUninitialized: true,
})
);
// app.use(function (req, res, next) {
// if (req.session.views) {
// req.session.views++;
// console.log("req.session.views: ", req.session.views);
// console.log("Expires: ", req.session.cookie.maxAge / 1000);
// } else {
// req.session.views = 1;
// console.log("welcome to the session demo. refresh!");
// }
// next();
// });
app.use(errorHandler());
app.use("/api/v1", registerRoutes);
app.use("/api/v1/verification", verificationRoutes);
app.listen(process.env.PORT || config.port, () => {
console.log(chalk.yellow("......................................."));
console.log(chalk.green(config.name));
console.log(chalk.green(`Port:\t\t${process.env.PORT || config.port}`));
console.log(chalk.green(`Site:\t\t${config.siteUrl}`));
console.log(chalk.green(`Mode:\t\t${config.mode}`));
console.log(chalk.yellow("......................................."));
});