-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0806.js
76 lines (64 loc) · 1.42 KB
/
0806.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
var fs=require('fs');
var express=require('express');
var bodyParser=require('body-parser');
var DummyDB=(function(){
var DummyDB={};
var storage=[2];
var count=1;
DummyDB.get=function(id){
console.log("db come"+id)
if(id){
//id=(typeof id =='string')?Number(id):id;
for(var i in storage) if(storage[i].id==id){
console.log(i+"i를 뽑음");
return storage[i];
}
}else{
return storage;
}
}
DummyDB.insert=function(data){
console.log("dummy insert)")
data.id=count++;
storage.push(data);
return data;
};
DummyDB.remove=function(id){
//id=(typeof id='string')?Number(id):id;
for(var i in storage) if(storage[i].id==id){
storage.splice(i,1);
return true;
}
return false;
};
return DummyDB;
})();
var app=express();
app.use(bodyParser.urlencoded({
extended:false
}));
app.get('/user', function(request,response){
response.send(DummyDB.get());
});
app.get('user/:id',function(request,response){
console.log("조회 : "+request.param.id)
response.send(DummyDB.get(request.param.id));
})
app.post('/user',function(request,response){
console.log("post")
var name=request.body.name;
var region=request.body.region;
console.log(name+","+region);
if(name&®ion){
response.send(DummyDB.insert({
name:name,
region:region
}));
}
})
app.put('/user/:id',function(request,response){
})
app.delete('/user/:id' ,function(request,response){
})
app.listen(52273,function(){
})