ایپلی کیشنز کو اکثر متحرک درخواستوں کو سنبھالنے کے علاوہ جامد فائلوں جیسے JavaScript، تصاویر اور CSS کو پیش کرنے کی ضرورت ہوتی ہے۔ معیاری ماحول میں ایپس Cloud Storage جیسے گوگل کلاؤڈ آپشن سے جامد فائلیں پیش کر سکتی ہیں، انہیں براہ راست پیش کر سکتی ہیں، یا فریق ثالث کے مواد کی ترسیل کے نیٹ ورک (CDN) کا استعمال کر سکتی ہیں۔ گوگل کلاؤڈ پر آپ کی جامد سائٹ کی میزبانی روایتی ہوسٹنگ کے استعمال سے کم خرچ ہو سکتی ہے۔ فراہم کنندہ، جیسا کہ گوگل کلاؤڈ مفت درجے فراہم کرتا ہے۔
## کلاؤڈ اسٹوریج سے فائلیں پیش کرنا
Cloud Storage متحرک ویب ایپس کے لیے جامد اثاثوں کی میزبانی کر سکتا ہے۔ اپنی ایپ سے براہ راست خدمت کرنے کے بجائے کلاؤڈ اسٹوریج استعمال کرنے کے فوائد میں شامل ہیں:
- کلاؤڈ اسٹوریج بنیادی طور پر مواد کی ترسیل کے نیٹ ورک کے طور پر کام کرتا ہے۔ اس کے لیے کسی خاص ترتیب کی ضرورت نہیں ہے کیونکہ بطور ڈیفالٹ کوئی بھی پڑھنے کے قابل آبجیکٹ کو عالمی کلاؤڈ اسٹوریج نیٹ ورک میں محفوظ کیا جاتا ہے۔
- Cloud Storage میں پیش کرنے والے جامد اثاثوں کو آف لوڈ کرنے سے آپ کی ایپ کا بوجھ کم ہو جائے گا۔ اس بات پر منحصر ہے کہ آپ کے پاس کتنے جامد اثاثے ہیں اور رسائی کی فریکوئنسی، یہ آپ کے ایپ کو چلانے کی لاگت کو ایک قابل ذکر رقم سے کم کر سکتا ہے۔
- مواد تک رسائی کے لیے بینڈوتھ چارجز اکثر کلاؤڈ اسٹوریج کے ساتھ کم ہو سکتے ہیں۔
آپ اپنے اثاثوں کو کلاؤڈ اسٹوریج پر اپ لوڈ کر سکتے ہیں۔
gsutil کمانڈ لائن ٹول
یا Cloud Storage API
گوگل کلاؤڈ کلائنٹ لائبریری Cloud Storage کو ایک محاوراتی Go 1.11 کلائنٹ فراہم کرتی ہے، ایک App Engine ایپ میں Cloud Storage کے ساتھ ڈیٹا کو ذخیرہ کرنے اور بازیافت کرنے کے لیے
کلاؤڈ اسٹوریج بالٹی سے سرونگ کی مثال
یہ سادہ مثال کلاؤڈ اسٹوریج بالٹی بناتی ہے اور گوگل کلاؤڈ CLI کا استعمال کرتے ہوئے جامد اثاثے اپ لوڈ کرتی ہے:
ایک بالٹی بنائیں۔ اپنی بالٹی کا نام اپنے پروجیکٹ ID کے بعد رکھنا عام ہے، لیکن اس کی ضرورت نہیں ہے۔ بالٹی کا نام عالمی سطح پر منفرد ہونا چاہیے۔
gsutil mb gsyour-bucket-name>بالٹی میں آئٹمز تک پڑھنے کی رسائی دینے کے لیے ACL کو سیٹ کریں۔
gsutil defacl عوامی پڑھا ہوا gsyour-bucket-name>سیٹ کریں۔
اشیاء کو بالٹی میں اپ لوڈ کریں۔ دی
rsynccommand عام طور پر اثاثوں کو اپ لوڈ اور اپ ڈیٹ کرنے کا تیز ترین اور آسان طریقہ ہے۔ آپ بھی استعمال کر سکتے ہیں۔
cp
gsutil -m rsync -r ./static gsyour-bucket-name>/static
اب آپ اپنے جامد اثاثوں تک رسائی حاصل کر سکتے ہیں۔
httpsstorage.googleapis.com//static
For more details on how to use Cloud Storage to serve static assets, including how to serve from a custom domain name, refer to How to Host a Static Website
Serving files from other Google Cloud services
You also have the option of using Cloud CDN or other Google Cloud storage services
## Serving files directly from your app
To serve static files for Go 1.11 in the standard environment,
you define the handlers in your
app.yaml file using either the
static_dir
or
static_files
elements
The content in the static files or static directories are unaffected
by the scaling settings in your
app.yaml file. Requests to static files or
static directories are handled by the App Engine infrastructure
directly, and do not reach the language runtime of the application
Configuring your static file handlers
To configure your app to serve the
./public directory from the
/static URL,
you define a handler in your
app.yaml file
The following demonstrates how to serve the static files of a sample
app's
./public directory. The template for this app's
index.html page
instructs the browser to load the
main.css file, for example:
/css/main.css">
The
./public directory is defined in the
static_dir element of the project's
app.yaml file:
handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: /static static_dir: public - url:secure: always redirect_http_response_code: 301 script: auto
The
handlers section in the above example handles three URL patterns:
The
/favicon.icohandler maps a request specifically for
/favicon.icoto a file named
favicon.icoin the app's root directory
The
/statichandler maps requests for URLs that start with
/static. When App Engine receives a request for a URL beginning with
/static, it maps the remainder of the path to files in the
./publicdirectory. If an appropriate file is found in the directory, the contents of that file are returned to the client
The
handler matches all other URLs and directs them to your app
URL path patterns are tested in the order they appear in
app.yaml, therefore
the pattern for your static files should be defined before the
pattern
For more information, see the
app.yaml
reference
## Serving from a third-party content delivery network
You can use any external third-party CDN to serve your static files and cache dynamic requests but your app might experience increased latency and cost
For improved performance, you should use a third-party CDN that supports CDN Interconnect.