|
|
|
@ -60,46 +60,50 @@ const SetupApp = (app: any, knex: Knex, apiBaseUrl: string) => { |
|
|
|
|
} catch (error) { cb(error); } |
|
|
|
|
})(); |
|
|
|
|
})); |
|
|
|
|
// passport.serializeUser(function (user: any, cb: any) {
|
|
|
|
|
// cb(null, user.id);
|
|
|
|
|
// });
|
|
|
|
|
// passport.deserializeUser(function (id: number, cb: any) {
|
|
|
|
|
// (async () => {
|
|
|
|
|
// try {
|
|
|
|
|
// const user = await knex.select(['email', 'passwordHash', 'id'])
|
|
|
|
|
// .from('users')
|
|
|
|
|
// .where({ 'id': id })
|
|
|
|
|
// .then((users: any) => users[0]);
|
|
|
|
|
// if (!user) { cb(null, false); }
|
|
|
|
|
// return cb(null, user);
|
|
|
|
|
// } catch (error) { cb(error); }
|
|
|
|
|
// })();
|
|
|
|
|
// });
|
|
|
|
|
passport.serializeUser(function (user: any, cb: any) { |
|
|
|
|
cb(null, user.id); |
|
|
|
|
}); |
|
|
|
|
passport.deserializeUser(function (id: number, cb: any) { |
|
|
|
|
(async () => { |
|
|
|
|
try { |
|
|
|
|
const user = await knex.select(['email', 'passwordHash', 'id']) |
|
|
|
|
.from('users') |
|
|
|
|
.where({ 'id': id }) |
|
|
|
|
.then((users: any) => users[0]); |
|
|
|
|
if (!user) { cb(null, false); } |
|
|
|
|
return cb(null, user); |
|
|
|
|
} catch (error) { cb(error); } |
|
|
|
|
})(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
app.use(require('express-session')({ secret: 'keyboard cat', resave: false, saveUninitialized: false })); |
|
|
|
|
app.use(passport.initialize()); |
|
|
|
|
//app.use(passport.session());
|
|
|
|
|
app.use(passport.session()); |
|
|
|
|
|
|
|
|
|
const _invoke = (handler: endpointTypes.EndpointHandler) => { |
|
|
|
|
return invokeHandler(handler, knex); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const checkLogin = require('connect-ensure-login').ensureLoggedIn; |
|
|
|
|
|
|
|
|
|
// Set up REST API endpoints
|
|
|
|
|
app.post(apiBaseUrl + api.CreateSongEndpoint, _invoke(CreateSongEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.QueryEndpoint, _invoke(QueryEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateArtistEndpoint, _invoke(CreateArtistEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifyArtistEndpoint, _invoke(ModifyArtistEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifySongEndpoint, _invoke(ModifySongEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.SongDetailsEndpoint, passport.authenticate('local', { session: false }), _invoke(SongDetailsEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.ArtistDetailsEndpoint, _invoke(ArtistDetailsEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateTagEndpoint, _invoke(CreateTagEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifyTagEndpoint, _invoke(ModifyTagEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.TagDetailsEndpoint, _invoke(TagDetailsEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateAlbumEndpoint, _invoke(CreateAlbumEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifyAlbumEndpoint, _invoke(ModifyAlbumEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.AlbumDetailsEndpoint, _invoke(AlbumDetailsEndpointHandler)); |
|
|
|
|
app.delete(apiBaseUrl + api.DeleteTagEndpoint, _invoke(DeleteTagEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.MergeTagEndpoint, _invoke(MergeTagEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateSongEndpoint, checkLogin(), _invoke(CreateSongEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.QueryEndpoint, checkLogin(), _invoke(QueryEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateArtistEndpoint, checkLogin(), _invoke(CreateArtistEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifyArtistEndpoint, checkLogin(), _invoke(ModifyArtistEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifySongEndpoint, checkLogin(), _invoke(ModifySongEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.SongDetailsEndpoint, checkLogin(), _invoke(SongDetailsEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.ArtistDetailsEndpoint, checkLogin(), _invoke(ArtistDetailsEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateTagEndpoint, checkLogin(), _invoke(CreateTagEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifyTagEndpoint, checkLogin(), _invoke(ModifyTagEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.TagDetailsEndpoint, checkLogin(), _invoke(TagDetailsEndpointHandler)); |
|
|
|
|
app.post(apiBaseUrl + api.CreateAlbumEndpoint, checkLogin(), _invoke(CreateAlbumEndpointHandler)); |
|
|
|
|
app.put(apiBaseUrl + api.ModifyAlbumEndpoint, checkLogin(), _invoke(ModifyAlbumEndpointHandler)); |
|
|
|
|
app.get(apiBaseUrl + api.AlbumDetailsEndpoint, checkLogin(), _invoke(AlbumDetailsEndpointHandler)); |
|
|
|
|
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(); }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export { SetupApp } |