-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (61 loc) · 1.92 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// server.js
require("dotenv").config()
var express = require('express');
var path = require('path');
const history = require('connect-history-api-fallback');
var serveStatic = require('serve-static');
var bodyParser = require("body-parser");
var cors = require('cors')
var firebase = require("firebase");
// Required for side-effects
require("firebase/functions");
var firebaseConfig = {
apiKey: process.env.apiKey,
authDomain: process.env.authDomain,
databaseURL: process.env.databaseURL,
projectId: process.env.projectId,
storageBucket: process.env.storageBucket,
messagingSenderId: process.env.messagingSenderId,
appId: process.env.appId
};
firebase.initializeApp(firebaseConfig);
var functions = firebase.functions();
var getGameInfos = firebase.functions().httpsCallable('getGameInfos');
var killed = firebase.functions().httpsCallable('killed');
app = express();
app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// routes(app);
app.get('/api/game/:id', function (req, res, next) {
getGameInfos({ gameId: req.params.id }).then(function (result) {
res.json(result.data)
}, function(error) {
res.json(error)
});
})
app.post('/api/game/:id/killed', function (req, res, next) {
killed({
gameId: req.params.id,
playerName: req.body.playerName,
status: req.body.status
}).then(function (result) {
res.json(result.data)
}, function(error) {
res.json(error)
})
})
const staticFileMiddleware = express.static(path.join(__dirname + '/dist'));
app.use(staticFileMiddleware);
app.use(history({
disableDotRule: true,
verbose: true
}));
app.use(staticFileMiddleware);
// app.use(serveStatic(__dirname + "/dist"));
app.get('/', function (req, res) {
res.render(path.join(__dirname + '/dist/index.html'));
});
var port = process.env.PORT || 5000;
app.listen(port);
console.log('server started ' + port);