This commit is contained in:
janis
2022-10-30 16:24:23 +01:00
parent c0054df4f7
commit c99d9c4533
2 changed files with 141 additions and 0 deletions

93
nodeserver/server.js Normal file
View File

@@ -0,0 +1,93 @@
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const ip = require('ip')
// GET IP OF SYSTEM AND DISPLAY TO USER
console.log("\n\nThis PC's IP address: " + ip.address());
console.log("Use this IP address when connecting to this server from the player and display!")
// INITIALIZE VARIABLES
var app = express();
var playbackpos = "1"
var upcomingsongs = "Test\nTest2\nTest3"
var currentsong = "This is a song"
var songmaxlength = "100"
var fullscreen = "False"
// CONFIG FOR EXPRESS
app.use(bodyParser.urlencoded({extended : true}))
/////////////////
////// API //////
/////////////////
app.get('/tryconnect', (request, response) => {
console.log("connecting")
response.send("ok")
})
// Get data (Interface for Screen)
app.get('/playbackpos', (request, response) => {
response.send(playbackpos)
})
app.get('/upcomingsongs', (request, response) => {
response.send(upcomingsongs)
})
app.get('/songmaxlength', (request, response) => {
response.send(songmaxlength)
})
app.get('/currentsong', (request, response) => {
response.send(currentsong)
})
app.get('/fullscreen', (request, response) => {
response.send(fullscreen)
})
// POST data (Interface for Player)
app.post('/postplayback', (request, response) => {
playbackpos = request.body.pos
response.send("ok")
})
app.post('/postupcomingsogns', (request, response) => {
upcomingsongs = request.body.songs
response.send("ok")
})
app.post('/postcurrentsong', (request, response) => {
currentsong = request.body.songname
response.send("ok")
})
app.post('/postfullscreen', (request, response) => {
fullscreen = request.body.fullscreen
response.send("ok")
})
app.post('/postsonglength', (request, response) => {
songmaxlength = request.body.length
response.send("ok")
})
// Test functions
app.post('/testrequest', (request, response) => {
console.log("request received")
console.log(request.body)
response.send(request.body)
response.status(200)
})
// Create and run server
http.createServer(app).listen(8000, function () {
console.log("\n\n-------------------\n\n Server started\n\n-------------------\n")
})