-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
68 lines (45 loc) · 1.32 KB
/
app.js
File metadata and controls
68 lines (45 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
require('dotenv').config();
/* env file:
DB_HOST=[host]
DB_USER=[user]
DB_PASS=[pass]
DB_NAME=[name]
production=false
*/
// On production, env file can also have line: "PROXY_PASS=/[proxy_pass]",
// which adds the following addition to the path "http://ip/[proxy_pass]/index.html"
const production = process.env.production == "true" ? true : false; // Is running on server? "true"/"false"
const port = 3000;
console.log("production: ", production);
/* REQUIRE */
const express = require('express');
const app = express();
const posts = require('./require/routes/postRoute');
const users = require('./require/routes/userRoute');
if (!production) {
const cors = require('cors')
app.use(cors());
}
/* INIT */
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/uploads',express.static('uploads'));
app.use(express.static('public_html'));
app.use('/thumbnails', express.static('thumbnails'));
/* CONFIGURE */
/* RUN */
if (production) {
require('./require/servers/production')(app, port);
} else {
require('./require/servers/localhost')(app, 8000, port);
}
/* ROUTE */
app.use('/posts', posts);
app.use('/users', users);
app.get('/test', (req, res) => // Example
{
res.send('Hello Secure World!');
});
module.export = production; // Is running on server? "true"/"false"
/*END*/