mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 04:54:23 +00:00
some more progress on backend integration
This commit is contained in:
@@ -6,6 +6,9 @@ const fs = require( 'fs' );
|
||||
const bodyParser = require( 'body-parser' );
|
||||
const cookieParser = require( 'cookie-parser' )
|
||||
const favicon = require( 'serve-favicon' );
|
||||
const static = require( 'express-static' );
|
||||
|
||||
const authKey = '' + fs.readFileSync( path.join( __dirname + '/authorizationKey.txt' ) );
|
||||
|
||||
app.use( expressSession ( {
|
||||
secret: 'akgfsdkgfösdolfgslöodfvolwseifvoiwefö',
|
||||
@@ -16,16 +19,33 @@ app.use( bodyParser.urlencoded( { extended: false } ) );
|
||||
app.use( bodyParser.json() );
|
||||
app.use( cookieParser() );
|
||||
app.use( favicon( path.join( __dirname + '' ) ) );
|
||||
app.use( static() );
|
||||
|
||||
|
||||
app.post( '/connect', ( request, response ) => {
|
||||
if ( request.session.authorized ) {
|
||||
response.send( 'Already authenticated' );
|
||||
} else {
|
||||
if ( request.body.authKey === authKey ) {
|
||||
request.session.authorized = true;
|
||||
response.send( 'Handshake OK' );
|
||||
} else {
|
||||
response.status( 403 ).send( 'AuthKey wrong' );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
app.post( '/statusUpdate/:update', ( req, res ) => {
|
||||
if ( req.session.authorized ) {
|
||||
res.send( 'thanks' );
|
||||
} else {
|
||||
res.status( 403 ).send( 'Unauthorized' );
|
||||
}
|
||||
} );
|
||||
|
||||
app.use( ( request, response, next ) => {
|
||||
response.sendFile( path.join( __dirname + '' ) )
|
||||
} );
|
||||
|
||||
|
||||
app.get( '/', ( request, response ) => {
|
||||
|
||||
} );
|
||||
|
||||
|
||||
const PORT = process.env.PORT || 8080;
|
||||
http.createServer( app ).listen( PORT );
|
||||
0
backend/authorizationKey.txt
Normal file
0
backend/authorizationKey.txt
Normal file
Reference in New Issue
Block a user