-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
46 lines (40 loc) · 1.29 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
'use strict'
// Requiring all Dependencies
const express = require('express'),
bodyParser = require('body-parser'),
fs = require('fs'),
config = require('./config/'),
path = require('path');
// App
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
// Enabling CORS
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header(
'Access-Control-Allow-Headers',
'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json'
);
next();
});
// Create audio/ and upload/ folders incase they don't already exist
// This is for the heroku platform with its ephemeral filesystem
try {
fs.existsSync("./audio") || fs.mkdirSync("./audio");
fs.existsSync("./upload") || fs.mkdirSync("./upload");
} catch (err) {
console.log(err);
}
// Routes
app.use('/api', require('./routes/'));
app.use('*', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
// App Listen
app.listen(config.port, function() {
console.log('App Started on Port ', config.port);
});