-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
77 lines (77 loc) · 1.87 KB
/
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
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
77
var Hapi = require('hapi');
var fs = require('fs');
var ytdl = require('ytdl-core');
var ejs = require('ejs');
var Path = require('path');
var server = new Hapi.Server('0.0.0.0', process.env.PORT || 8000, {
"payload": {
"maxBytes": 104857600 //Increasing max file size to 1MB
}
});
/*
var server = new Hapi.Server();
server.connection( { port: 8000 } );
*/
server.views({
engines: {
ejs: ejs
},
path: Path.join(__dirname, 'views')
});
//NEW ROUTE
server.route({
method: 'GET',
path: '/old',
handler: function(req, reply) {
reply.view('view.ejs', {
video_id: '',
youtube: false
});
}
});
server.route({
method: 'GET',
path: '/',
handler: function(req, reply) {
reply.view('three.ejs', {
video_id: '',
youtube: false
});
}
});
server.route({
method: 'GET',
path: '/watch',
handler: function(req, reply) {
if (req.query.v) {
if (!req.query.download) {
var stream = fs.createWriteStream("public/" + req.query.v + '.mp4');
stream.on('close', function() {
reply.view('view.ejs', {
video_id: req.query.v,
youtube: true
});
});
ytdl('http://www.youtube.com/watch?v=' + req.query.v).pipe(stream);
} else {
reply.view('view.ejs', {
video_id: req.query.v,
youtube: true
});
}
}
}
});
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');