-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (41 loc) · 1.32 KB
/
app.js
File metadata and controls
50 lines (41 loc) · 1.32 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
48
49
50
const fs = require('fs');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
//dot env
const dotenv = require('dotenv');
dotenv.config();
// enabling CORS for all requests
app.use(cors());
// Parse incoming requests data (https://github.com/expressjs/body-parser)
// using bodyParser to parse JSON bodies into JS objects
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/*
app.use('/a',express.static('/b'));
Above line would serve all files/folders inside of the 'b' directory
And make them accessible through http://localhost:3100/a.
*/
const dir = path.join(__dirname, 'public');
app.use(express.static(dir));
// create upload folder
const folderName = `${dir}/uploads`;
try {
if (!fs.existsSync(folderName)) {
fs.mkdirSync(folderName);
}
} catch (err) {}
/* */
//router routes
const productRouter = require('./server/router/ProductRouter');
const categoryRouter = require('./server/router/CategoryRouter');
const userRouter = require('./server/router/UserRouter');
app.use('/api', productRouter);
app.use('/api', categoryRouter);
app.use('/api', userRouter);
const port = process.env.PORT || 3100;
app.listen(port, function () {
console.log('Express server listening on port ' + port);
});