forked from upstanding-biome/sixdegrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
81 lines (64 loc) · 2.65 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use strict";
/*=======================================================|
| Call in express and other node_modules |
|=======================================================*/
var express = require('express'),
https = require('https'),
http = require('http'),
path = require('path'),
bodyParser = require('body-parser'),
app = express(),
dbRemote = require('./db/db');
/*=======================================================|
| Sets port to environment port or local port |
|=======================================================*/
var port = process.env.PORT || 7473;
/*=======================================================|
| connecting the client and server |
| allows for CORS (cross origin resource sharing) |
|=======================================================*/
app.use('player', function(req, res, next) {
// console.log("req",req);
// console.log("res",res);
res.header("access-control-allow-origin", "*");
res.header("access-control-allow-headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
/*=======================================================|
| statically serves files from the client directory |
|=======================================================*/
app.use('/node_modules', express.static(__dirname + '/node_modules'));
app.use(express.static(__dirname + '/public'));
/*=======================================================|
| ROUTES |
|=======================================================*/
app.get('/', function(req, res) {
res.location('/public/index.html');
});
app.post('/player', function(req, res){
// console.log(req.body.query);
dbRemote.queryRaw(req.body.query,{}, function(err, result){
if (err) throw err;
res.send(result);
});
});
app.post('/picture', function(req, res){
var str = req.body["data"];
res.send(str);
});
/*=======================================================|
| Test |
|=======================================================*/
// dbRemote.queryRaw("MATCH (n:Player) RETURN n LIMIT 1", {}, function(err, result) {
// if (err) throw err;
// console.log("Query is working")
// });
/*=======================================================|
| Calling the server |
|=======================================================*/
app.listen(port, function() {
console.log('Tip off on port', port);
});
exports = module.exports = app;