Go Google app engine - can't find template files - google-app-engine

I using Gin framework.
At local development mode: goapp serve
all works fine.
func init() {
route := gin.Default()
route.LoadHTMLGlob("../*/views/**/*.html")
...
}
But after deploy:
panic: html/template: pattern matches no files: ../*/views/**/*.html
OK. I try:
func init() {
route := gin.Default()
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
route.LoadHTMLGlob(dir + "/../*/views/**/*.html")
...
}
Same result.
I try fetch dir:
...
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
...
}
c.String(http.StatusOK, "Dir: ", dir)
c.String(http.StatusOK, "\nOK")
res, err := filepath.Glob(dir + "/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v\n\n", res, err))
c.String(http.StatusOK, "Dirs:")
res, err = filepath.Glob(dir + "/**/*")
c.String(http.StatusOK, fmt.Sprintf("%v | %v", res, err))
...
Result:
Dir: %!(EXTRA string=/base/data/home/apps/tmp-LEIYJC/_ah)
OK[/base/data/home/apps/tmp-LEIYJC/_ah/exe] |
Dirs:[] |
Ooops. What I done wrong?
UPD:
app.yaml
runtime: go
api_version: go1
handlers:
- url: /images
static_dir: ../static/images
- url: /css
static_dir: ../static/css
- url: /js
static_dir: ../static/js
- url: /fonts
static_dir: ../static/fonts
- url: /.*
script: _go_app
I put app.yaml to subdirectory, cause without that another problem:
[https://groups.google.com/forum/#!topic/google-appengine-go/dNhqV6PBqVc
Folder structure:
app/
app.go
app.yaml
static/
...
frontend/
controllers/
UserController.go
...
models/
UserModel.go
...
views/
home/
*.html
user/
*.html
anotherfolder/
*.html
backend/
controllers/
MainController.go
...
models/
SomeModel.go
...
views/
main/
*.html
anotherfolder/
*.html
...

I found next solution.
I reorginize structure:
app/
static/
...
frontend/
views/
home/
*.html
user/
*.html
anotherfolder/
*.html
backend/
views/
main/
*.html
anotherfolder/
*.html
app.go
app.yaml
frontend/
controllers/
UserController.go
...
models/
UserModel.go
...
backend/
controllers/
MainController.go
...
models/
SomeModel.go
...
...
Change:
app.yaml
runtime: go
api_version: go1
handlers:
- url: /images
static_dir: static/images
- url: /css
static_dir: static/css
- url: /js
static_dir: static/js
- url: /fonts
static_dir: static/fonts
- url: /.*
script: _go_app
It's really strange ecision GAE. I can't put app.yaml to root directory for application because I got panic message for duplication import. And I can't put templates to root directory because that not under scope, only at directory parent to app.yaml

If I'm not mistaken all of your directories should live within the root directory where your app.yaml exists. So you would want something like this. Also, when you want your application to access a static file directory you need to add application_readable: true to that directories definition. See the next example down. Hope this helps.
app/
app.go
app.yaml
static/
...
frontend/views/
home/
*.html
anotherfolder/
*.html
Example Directory Definition:
- url: /s
static_dir: s/
application_readable: true

Related

why {app-url}/reset-password/{token} url showing page not found in react app deployed on google cloud where it working in local?

Token: {app-url}/reset-password/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTI3OTUxNjksInVzZXJJZCI6NjB9.YS1seObMs45hcTDH4nSbTNh1W4fTTqPcpF4TUamfFFk
Error: Error: Not Found
The requested URL /reset-password/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTI3OTUxNjksInVzZXJJZCI6NjB9.YS1seObMs45hcTDH4nSbTNh1W4fTTqPcpF4TUamfFFk was not found on this server.
Code:
<Route exact path="/reset-password/:token" component={ResetPassword} />
Does this issue bcs app deployed in GCloud or any thing needs to change in react code (project is create react app not webpack) ?
app.yaml
runtime: nodejs12
handlers:
- url: /(.*\..+)$
static_files: build/\1
upload: build/(.*\..+)$
- url: /.*
static_files: build/index.html
upload: build/index.html
Needs to change app.yaml
runtime: nodejs12
handlers:
- url: /static
static_dir: build/static
- url: /(.*\.(json|ico|js|png))$
static_files: build/\1
upload: build/.*\.(json|ico|js|png)$
- url: .*
static_files: build/index.html
upload: build/index.html
thanks to https://stackoverflow.com/a/55831186

Config Yaml for folders inside folders in App Engine

I have this app engine project structure:
and the this yaml file:
but only chicken.jpg will appear in index.html and not the images inside img/cats or img/puppys.
/img intercepts the others. Put your url handlers in this order:
- url: /img/puppys
static_dir: img/puppys
- url: /img/cats
static_dir: img/cats
- url: /img
static_dir: img

Google App Engine, Jinja2 CSS Stylesheets not loading (404)

Long time listener, first time caller.
I'm having some frustrating, seemingly inexplicable issues with Google App Engine, Jinja2, and CSS.
My templates are working, the functionality of my app works (users, blog posts, etc.), but the CSS file shows a big, fat 404 in my Chrome debugging tools and in my Google App Engine logs. Why isn't my /stylesheets/main.css loading?
Dear internet, I'd love to hear that this is just a typo. I'm sure that I'm just an idiot.
Here's my file directory:
stylesheets
main.css
templates
base.html
blog.html
front.html
login.html
newpost.html
signup.html
welcome.html
app.yaml
blogs.py
favicon.ico
index.yaml
main.py
users.py
utilities.py
Here's my YAML file:
application: hello-udacity-5681
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: main.app
- url: /stylesheets
static_dir: stylesheets
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
Here's my main.py:
import webapp2
import os
import jinja2
from google.appengine.ext import db
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)
class Handler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
class MainHandler(Handler):
def render_front(self):
self.render("base.html")
def get(self):
self.render_front()
Here's my base.html:
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css"/>
<title>Blog</title>
</head>
<body>
Blog
</body>
</html>
I ran my main.css through http://jigsaw.w3.org/css-validator/ without any issues, so I won't bore you with that.
Why am I still getting a 404 for my /stylesheets/main.css ?
Your app.yaml handler section should be like this
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: main.app
In this case, the /stylesheets pattern will match before the /.* pattern will for the appropriate paths. For more information on URL mapping and other options you can specify in app.yaml, see the app.yaml reference.

How to configure the app.yaml for using images?

i have a big problem with images for my project with python (appspots.com).
How to configure the app.yaml for images?
My Images are in the directory /css/images/xy.png
The log say:
INFO 2012-04-22 17:29:42,601 dev_appserver.py:2884] "GET
/css/images/ui-bg_glass_75_e6e6e6_1x400.png HTTP/1.1" 404 -
My app.yaml (only handlers):
- url: /js
static_dir: js
- url: /css/main.css
static_files: css/main.css
upload: css/main.css
- url: /css/jquery-ui-1.8.19.custom.css
static_files: css/jquery-ui-1.8.19.custom.css
upload: css/jquery-ui-1.8.19.custom.css
- url: .*
script: main.py
- url: /css/images/.*
static_dir: css/images
I hope that you can help me :)
The problem is that you have .* before /css/images./* and that pattern matches everything. Rearrange it like this:
- url: /js
static_dir: js
- url: /css/main.css
static_files: css/main.css
upload: css/main.css
- url: /css/jquery-ui-1.8.19.custom.css
static_files: css/jquery-ui-1.8.19.custom.css
upload: css/jquery-ui-1.8.19.custom.css
- url: /css/images
static_dir: css/images
- url: .*
script: main.py
EDIT:
Try removing the /.* from the end of the pattern, as illustrated above.

How should I write my Google App Engine app.yaml file?

I registered a Google App Engine app and I have some files below:
/index.html
/css/index.css
/js/index.js
/feedbacks/index.html
/feedbacks/css/index.css
/feedbacks/js/index.js
How should I write the app.yaml file?
Thank you!
application: appname
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon.ico
static_files: img/favicon.ico
upload: img/favicon.ico
mime_type: image/x-icon
- url: /css #your css folder
static_dir: css
- url: /scripts #your javascript folder
static_dir: scripts
- url: /img #your image folder
static_dir: img
- url: /.*
script: your_script.py
Put your first 3 files into a folder name "static"
handlers:
- url: /feedbacks/
static_dir: feedbacks
- url: /css/
static_dir: static
- url: /js/
static_dir: static
- url: /.*
script: main.py
In your main.py
class IndexHandler(webapp.RequestHandler):
def get(self):
self.redirect('static/index.html')
def main():
application = webapp.WSGIApplication([
('/index.html', IndexHandler),
], debug=True)
run_wsgi_app(application)
It's not good to write in this way,
but this will solve your problem.

Resources