forked from mixi-inc/JavaScriptTraining
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
38 lines (27 loc) · 983 Bytes
/
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
'use strict';
var util = require('util');
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({extended: true, limit: '50mb' }));
var PUBLIC_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);
});
var friendMap = require('./server/response/friendsmap.json');
app.get('/api/friends/:username([\\w.-]+)', function(req, res) {
var username = req.params.username;
res.json(friendMap[username]);
});
var PORT = process.env.PORT;
var HOSTNAME = 'localhost';
var server = require('http').createServer(app);
server.listen(PORT, HOSTNAME, function () {
console.log('SERVER_READY');
console.log(util.format('http://%s:%d にブラウザでアクセスしてください'), HOSTNAME, PORT);
});