-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (42 loc) · 1.46 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
47
48
49
50
51
52
53
54
55
require("dotenv-safe").config({
allowEmptyValues: true,
});
const morgan = require("morgan");
const bodyParser = require("body-parser");
const express = require("express");
const cors = require("cors");
const querystring = require("querystring");
const errorHandler = require("errorhandler");
const fs = require('fs')
const path = require("path")
const isProduction = process.env.NODE_ENV === "production";
const { VIDEO_FILEPATH, PICTURE_FILEPATH } = process.env;
if (!fs.existsSync(VIDEO_FILEPATH)) {
fs.mkdirSync(VIDEO_FILEPATH);
console.log(`Created video filepath: ${VIDEO_FILEPATH}.`)
}
if (!fs.existsSync(PICTURE_FILEPATH)) {
fs.mkdirSync(PICTURE_FILEPATH);
console.log(`Created picture filepath: ${PICTURE_FILEPATH}.`)
}
const app = express();
app.get(`/${PICTURE_FILEPATH}/:fileName`, (req, res) => {
let { fileName } = req.params;
res.sendFile(path.join(__dirname+`/${PICTURE_FILEPATH}/${fileName}`));
})
app.use(express.static(path.join(__dirname, 'client/build')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(morgan("dev"));
if (!isProduction) {
app.use(errorHandler())
}
require('./models');
require('./config/passport');
app.use(require('./routes'));
app.get('*', (req,res) => {
console.log("Catchall - sending client")
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
const port = process.env.PORT || 8000;
app.listen(port, () => console.log(`Example app listening on port ${port}!`))