-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (44 loc) · 1.65 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
48
49
50
51
52
53
54
55
56
57
58
59
var express = require('express');
var fs = require('fs');
var mongoose = require('mongoose');
var app = express();
var path = require('path');
var bodyParser = require('body-parser');
var turf = require('@turf/turf');
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.use('/scripts', express.static(__dirname + '/node_modules'));
app.use(bodyParser.json({limit: '200mb'}));
app.use(bodyParser.urlencoded({limit: '200mb', extended: true, parameterLimit:50000}));
// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
response.render('pages/index')
});
app.get('/api/buffer', function(request, response) {
response.json({message: 'API!!'});
});
//buffer computations
app.post('/api/buffer', function(request,response){
result = turf.buffer(request.body.layer, request.body.dist, 'kilometers');
response.send(result);
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
// Connection URL
var url = 'mongodb://heroku_k7jjmzwc:[email protected]:39327/heroku_k7jjmzwc';
// mongoose.connect(url);
// mongoose.connection.on('connected', function () {
// console.log('connected correctly to server');
// });
// load all files in models dir
// fs.readdirSync(__dirname + '/models').forEach(function(filename) {
// if (~filename.indexOf('.js')) require(__dirname + '/models/' + filename)
// });
// app.get('/users', function(req, res) {
// mongoose.model('users').find(function(err, users) {
// res.send(users);
// });
// });