diff --git a/.gitignore b/.gitignore index df5af67..e14c5ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/node_modules -.vscode \ No newline at end of file +.vscode +**/.env \ No newline at end of file diff --git a/server/index.js b/server/index.js index e69de29..22864dc 100644 --- a/server/index.js +++ b/server/index.js @@ -0,0 +1,53 @@ +import express from "express"; +import bodyParser from "body-parser"; +import mongoose from "mongoose"; +import cors from "cors"; +import dotenv from "dotenv"; +import multer from "multer"; +import helmet from "helmet"; +import morgan from "morgan"; +import path from "path"; +import { fileURLToPath } from "url"; + +/** + * Config + * */ +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +dotenv.config(); +const app = express(); +app.use(express.json()); +app.use(helmet()); +app.use(helmet.crossOriginResourcePolicy({ policy: "cross-origin" })); +app.use(morgan("common")); +app.use(bodyParser.json({ limit: "30mb", extended: true })); +app.use(bodyParser.urlencoded({ limit: "30mb", extended: true })); +app.use(cors()); +app.use("/assets", express.static(path.join(__dirname, "public/assets"))); + +/** + * Storage + * */ +const storage = multer.diskStorage({ + destination: (req, file, cb) => { + cb(null, "public/assets"); + }, + filename: (req, file, cb) => { + cb(null, file.originalname); + }, +}); +const upload = multer({ storage }); + +/** + * Database + * */ +const PORT = process.env.PORT || 5001; +mongoose + .connect(process.env.MONGO_URL, { + useNewUrlParser: true, + useUnifiedTopology: true, + }) + .then(() => + app.listen(PORT, () => console.log(`Server running on port: ${PORT}`)) + ) + .catch((error) => console.log(error.message));