Fix dynamic route requests, add auth middleware

This commit is contained in:
advplyr
2021-08-23 19:37:40 -05:00
parent 7ef977b783
commit db2f2d6660
11 changed files with 29 additions and 25 deletions

View File

@ -42,7 +42,7 @@ class Auth {
const authHeader = req.headers['authorization']
const token = authHeader && authHeader.split(' ')[1]
if (token == null) {
Logger.error('Api called without a token')
Logger.error('Api called without a token', req.path)
return res.sendStatus(401)
}

View File

@ -106,8 +106,8 @@ class Server {
app.use(this.auth.cors)
// Static path to generated nuxt
const distPath = Path.join(global.appRoot, '/client/dist')
if (process.env.NODE_ENV === 'production') {
const distPath = Path.join(global.appRoot, '/client/dist')
app.use(express.static(distPath))
app.use('/local', express.static(this.AudiobookPath))
} else {
@ -119,14 +119,13 @@ class Server {
app.use(express.urlencoded({ extended: true }));
app.use(express.json())
// Dynamic routes are not generated on client
app.get('/audiobook/:id', (req, res) => res.sendFile(Path.join(distPath, 'index.html')))
app.use('/api', this.authMiddleware.bind(this), this.apiController.router)
app.use('/hls', this.authMiddleware.bind(this), this.hlsController.router)
app.use('/feeds', this.rssFeeds.router)
app.get('/', (req, res) => {
res.sendFile('/index.html')
})
app.post('/login', (req, res) => this.auth.login(req, res))
app.post('/logout', this.logout.bind(this))
app.get('/ping', (req, res) => {