Skip to content

Commit

Permalink
1008 #14 後端完成,再來是說明
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulipuli Chen committed Oct 7, 2019
1 parent 34aa53f commit 8cfdfa1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
28 changes: 23 additions & 5 deletions app/Helpers/RefererPathFilter.js
@@ -1,7 +1,25 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
'use strict'

const Config = use('Config')
let directoryIndexMapping = Config.get('referer.directoryIndexMapping')

let RefererPathFilter = function (referer) {

if (typeof(referer) !== 'string') {
return '/'
}

let refererPath = '/' + referer.split('/').slice(3).join('/')

for (let i = 0; i < directoryIndexMapping.length; i++) {
let needle = directoryIndexMapping[i]
if (refererPath.startsWith(needle) === true) {
refererPath = '/' + refererPath.slice(needle.length)
break
}
}

return refererPath
}

module.exports = RefererPathFilter
3 changes: 0 additions & 3 deletions app/Middleware/OriginParser.js
@@ -1,8 +1,5 @@
'use strict'

const Config = use('Config')
let mapping = Config.get('origin.originMapping')

const OriginFilter = use('App/Helpers/OriginFilter')

class OriginParser {
Expand Down
21 changes: 2 additions & 19 deletions app/Middleware/RefererPathParser.js
@@ -1,7 +1,6 @@
'use strict'

const Config = use('Config')
let directoryIndexMapping = Config.get('referer.directoryIndexMapping')
const RefererPathFilter = use('App/Helpers/RefererPathFilter')

class RefererPathParser {
async handle (data, next) {
Expand All @@ -12,23 +11,7 @@ class RefererPathParser {
referer = headers.origin
}

if (typeof(referer) !== 'string') {
data.refererPath = '/'
await next()
return
}

let refererPath = '/' + referer.split('/').slice(3).join('/')

for (let i = 0; i < directoryIndexMapping.length; i++) {
let needle = directoryIndexMapping[i]
if (refererPath.startsWith(needle) === true) {
refererPath = '/' + refererPath.slice(needle.length)
break
}
}

data.refererPath = refererPath
data.refererPath = RefererPathFilter(referer)
await next()
}
}
Expand Down

0 comments on commit 8cfdfa1

Please sign in to comment.