-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (60 loc) · 1.72 KB
/
app.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
// Require the express library:
var express = require('express');
// Create an app:
var app = express();
// This shows you how to use "middleware" to provide additional
// functionality. This middleware allows files to be served
// statically:
app.use(express.static(__dirname + '/public'));
// What happens if the app gets a request that it does not understand?
// We match anything and return a response:
app.get('*', function (req, res) {
res.status(404).send('Sorry. I do not understand you!\n');
});
// Start the server:
var server = app.listen(3000, function () {
console.log('Listening on port %d', server.address().port);
});
/*
var Hapi = require('hapi');
var fs = require('fs');
var request = require('request');
var server = new Hapi.Server('0.0.0.0', process.env.PORT || 8000, {
"payload": {
"maxBytes": 104857600 //Increasing max file size to 1MB
}
});
server.route({
method: 'GET',
path: '/',
handler: function(req, reply) {
reply.file('view.html');
}
});
server.route({
method: 'GET',
path: '/watch',
handler: function(req, reply) {
if (req.query.v) {
var stream = fs.createWriteStream(req.query.v + '.mp3');
stream.on('close', function() {
reply("finished downloading mp3");
});
request('http://YouTubeInMP3.com/fetch/?video=http://www.youtube.com/watch?v=' + req.query.v).pipe(stream);
}
}
});
server.route({
method: "GET",
path: "/public/{path*}", //exposes public directory to public
handler: {
directory: {
path: "./public",
listing: false,
index: false
}
}
});
server.start();
console.log('Server started on localhost:8000');
*/