1
1
import apicache from 'apicache'
2
+ import axios from 'axios'
2
3
import type { NextFunction , Request , Response } from 'express'
3
4
import express from 'express'
4
5
import { config } from '../../config'
43
44
. get (
44
45
cache ( '1 day' ) ,
45
46
async ( req : Request , res : Response , next : NextFunction ) => {
46
- let url
47
47
try {
48
48
const rawRequestParams = decodeURIComponent (
49
49
req . query . requestParams as string
@@ -62,28 +62,23 @@ router
62
62
63
63
const authorizedMethod = authorizedMethods . includes ( matomoMethod )
64
64
65
- const authorizedSiteId = requestParams . get ( 'idSite' ) === '153 '
65
+ const authorizedSiteId = requestParams . get ( 'idSite' ) === '20 '
66
66
67
67
if ( ! authorizedMethod || ! authorizedSiteId ) {
68
68
res . statusCode = 401
69
69
return next ( 'Error. Not Authorized' )
70
70
}
71
71
72
- url =
73
- config . thirdParty . matomo . url +
74
- '?' +
75
- requestParams +
76
- '&token_auth=' +
77
- config . thirdParty . matomo . token
78
-
79
72
console . log ( 'will make matomo request' , requestParams )
80
73
81
- const response = await fetch ( url )
82
-
83
- const json = ( await response . json ( ) ) as {
84
- label : string
85
- subtable : { url : string } [ ]
86
- } [ ]
74
+ const { data : json } = await axios . post <
75
+ {
76
+ label : string
77
+ subtable : { url : string } [ ]
78
+ } [ ]
79
+ > ( config . thirdParty . matomo . url + '?' + requestParams , {
80
+ token_auth : config . thirdParty . matomo . secureToken ,
81
+ } )
87
82
88
83
// Remove secret pages that would reveal groupe names that should stay private
89
84
if ( rawRequestParams . includes ( 'Page' ) ) {
0 commit comments