-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serve static pages from app.yaml #6974
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Two important comments!
Codecov Report
@@ Coverage Diff @@
## develop #6974 +/- ##
===========================================
- Coverage 97.54% 97.52% -0.03%
===========================================
Files 379 379
Lines 63366 63354 -12
===========================================
- Hits 61809 61783 -26
- Misses 1557 1571 +14
Continue to review full report at Codecov.
|
Hi @Jamesjay4199. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just one question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of things, happy to approve after that.
core/controllers/base.py
Outdated
|
||
path = os.path.join( | ||
feconf.FRONTEND_TEMPLATES_DIR, filepath) | ||
self.response.write(template.render(path, None)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering ... what does template.render do? Does it have any unnecessary overhead? Is there a reference link you can point to that says "this is the preferred way to serve static files"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is "the preferred way" to serve static files, but this is what was in the documentation and I expect that since it comes bundled with webapp, then it should have been optimized for the purpose.
https://webapp2.readthedocs.io/en/latest/tutorials/gettingstarted/templates.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template.render is similar to rendering with jinja, but it uses Django templating instead, so I'm not sure it's what you want to do here if your aim is to serve the files statically.
If you do want to serve a file statically, then typically that is done in app.yaml -- see https://cloud.google.com/appengine/docs/standard/python/config/appref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(You might also want to try the three ways -- jinja render, django template.render, and app.yaml static rendering -- and compare their times.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app.yaml - 42ms
Jinja render - 147ms
template.render - 119ms
So we should go with app.yaml, but how about the headers?
You can specify http_headers in app.yaml, look at the documentation.
…On Sunday, June 23, 2019, James James ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In core/controllers/base.py
<#6974 (comment)>:
> + def render_static_template(self, filepath, iframe_restriction='DENY'):
+ """Prepares a Jinja-less HTML response to be sent to the client.
+ Args:
+ filepath: str. The template filepath.
+ iframe_restriction: str or None. Possible values are
+ 'DENY' and 'SAMEORIGIN':
+
+ DENY: Strictly prevents the template to load in an iframe.
+ SAMEORIGIN: The template can only be displayed in a frame
+ on the same origin as the page itself.
+ """
+ self.prepare_headers(iframe_restriction)
+
+ path = os.path.join(
+ feconf.FRONTEND_TEMPLATES_DIR, filepath)
+ self.response.write(template.render(path, None))
app.yaml - 42ms
Jinja render - 147ms
template.render - 119ms
So we should go with app.yaml, but how about the headers?
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#6974?email_source=notifications&email_token=ACQV5SR23YTWSKHGZLUBVB3P35UH3A5CNFSM4HZH3WT2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB4LHMVY#discussion_r296479115>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACQV5SQGMKKDUHASAV3TBVDP35UH3ANCNFSM4HZH3WTQ>
.
|
@seanlip, while implementing this, I noticed that it wouldn't work well for the other variants of splash page. |
Can you be more descriptive about what "wouldn't work well" means? Otherwise it is hard to offer advice. For X-Frame-Options, I think it's usually DENY except for the exploration pages. Is that correct? If so you can just go with that... |
Other splash pages like splash_at0 and splash_at1 |
I'll just render them individually |
Yep, sg. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Jamesjay4199, are there e2e tests for each of these pages? If so, could you please point me to them? I think we should add a note in build.py or app.yaml to say that each of these pages needs to be tested in an e2e test, too (in case future devs add stuff).
@@ -93,6 +93,27 @@ describe('Oppia static pages tour', function() { | |||
waitFor.pageToFullyLoad(); | |||
}); | |||
|
|||
it('visits the Get started page', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanlip, the tests are here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you assert for something that should exist in the page (to make sure it's not serving a 404)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
scripts/start.sh
Outdated
@@ -89,10 +89,12 @@ if [[ "$FORCE_PROD_MODE" == "True" ]]; then | |||
constants_env_variable="\"DEV_MODE\": false" | |||
sed -i.bak -e s/"\"DEV_MODE\": .*"/"$constants_env_variable"/ assets/constants.js | |||
$PYTHON_CMD scripts/build.py --prod_env --enable_watcher | |||
APP_YAML="app.yaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APP_YAML_FILEPATH, here and elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -93,6 +93,27 @@ describe('Oppia static pages tour', function() { | |||
waitFor.pageToFullyLoad(); | |||
}); | |||
|
|||
it('visits the Get started page', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you assert for something that should exist in the page (to make sure it's not serving a 404)?
@@ -111,7 +111,12 @@ | |||
'third_party/generated/js/third_party.min.js.map', | |||
'third_party/generated/webfonts/*', | |||
'*.bundle.js', | |||
'*.bundle.js.map') | |||
'*.bundle.js.map', | |||
'*/dist/get-started-page.mainpage.html', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the comment to explain why these files are present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
app.yaml
Outdated
@@ -2,9 +2,6 @@ runtime: python27 | |||
api_version: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our discussion, let's just have one app.yaml file in the codebase so that there's a single source of truth.
@vojtechjelinek FYI we discussed having a template file from which to generate dev/prod, but then we figured that it would be better to just have the "dev" version in the codebase (as we do now) and then do the changes needed to transform it to the "prod" version (like we do with other files/folders). This means that we only have one indirectly-generated file rather than two (which is better, since indirect pipelines like this often lead to errors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanlip, should this file still be in the codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanlip PTAL. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me. I think just removing the app.yaml file suffices. Tganks!
Done |
@Jamesjay4199 Don't forget to revert changes in package-lock.json if they are not intentional. @apb7 PTAL as codeowner, thanks! |
Also @Jamesjay4199 please note that the lint and an e2e test is failing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from code owner's perspective. Thanks!
@seanlip, I think this is ready to be merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks good. Thanks!
Explanation
Following the work on the static pages, this PR creates a new render_static_template method to serve the jinja-less templates
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.