forked from alyssazhan/ML4GIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (39 loc) · 1.12 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
// server/index.js
const express = require("express");
const app = express();
const path = require('path');
const PORT = process.env.PORT || 3001;
var env = process.env.NODE_ENV || 'development';
var configEnv=require('./config.json').setup.development
// Have Node serve the files for our built React app
// Without middleware
if (configEnv) {
process.env.NODE_ENV = 'development';
}
else {
process.env.NODE_ENV='production';
}
console.log("config env is: ", process.env.NODE_ENV);
app.get('/api', function(req, res,next){
var options = {
root: path.join(__dirname)
};
var fileName = 'config.json';
res.sendFile(fileName, options, function (err) {
if (err) {
next(err);
} else {
console.log('Sent:', fileName);
}
});
});
let allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Headers', "*");
next();
}
app.use(allowCrossDomain);
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
});