forked from mixi-inc/JavaScriptTraining
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
Latest commit
38 lines (27 loc) · 983 Bytes
/
Copy pathserver.js
File metadata and controls
38 lines (27 loc) · 983 Bytes
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
'use strict';
varutil=require('util');
varpath=require('path');
varexpress=require('express');
varbodyParser=require('body-parser');
varapp=express();
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({extended: true,limit: '50mb'}));
varPUBLIC_DIR=path.join(__dirname,'public');
app.use(express.static(PUBLIC_DIR));
app.get('/api/heavy',function(req,res){
setTimeout(function(){
res.send('// do nothing');
},1000);
});
varfriendMap=require('./server/response/friendsmap.json');
app.get('/api/friends/:username([\\w.-]+)',function(req,res){
varusername=req.params.username;
res.json(friendMap[username]);
});
varPORT=process.env.PORT;
varHOSTNAME='localhost';
varserver=require('http').createServer(app);
server.listen(PORT,HOSTNAME,function(){
console.log('SERVER_READY');
console.log(util.format('http://%s:%d にブラウザでアクセスしてください'),HOSTNAME,PORT);
});