Moved express route uploads to own dir and file.

parent 1c711aad
......@@ -22,7 +22,6 @@ const express = require('@feathersjs/express')
const primus = require('@feathersjs/primus')
const auth = require('@feathersjs/authentication')
const jwt = require('@feathersjs/authentication-jwt')
const jsonWebToken = require('jsonwebtoken')
const middleware = require('./middleware')
const services = require('./services')
......@@ -68,6 +67,13 @@ app.configure(jwt({
audience: 'hallo.gent'
}))
// Expose dataDirectoryPath to requests and feathers services
app.use((req, res, next) => {
req.dataDirectoryPath = dataDirectoryPath
req.feathers.dataDirectoryPath = dataDirectoryPath
next()
})
// Setup a hook to only allow valid JWTs to authenticate
// and get new JWT access tokens
app.service('authentication').hooks({
......@@ -78,33 +84,8 @@ app.service('authentication').hooks({
}
})
app.get('/uploads/:domain/:id',
// authenticate request with JSONWebToken
// optional
// function (req, res, next) {
// jsonWebToken.verify(req.headers.authorization, secretFile.secret, err => {
// if (err) {
// res.status(401).end()
// } else {
// next()
// }
// })
// },
// fetch file and return
function (req, res) {
res.sendFile(`${req.params.domain}/${req.params.id}`, {root: `${dataDirectoryPath}/uploads/`}, err => {
if (err) {
res.status(err.status).end()
}
})
})
// expose dataDirectoryPath to requests and feathers services
app.use((req, res, next) => {
req.dataDirectoryPath = dataDirectoryPath
req.feathers.dataDirectoryPath = dataDirectoryPath
next()
})
// Add express routes
app.use('/uploads', require('./routes/uploads'))
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware)
......
const express = require('express')
const router = express.Router()
// const jsonWebToken = require('jsonwebtoken')
router.get('/:domain/:id',
// authenticate request with JSONWebToken
// optional
// function (req, res, next) {
// jsonWebToken.verify(req.headers.authorization, secretFile.secret, err => {
// if (err) {
// res.status(401).end()
// } else {
// next()
// }
// })
// },
// fetch file and return
function (req, res) {
console.log('mkqsdf')
res.sendFile(`${req.params.domain}/${req.params.id}`, {root: `${req.dataDirectoryPath}/uploads/`}, err => {
if (err) {
console.log(req.dataDirectoryPath)
res.status(err.status).end()
}
})
})
module.exports = router
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment