GAE: file_get_contents() and static files

霸气de小男生 提交于 2019-12-29 09:33:09

问题


Instead of updating the same variable in various locations I parse files and extract the bits I need. One bit I am looking for is the cache name in my service-worker.js file. When I'm developing locally, I can easily retrieve the js file in the directory structure.

When I deploy my app to GAE, the service worker JS file needs to be declared static and so GAE stashes it away somewhere.

Is there a way to get to this file without making a URL call?

This is what I currently use and it's all working fine in 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>

回答1:


You need to also configure application_readable: true in addition to the static file declaration in your app.yaml file.

From Handlers element:

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.



来源:https://stackoverflow.com/questions/41414346/gae-file-get-contents-and-static-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!