Skip to content
Permalink
1e00994d0f
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
61 lines (52 sloc) 1.55 KB
import express from "express";
import bodyParser from "body-parser";
import chalk from "chalk";
import cors from "cors";
import cfg from "config";
import session from "express-session";
import errorHandler from "errorhandler";
import registerRoutes from "./routes/register.js";
const app = express();
const mode = process.env.NODE_ENV || "dev";
const config = cfg.get(mode);
app.use(
cors({
origin: config.siteUrl,
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.json());
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(function(req, res, next) {
console.log('SESSION: ', !!req.session)
next();
});
app.use(
session({
name: "random_session",
secret: "verysecret",
resave: false,
saveUninitialized: true,
cookie: {
secure: false,
maxAge: 600000,
sameSite: "none",
},
})
);
app.use(errorHandler());
app.use("/api/v1", registerRoutes);
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("......................................."));
});