-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (31 loc) · 1 KB
/
Copy pathserver.js
File metadata and controls
33 lines (31 loc) · 1 KB
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
var http = require('http'),
filed = require('filed'),
url = require('url'),
request = require('request');
server = http.createServer(function(req, resp){
var pathname = url.parse(req.url).pathname;
if (pathname === '/') pathname = '/index.html';
if (pathname === '/contact' && req.method === 'POST') {
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
console.log(body);
request.post('http://codecamp:rocks@chscodesq.herokuapp.com/contact', { json: true, body: body }, function(e,r,b){
console.log(b);
resp.writeHead(200, {'Content-Type': 'application/json'});
resp.end(JSON.stringify(b));
});
});
// req.pipe(
// request.post('http://codecamp:rocks@chscodesq.herokuapp.com/contact')
// ).pipe(resp);
} else {
filed(__dirname + "/gen" + pathname).pipe(resp);
}
});
server.listen(3000, function() {
console.log('Listening on Port 3000...');
console.log('CTRL-C to quit');
})