-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (39 loc) · 1.14 KB
/
index.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
const express = require('express');
const fs = require('fs');
const cors = require('cors')
const bodyParser = require('body-parser');
const mysql = require('mysql');
const credentials = require('./credentials');
const fileUpload = require('express-fileupload');
const multer = require('multer')
const serveIndex = require('serve-index');
const PORT = process.env.PORT || 8001;
const app = express();
app.use(cors());
const db = mysql.createPool({
/*
host: 'localhost',
user: 'root',
password: 'password',
database: 'test',
*/
multipleStatements: true,
host: credentials.host,
user: credentials.user,
password: credentials.password,
database: credentials.database,
})
app.use(bodyParser.json());
app.use(express.static(__dirname + "/"))
app.use('/uploads', serveIndex(__dirname + '/uploads'));
let upload = multer({ dest: 'uploads/' })
app.use(fileUpload({
createParentPath: true
}));
fs.readdirSync(__dirname + '/routes').forEach(function(file) {
let name = file.substr(0, file.indexOf('.'));
require('./routes/' + name)(app, db, upload, fs);
});
app.listen(PORT, () => {
console.log(`APP is now running on port ${PORT}!`);
})