You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
"use strict" ;
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . uniTimestampMiddleware = void 0 ;
const url _1 = require ( "url" ) ;
const path _1 = _ _importDefault ( require ( "path" ) ) ;
const uni _cli _shared _1 = require ( "@dcloudio/uni-cli-shared" ) ;
function uniTimestampMiddleware ( server ) {
return async function timestampMiddleware ( req , _ , next ) {
// 当页面被作为组件引用时, 会导致history刷新该页面直接显示js代码, 因为该页面已被缓存为了module,
// https://github.com/vitejs/vite/blob/702d50315535c189151c67d33e4a22124f926bed/packages/vite/src/node/server/transformRequest.ts#L52
// /pages/tabBar/API/API
let { url } = req ;
if ( url ) {
const base = server . config . base ;
const parsed = ( 0 , url _1 . parse ) ( url ) ;
let newUrl = url ;
if ( ( parsed . pathname || '/' ) . startsWith ( base ) ) {
newUrl = newUrl . replace ( base , '/' ) ;
}
if ( ! path _1 . default . extname ( newUrl ) &&
! newUrl . endsWith ( '/' ) &&
! newUrl . includes ( '?' ) ) {
const module = await server . moduleGraph . getModuleByUrl ( newUrl ) ;
if ( module && module . file && uni _cli _shared _1 . EXTNAME _VUE _RE . test ( module . file ) ) {
// /pages/tabBar/API/API => /pages/tabBar/API/API?__t__=time
req . url = url + '?__t__=' + Date . now ( ) ;
}
}
}
next ( ) ;
} ;
}
exports . uniTimestampMiddleware = uniTimestampMiddleware ;