forked from caracolplusplus/avalon.ist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
86 lines (68 loc) · 2.47 KB
/
app.js
File metadata and controls
86 lines (68 loc) · 2.47 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const d = require('domain').create();
d.on('error', function (err) {
// Handle errors
const { message, stack } = err;
console.log(err);
const environment = require('./routes/constructors/environment').getGlobal();
environment.addErrorLog({ message, stack });
});
d.run(function () {
// Create Parse Server
const ParseServer = require('parse-server').ParseServer;
const api = new ParseServer({
databaseURI: process.env.DATABASE_URI || 'mongodb://localhost:27017/dev2',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'AVALONIST',
masterKey: process.env.MASTER_KEY || 'avalonist_key',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
logLevel: 'warn',
/* passwordPolicy: {
validatorPattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{6,})/,
validationError:
'Password must have at least 6 characters, with 1 upper case letter and 1 digit.',
doNotAllowUsername: true,
}, */
/* EMAIL VERIFICATION REQUIRES MAILGUN */
});
// Start Express
const express = require('express');
const path = require('path');
const ms = require('mediaserver');
const app = express();
// Serve React
app.use(express.static('build'));
// Add Cookie Parser
const cookieParser = require('cookie-parser');
app.use(cookieParser());
// Serve Parse API
const mount = process.env.PARSE_MOUNT || '/parse';
app.use(mount, api);
// Routing
app.get('/audio/notification.ogg', (req, res) => {
ms.pipe(req, res, __dirname + '/audio/notification.ogg');
});
app.get('/audio/slap.ogg', (req, res) => {
ms.pipe(req, res, __dirname + '/audio/slap.ogg');
});
app.get('/audio/rejected.ogg', (req, res) => {
ms.pipe(req, res, __dirname + '/audio/rejected.ogg');
});
app.get('/audio/lick.ogg', (req, res) => {
ms.pipe(req, res, __dirname + '/audio/lick.ogg');
});
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/build/index.html'));
});
// Set Server and Port
const port = process.env.PORT || 1337;
const server = require('http').createServer(app);
// Initialize SocketIO
const socketIO = require('socket.io');
const socketRoutes = require('./routes/init');
const io = socketIO(server);
socketRoutes.initialize(io);
// Listen
server.listen(port, () => {
console.log(`Avalon.ist running on port ${port}.`);
});
});