forked from MithraPerera/passwordkeepr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
70 lines (59 loc) · 2.09 KB
/
server.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
63
64
65
66
67
68
69
70
// Load environment variables from .env file
require('dotenv').config();
// Import required modules
const sassMiddleware = require('./lib/sass-middleware');
const express = require('express');
const morgan = require('morgan');
const bcrypt = require("bcryptjs");
const cookieSession = require("cookie-session");
const PORT = process.env.PORT || 8080;
const app = express();
// Set the view engine to EJS
app.set('view engine', 'ejs');
// Middleware setup
app.use(morgan('dev')); // Logging middleware
app.use(express.urlencoded({ extended: true })); // Parse URL-encoded bodies
// Sass middleware for compiling SASS to CSS
app.use(
'/styles',
sassMiddleware({
source: __dirname + '/styles',
destination: __dirname + '/public/styles',
isSass: false,
})
);
// Serve static files from the 'public' directory
app.use(express.static('public'));
// Import required functions and routes
const { registerNewUser } = require('./db/queries/registerNewUser.js');
app.use(cookieSession({
name: 'session',
keys: ['midterm'],
}));
const usersRoutes = require('./routes/users');
const homeRoute = require('./routes/home');
const registerRoute = require('./routes/register');
const loginRoute = require('./routes/login');
const logoutRoute = require('./routes/logout');
const categoryRoute = require('./routes/categories')
const createAccountRoute = require('./routes/createAccount');
const editAccountRoute = require('./routes/editAccount');
const deleteAccountRoute = require('./routes/deleteAccount');
// Define routes for different URL paths
app.use('/users', usersRoutes);
app.use('/home', homeRoute);
app.use('/register', registerRoute);
app.use('/login', loginRoute);
app.use('/logout', logoutRoute);
app.use('/users/category/', categoryRoute);
app.use('/createAccount', createAccountRoute);
app.use('/editAccount', editAccountRoute);
app.use('/deleteAccount', deleteAccountRoute);
// Redirect the root path to '/home'
app.get('/', (req, res) => {
res.redirect('/home');
});
// Start the server and listen on the specified port
app.listen(PORT, () => {
console.log(`Example app listening on port ${PORT}`);
});