LoginSignup
9
11

More than 5 years have passed since last update.

GAEを静的ファイル置き場にしてみた

Last updated at Posted at 2016-06-19

意外とGoogle Appengineを静的ファイルだけで構成する情報がなかったのでその備忘録

環境構築

Google App Engine SDKが必要なので以下を参考に
Download the Google App Engine SDK

構成

とりあえず、runtimeはpython
ディレクトリはシンプルなこんな感じで

static_sample
├── app.yaml
├── sample.html
└── style
    └── style.css

ソース

みんな大好きHELLO WORLD

sample.html
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="/style/style.css">
    </head>
    <body>
        <h1>HELLO WORLD!!</h1>
    </body>
</html>

とりあえず文字色を変更するだけ

style.css
h1 {
    color: red;
}

deployに必要な設定
「application」と書いてあるけど、設定値はproject IDなので注意
あと、uploadに「.sample.html」と書いてもローカルサーバでは動いちゃうけどdeployしたら動かないので注意
(そもそもそんな記述しないか…)

app.yaml
application: {project ID}
module: staticsample1
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /
  static_files: sample.html
  upload: sample.html

- url: /style
  static_dir: style

さあ動かそう!!!

ローカルサーバで確認

cd static_sample
dev_appserver.py .

http:localhost:8080でアクセスで確認

いよいよdeploy

cd satic_sample
appcfg.py update .

Developers ConsoleのApp Engineでdeployされてるか確認
以下のアドレスで確認
https://staticsample1-dot-{project ID}.appspot.com/
※「staticsample1」はmodule名

その他

cssファイルだけのサンプルだけどjsファイル、画像ファイルも同じ感じで動く
アップロードするファイルを正規表現で指定もできるけどそれはまた今度

9
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11