-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
33 lines (27 loc) · 976 Bytes
/
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
const express = require('express');
const path = require('path');
const fs = require('fs');
const helmet = require('helmet');
// Check if configuration files exists.
if (!fs.existsSync('config.json')) {
console.log('Error: config.json does not exist. Please run: npm run config.');
} else {
const app = express();
// Load configuration.
const config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
// Export configuration.
exports.config = config;
const PORT = config.port;
// Body parsers.
app.use(express.json()); // JSON.
app.use(express.urlencoded({ extended: false })); // Form data.
// Helmet middleware.
app.use(helmet());
// Set static folder.
app.use(express.static(path.join(__dirname, 'public')));
// Use login API.
app.use('/api/login', require('./routes/api/login'));
// Use Files API.
app.use('/api/files', require('./routes/api/files'));
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
}