-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
66 lines (54 loc) · 1.46 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
/**
* Created by Binnur Kurt on 2/3/2015.
*/
var express= require('express'),
stylus= require('stylus'),
mongoose= require('mongoose');
var app= express();
function compile(src,path){
// css pre-processor like less
return stylus(src).set('filename',path);
}
app.set('views', __dirname + '/server/views');
app.set('view engine', 'jade');
app.use(stylus.middleware({
"src": __dirname + '/public',
"compile": compile
}));
app.use(express.static(__dirname + '/public'));
mongoose.connect('mongodb://localhost:27017/gis');
var mapSchema = new mongoose.Schema({
"_id": mongoose.Schema.Types.ObjectId,
"name": String,
width: Number,
height: Number,
bbox: {
"minx": Number,
"miny": Number,
"maxx": Number,
"maxy": Number
} ,
wmsUrl: String,
wmsLayer: String,
zoom: Number,
crs: String
});
var Map= mongoose.model('maps', mapSchema);
app.get('/maps/:name',function(req,res){
Map.findOne( {"name": req.params.name} ,function(err,result){
res.set('Content-Type','application/json');
res.status(200).send(result);
});
}) ;
app.get('/all/maps',function(req,res){
Map.find( {} , {"name":1, "description":2, "_id":0 },function(err,result){
res.set('Content-Type','application/json');
res.status(200).send(result);
});
}) ;
app.get('/',function(req,res){
res.render('index');
});
var port= 8001;
app.listen(port);
console.log('Server is running.......');