Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
77 lines (65 loc) · 2.73 KB
/
Copy pathserver.js
File metadata and controls
77 lines (65 loc) · 2.73 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
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
#!/usr/bin/env node
/*
* iumix
* Copyright (C) 2026 uiloops
* License: GNU AGPL v3 or later. See LICENSE for details.
*/
const express = require("express");
const app = new express();
const stream = require('./ytstream');
const cors = require('cors');
const PORT = process.env.PORT || 5000;
// Bind to localhost by default: this app is meant to sit behind a reverse
// proxy (Apache/nginx) that terminates TLS and forwards to it, so it
// shouldn't be reachable directly from outside the host. Override with
// HOST=0.0.0.0 if you really need it exposed directly.
const HOST = process.env.HOST || '127.0.0.1';
const VisitCounter = require('./modules/visitCounter');
// Hidden, cookie-free page view counter. No per-visitor data is stored, so
// no cookie-consent banner is needed for this.
const visits = new VisitCounter();
app.use(cors());
const uri = "https://www.youtube.com/watch?v=";
// added async
app.use(async function(req, res, next) {
res.setHeader("Content-Security-Policy", "script-src 'self' 'unsafe-inline' https://apis.google.com");
return next();
});
// Count homepage loads before the static middleware serves the file.
// Note: app.get() matches these paths exactly, unlike app.use('/', ...)
// which would match (and over-count) every request as a path prefix.
app.get(['/', '/index.html'], visits.middleware());
/* Serve website folder */
app.use(express.static(__dirname + '/'));
//app.use(express.static('/styles',__dirname + '/styles'));
app.get("/audio1", (req, res) => {
let songId = req.query.songId; //CDO
//var songId = "t1TcDHrkQYg";
console.log('YTat1='+songId);
console.log("and the holder is of type: " + typeof(uri.concat(songId)));
if (typeof songId === 'string' || songId instanceof String){
stream(uri.concat(songId)).pipe(res);}
else{
console.log('song id not a string')
}
//stream('https://soundcloud.com/feindrehstar/afrikatour_interview_mdr)
//Create binding for aubio on node.js
//should be in argument? ex: ?time-track
//Create JSON response.
});
app.get("/audio2", (req, res) => {
let songId = req.query.songId;
console.log('YTat2='+songId);
let thisVar = uri.concat(songId);
console.log("and the holder is of type: " + typeof(thisVar));
if (typeof songId === 'string' || songId instanceof String){
stream(uri.concat(songId)).pipe(res);}
else{
console.log('song id not a string')
}
});
// Private, token-gated endpoint to read the hidden counter yourself, e.g.
// GET /admin/visits?token=<VISIT_COUNTER_TOKEN>. Returns 404 (as if it
// doesn't exist) unless VISIT_COUNTER_TOKEN is set and matches.
app.use('/admin/visits', visits.router({ requireToken: process.env.VISIT_COUNTER_TOKEN }));
app.listen(PORT, HOST, () => console.log(`Ready! Listening on http://${HOST}:${PORT}`));