-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
62 lines (51 loc) · 2.1 KB
/
app.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
// Load environment variables from .env file
require("dotenv").config();
// Load environment variables based on NODE_ENV
require('custom-env').env(process.env.NODE_ENV, './');
// Connect to MongoDB
const mongoose = require("mongoose");
mongoose.set('strictQuery', true); // Enable strict mode for queries
mongoose.connect(process.env.CONNECTION_STRING, {
useNewUrlParser: true, // Use new URL parser
useUnifiedTopology: true // Use new server engine
});
// Import Express and create app
const express = require("express");
const app = express(); // Create Express app
// Set up sessions
const session = require('express-session');
app.use(session({
secret: process.env.SECRET, // Secret key for sessions
saveUninitialized: false, // Don't save empty sessions
resave: false // Don't save unchanged sessions
}));
// Use EJS for templates
const ejs = require('ejs');
app.set("view engine", "ejs"); // Set EJS as template engine
// Set views folder
const path = require('path');
app.set('views', path.join(__dirname, 'views')); // Set folder for templates
// Parse form data
app.use(express.urlencoded({
extended: false, // Simple query strings
limit: '50mb' // Increase data limit
}));
// Parse JSON data
app.use(express.json({ limit: '50mb' })); // Increase data limit
// Serve static files
app.use(express.static('public')); // Serve files in public folder
// Define routes
app.use("/", require("./routes/home")); // Home page
app.use("/login", require("./routes/login")); // Login page
app.use("/about", require("./routes/about")); // About page
app.use("/client", require("./routes/client")); // Client page
app.use("/products", require("./routes/products")); // Products page
app.use("/tickets", require("./routes/tickets")); // Tickets page
app.use("/manager", require("./routes/manager")); // Manager page
app.use("/clients", require("./routes/clients")); // Clients page
app.use("/cart", require("./routes/cart")); // Cart page
// Start server
const port = process.env.PORT || 8084; // Set port
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`); // Show server start message
});