forked from antonroesler/application-landscape-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
87 lines (69 loc) · 1.7 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
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright (c) 2021 Ecore. All rights reserved.
*
* University: Frankfurt University of Applied Sciences
* Study program: Engineering Business Information Systems
* Module: Advanced Programming 2021
* Professor: Prof. Dr. Jung, Prof. Dr. Bremm
* Date: 03.05.2021
*
*/
/**
* Defines the node.js server.
* @author Anton Roesler, Leonard Husske
*
*/
/**
* Required External Modules
*/
const express = require('express');
const path = require('path');
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const cors = require("cors");
require('dotenv/config')
/**
* App Variables
*/
const app = express();
const port = process.env.PORT || '8000';
/**
* App Configuration
*/
app.use(express.static('public')) // set the static files location
//app.use(bodyParser.json())
app.use(cors()) // Need to use cors to make API requests due to CORS-policy
app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({limit: '50mb'}));
/**
* Routes Definitions
*/
app.get('/', (req, res) => {
res.sendFile('./public/index.html');
});
// MongoDB Route
const mongoRoute = require('./routes/mongo')
app.use('/mongo', mongoRoute)
// Tinycolor2 Route
// Import routes
const tinycolorRoute = require('./routes/color')
app.use('/color', tinycolorRoute)
/**
* Database
*/
mongoose.connect(
process.env.DB_CONNECTION, {useNewUrlParser: true}, err =>{
if (err===null) {
console.log('Connected to DB')
}
else{
console.error('Failed to connect to DB. Check your credentials in .env ')
}
}
)
/**
* Server Activation
*/
app.listen(port, () => {
console.log(`Listening to requests on http://localhost:${port}`);
});