-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (36 loc) · 1.36 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
const express = require('express');
const path = require('path');
const session = require('express-session')
const connectMongoDB = require('./config/database');
const mainRoute = require('./routes/mainRoute');
const authRoute = require('./routes/authRoute');
const adminRoute = require('./routes/adminRoute');
const timeRoute = require('./routes/timeRoute');
const weatherRoute = require('./routes/weatherRoute');
const coordinateRoute = require('./routes/coordinateRoute');
const dataRoute = require('./routes/dataControlRoute')
require('dotenv').config();
const app = express();
//MongoDB Connection
connectMongoDB();
//Middleware configuration
app.use(session({ secret: 'darkhost', resave: false, saveUninitialized: false}));
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname,'public' ,'views'));
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
//Routes
app.use('/', mainRoute);
app.use('/', authRoute);
app.use('/', adminRoute);
app.use('/timeAPI', timeRoute)
app.use('/weatherAPI', weatherRoute);
app.use('/coordinateAPI', coordinateRoute);
app.use('/dataAPI', dataRoute);
app.all("*", async (req,res) => {
res.status(500).sendFile(path.join(__dirname, 'public', 'views', '404.html'));
})
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Local server is running on http://localhost:${PORT}/`);
});