|
|
|
@ -84,7 +84,14 @@ const SetupApp = (app: any, knex: Knex, apiBaseUrl: string) => { |
|
|
|
|
return invokeHandler(handler, knex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const checkLogin = require('connect-ensure-login').ensureLoggedIn; |
|
|
|
|
const checkLogin = () => { |
|
|
|
|
return function (req: any, res: any, next: any) { |
|
|
|
|
if (!req.isAuthenticated || !req.isAuthenticated()) { |
|
|
|
|
return res.status(401).send(); |
|
|
|
|
} |
|
|
|
|
next(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set up REST API endpoints
|
|
|
|
|
app.post(apiBaseUrl + api.CreateSongEndpoint, checkLogin(), _invoke(CreateSongEndpointHandler)); |
|
|
|
@ -103,7 +110,12 @@ const SetupApp = (app: any, knex: Knex, apiBaseUrl: string) => { |
|
|
|
|
app.delete(apiBaseUrl + api.DeleteTagEndpoint, checkLogin(), _invoke(DeleteTagEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.MergeTagEndpoint, checkLogin(), _invoke(MergeTagEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.RegisterUserEndpoint, _invoke(RegisterUserEndpointHandler)); |
|
|
|
|
|
|
|
|
|
app.post('/login', passport.authenticate('local'), (req: any, res: any) => { res.status(200).send(); }); |
|
|
|
|
app.post('/logout', function (req: any, res: any) { |
|
|
|
|
req.logout(); |
|
|
|
|
res.status(200).send(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export { SetupApp } |