-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.js
60 lines (49 loc) · 1.54 KB
/
example.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
var express = require('express');
var fs = require('fs');
var mongodb = require('mongodb');
var server = new mongodb.Db('test', new mongodb.Server("127.0.0.1", 27017, {}));
var app = express.createServer();
app.get('/foobar', function(req,res){
res.contentType("text");
res.send( "Hi Elsbeth!" );
});
app.get('/static/js/jquery.js', function(req,res){
res.contentType("javascript");
fs.readFile( "templates/jquery.js", function(err,data){
res.send( data );
});
});
server.open(function(err, client) {
var collection = new mongodb.Collection(client,"tiled_ways");
var compcoll = new mongodb.Collection(client,"simple_tiles");
var profilecoll = new mongodb.Collection(client,"profiles");
app.get('/tile/*', function(req,res) {
res.contentType("json");
var cursor = collection.find({_id:req.params[0]}).limit(1);
cursor.nextObject( function(err,doc){
res.send( doc );
});
});
app.get('/comptile/*', function(req,res) {
res.contentType("json");
var cursor = compcoll.find({_id:req.params[0]}).limit(1);
cursor.nextObject( function(err,doc) {
res.send( doc );
});
});
app.get('/profile/*', function(req,res) {
res.contentType("json");
var cursor = profilecoll.find({id:req.params[0]}).limit(1);
cursor.nextObject( function(err,doc) {
res.send( doc );
});
});
});
app.get('/', function(req, res){
console.log( req.method, req.url );
res.contentType("html");
fs.readFile("templates/game.html", function(err,data){
res.send( data );
});
});
app.listen(80);