GAE:file_get_contents() 和静态文件
GAE: file_get_contents() and static files
我没有在不同位置更新同一个变量,而是解析文件并提取我需要的位。我正在寻找的一点是我的 service-worker.js 文件中的缓存名称。当我在本地开发时,我可以很容易地检索目录结构中的js文件。
当我将我的应用程序部署到 GAE 时,服务工作者 JS 文件需要声明为静态,因此 GAE 将其隐藏在某个地方。
有没有办法在不进行 URL 调用的情况下访问此文件?
这是我目前使用的,在 DEV 中一切正常:
<?php
function getCacheId() {
$cache_id = "";
$c = file_get_contents ( dirname ( __FILE__ ) . "/service-worker.js" );
if (preg_match ( "/CACHE_NAME = '(.*)'/", $c, $matches ) !== false) {
if (count ( $matches )) {
$cache_id = trim ( $matches[1] );
}
}
return $cache_id;
}
?>
<script>
const CACHEID = "<?php echo getCacheId() ?>";
</script>
除了 app.yaml
文件中的静态文件声明外,您还需要配置 application_readable: true
。
application_readable
Optional. Boolean. By default, files declared in static file handlers
are uploaded as static data and are only served to end users. They
cannot be read by an application. If this field is set to true, the
files are also uploaded as code data so your application can read
them. Both uploads are charged against your code and static data
storage resource quotas.
我没有在不同位置更新同一个变量,而是解析文件并提取我需要的位。我正在寻找的一点是我的 service-worker.js 文件中的缓存名称。当我在本地开发时,我可以很容易地检索目录结构中的js文件。
当我将我的应用程序部署到 GAE 时,服务工作者 JS 文件需要声明为静态,因此 GAE 将其隐藏在某个地方。
有没有办法在不进行 URL 调用的情况下访问此文件?
这是我目前使用的,在 DEV 中一切正常:
<?php
function getCacheId() {
$cache_id = "";
$c = file_get_contents ( dirname ( __FILE__ ) . "/service-worker.js" );
if (preg_match ( "/CACHE_NAME = '(.*)'/", $c, $matches ) !== false) {
if (count ( $matches )) {
$cache_id = trim ( $matches[1] );
}
}
return $cache_id;
}
?>
<script>
const CACHEID = "<?php echo getCacheId() ?>";
</script>
除了 app.yaml
文件中的静态文件声明外,您还需要配置 application_readable: true
。
application_readable
Optional. Boolean. By default, files declared in static file handlers are uploaded as static data and are only served to end users. They cannot be read by an application. If this field is set to true, the files are also uploaded as code data so your application can read them. Both uploads are charged against your code and static data storage resource quotas.