-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (40 loc) · 1.53 KB
/
Copy pathindex.js
File metadata and controls
47 lines (40 loc) · 1.53 KB
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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const app = express();
const router = express.Router();
const config = require('./config/database');
const mongoose = require('mongoose');
const PORT = process.env.PORT || 3000;
const path = require('path');
require('http').Server(app);
// const http = require('http').Server(app);
//routes
const users = require('./routes/users')(router);
const authentication = require('./routes/authentication')(router);
const file = require('./routes/fileupload')(router);
mongoose
.connect(config.uri)
.then(() => console.log('Connected to the database:', process.env.DB_NAME))
.catch((err) => console.error('Error connecting to database:', err));
app.use(cors());
app.use(express.json({ limit: '20mb' }));
app.use(express.urlencoded({ limit: '20mb', extended: false }));
//for deployment on hosting and build
app.use(express.static(__dirname + '/app/dist/'));
app.use('/images', express.static(path.join(__dirname, './images')));
app.use('/uploads', express.static(path.join(__dirname, '../uploads/files')));
app.use('/uploads', express.static(path.join(__dirname, '../uploads/images')));
app.use('/authentication', authentication);
app.use('/users', users);
app.use('/fileupload', file);
app.use(
'/profile_pic',
express.static(path.join(__dirname, '../uploads/images'))
);
app.get('*', (req, res) => {
// res.sendFile(path.join(__dirname + '/app/dist/index.html'));
});
app.listen(PORT, () => {
console.log('Connected on port ' + PORT);
});