Why do I see non-parsed AngularJS expressions in the Nginx logs? - angularjs

I'm working on an Angular-based SPA using Nginx and HTTPD ; I recently realized that some non-parsed AngularJS expressions are being logged in the Nginx error log :
2016/03/24 10:47:53 [error] 63879#0: *2639 open() "/var/www/mysite/assets/css/png/{{ client.logo }}_bw.png" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: example.com, request: "GET /css/png/{{%20client.logo%20}}_bw.png HTTP/1.1", host: "www.example.com", referrer: "https://www.example.com/my-page"
2016/03/24 10:48:34 [error] 63879#0: *2789 open() "/var/www/mysite/assets/css/png/{{ src }}-small.png" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: example.com, request: "GET /css/png/{{%20src%20}}-small.png HTTP/1.1", host: "www.example.com", referrer: "https://www.example.com/"
2016/03/24 10:48:37 [error] 63879#0: *2813 open() "/var/www/mysite/assets/css/png/{{ src }}-small.png" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: example.com, request: "GET /assets/css/png/%7B%7B%20src%20%7D%7D-small.png HTTP/1.1", host: "www.example.com", referrer: "https://www.example.com/my-page"
On the website the expressions are correctly evaluated are the images shown normally, but there may be indeed a short processing time. How do I prevent Nginx from logging these expressions before they are evalutated ?

You need to use ng-src when displaying images in your application - otherwise the browser will fire off requests for the unparsed expression to the server.
Wrong:
<img src="assets/css/png/{{ client.logo }}_bw.png" />
Right:
<img ng-src="assets/css/png/{{ client.logo }}_bw.png" />
More information: https://docs.angularjs.org/api/ng/directive/ngSrc

Related

Server times out when using HTTPS instead of HTTP?

I'm running a remote react server with a NGINX load balancer.
When I use HTTP, I have no issues. But when I set HTTPS=True in my react environment, I get bad gateway when I try connecting the webpage.
The NGINX log says the following:
2021/07/06 10:01:07 [error] 10365#0: *62 upstream prematurely closed connection while reading response header from upstream, client: 155.4.218.180, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.50.3.152:80/favicon.ico", host: "remdent.com", referrer: "http://remdent.com/"
And 3 more similar messages claiming upstream was prematurely closed.
How do I remedy this?

npm packages are not found - SyntaxError: Unexpected token '<'

I'm running a react container in Kubernetes env (AKS) with an istio gateway
In local env, everything works well using docker build && docker run
In Kubernetes, for each npm package, the response I'm getting is status code: 200, response content-type: text/html, and the response content is of index.html which is why I'm assuming package was not found?
When checking docker dist content, I can assert that the package is there (for example /dist/npm.babel.4fca54....chunk.js is present
docker image is built using a base context: docker build -t imagename --build-arg PUBLIC_URL=/base-app .
index.html is valid and contains valid script declarations. for example <script type="text/javascript" src="/base-app/npm.babel.743f....chunk.js"></script>
Istio Gateway
spec:
selector:
istio: ingressgateway
servers:
- hosts:
- dev.myDomain.com
port:
name: https
number: 443
protocol: HTTPS
tls:
credentialName: someCreds
mode: SIMPLE
Istio VS
- match:
- uri:
prefix: /base-app
route:
- destination:
host: svc-app
port:
number: 8000
Example for a Request + headers
Request URL: https://dev.myDomain.com/base-app/npm.babel.4fca5....chunk.js
Request Method: GET
Status Code: 200
Remote Address: xxx.xxx.xxx:443
Referrer Policy: no-referrer-when-downgrade
Response Headers
accept-ranges: bytes
content-length: 11920 ---> length of index.html
content-type: text/html --> bad needs to be text/javascript
date: Tue, 11 Aug 2020 21:30:07 GMT
etag: "5f32aff9-2e90"
last-modified: Tue, 11 Aug 2020 14:49:29 GMT
server: istio-envoy
status: 200
x-envoy-upstream-service-time: 4
By default Istio will proxy from https://dev.myDomain.com/base-app/npm.babel.4fca5....chunk.js to http://pod_ip:8000/base-app/npm.babel.4fca5....chunk.js, and, as far as I can tell, your image serves files directly from /dist, so Istio should actually proxy to http://pod_ip:8000/npm.babel.4fca5....chunk.js; note the missing /base-app/. To do that, try to update the Istio Virtual Service to:
- match:
- uri:
prefix: /base-app
rewrite:
uri: /
route:
- destination:
host: svc-app
port:
number: 8000

App Engine Node flexible instance constantly running

I have several Firebase-Queue NodeJS instances running in my project on App Engine.
The instances seems to be constantly running, producing errors after trying a GET request.
13:33:36.078
{"method":"GET","latencySeconds":"0.000","referer":"-","host":"-","user":"-","code":"502","remote":"130.211.0.96","agent":"GoogleHC/1.0","path":"/_ah/health","size":"166"}
13:33:36.421
{"method":"GET","latencySeconds":"0.000","referer":"-","host":"-","user":"-","code":"502","remote":"130.211.1.229","agent":"GoogleHC/1.0","path":"/_ah/health","size":"166"}
13:33:37.000
[error] 32#0: *80631 connect() failed (111: Connection refused) while connecting to upstream, client: 130.211.1.11, server: , request: "GET /_ah/health HTTP/1.1", upstream: "http://172.18.0.2:8080/_ah/health", host: "10.128.0.5"
13:33:37.000
[error] 32#0: *80633 connect() failed (111: Connection refused) while connecting to upstream, client: 130.211.3.85, server: , request: "GET /_ah/health HTTP/1.1", upstream: "http://172.18.0.2:8080/_ah/health", host: "10.128.0.5"
My App.yaml file when i deploy my Node apps looks like this:
runtime: nodejs
env: flex
service: album-queue
skip_files:
- ^(node_modules)
handlers:
- url: .*
script: build/index.js
I think it must have something to do with all these these GET requests it's trying to do internally, but I don't know how to stop them / fix it. My bills are raking up fairly quickly, so would be pretty nice to get it fixed >_<
App Engine Flex doesn't scale to zero like the standard environment does. There will always be at least one instance running (default is actually 2). The requests you see are the normal health checks.

Cross-Origin Request Blocked with CORS headers present

on the server side I have the following filter in apache which allow all methods and all origins by defaults
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Using angular $http One post is working, but another fail failed. The request that fails talks to another app on the same apache.
Cross-Origin Request Blocked: The Same Origin Policy disallows
reading the remote resource at http://localhost:..
(Reason: CORS header 'Access-Control-Allow-Origin'
does not match 'http://localhost:8100, http://localhost:8100').
But the response header does contain the ACAO
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
access-control-allow-credentials: true, true
access-control-allow-origin: http://localhost:8100, http://localhost:8100
Vary: Origin
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 22 Oct 2015 04:35:29 GMT
Where did the ' http://localhost:8100, http://localhost:8100' come from ? Do you think it is angular $http or Apache problem ?
Access-Control-Allow-Origin accepts either '*' or a single origin for its value. You can't put a comma-separated list there.
The browser is matching the origin (http://localhost:8100 against http://localhost:8100, http://localhost:8100 and not getting a match.
You have a similar problem on the line before. It looks like you are running the code to insert your CORS headers twice.

gcloud preview app deploy returns 400 error

Trying to deploy some static content to GAE, since they removed the push-to-deploy pipeline feature. I've setup a brand new project. It's in the US region. Did gcloud auth login again. Still getting the same response.
Verbose debug output below. [REDACTED] is my addition to the code.
$ gcloud preview app deploy dist/app.yaml --verbosity debug
DEBUG: Running gcloud.preview.app.deploy with Namespace(__calliope_internal_deepest_parser=ArgumentParser(prog='gcloud.preview.app.deploy', usage=None, description="*(BETA)* This command is used to deploy both code and configuration to the App Engine\nserver. As an input it takes one or more ``DEPLOYABLES'' that should be\nuploaded. A ``DEPLOYABLE'' can be a module's .yaml file or a configuration's\n.yaml file.", version=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=False), cmd_func=<bound method Command.Run of <googlecloudsdk.calliope.backend.Command object at 0x10bf14290>>, command_path=['gcloud', 'preview', 'app', 'deploy'], deployables=['dist/app.yaml'], document=None, env_vars=None, force=False, format=None, h=None, help=None, http_timeout=None, log_http=None, markdown=None, project=None, quiet=None, remote=False, server=None, set_default=False, trace_token=None, user_output_enabled=None, verbosity='debug', version=None).
You are about to deploy the following modules:
- [PROJECT_ID]/default/20150612t130942 From: [/Users/[ME]/Dropbox/Sites/[PROJECT_ID]/site/dist/app.yaml]
Do you want to continue (Y/n)? Y
Updating module [default]...DEBUG: Host: appengine.google.com
DEBUG: Host: appengine.google.com
DEBUG: Getting current resource limits.
DEBUG: Send: /api/appversion/getresourcelimits, params={'version': '20150612t130942', 'app_id': '[PROJECT_ID]'}
DEBUG: _Authenticate configuring auth; needs_auth=False
DEBUG: Sending request to https://appengine.google.com/api/appversion/getresourcelimits?app_id=[PROJECT_ID]&version=20150612t130942 headers={'X-appcfg-api-version': '1', 'content-length': '0', 'Content-Type': 'application/octet-stream'} body=
INFO: Attempting refresh to obtain initial access_token
INFO: Refreshing access_token
DEBUG: Got response: max_file_size: 32000000
max_blob_size: 32000000
max_files_to_clone: 2000
max_total_file_size: 9223372036854775807
max_file_count: 10000
DEBUG: Using resource limits: {'max_file_size': 32000000, 'max_total_file_size': 9223372036854775807, 'max_blob_size': 32000000, 'max_files_to_clone': 2000, 'max_file_count': 10000}
INFO: Reading app configuration.
DEBUG:
Starting update of app: [PROJECT_ID], version: 20150612t130942
DEBUG: Scanning files on local disk.
INFO: Processing file [app.yaml]
INFO: Processing file [index.html]
INFO: Processing file [views/6a0e56b1.main.html]
INFO: Processing file [views/partials/90bc29e6.case-study.html]
INFO: Processing file [views/partials/cc69dea5.home.html]
INFO: Processing file [styles/9960b040.main.css]
INFO: Processing file [scripts/8a12aff1.scripts.js]
INFO: Processing file [scripts/8e6de882.libraries.js]
DEBUG: Send: /api/appversion/create, params={'version': '20150612t130942', 'app_id': '[PROJECT_ID]', 'module': 'default'}
DEBUG: _Authenticate configuring auth; needs_auth=False
DEBUG: Sending request to https://appengine.google.com/api/appversion/create?app_id=[PROJECT_ID]&module=default&version=20150612t130942 headers={'X-appcfg-api-version': '1', 'content-length': '633', 'Content-Type': 'application/octet-stream'} body=api_version: '1'
application: [PROJECT_ID]
auto_id_policy: default
builtins:
- default: 'on'
derived_file_type:
- python_precompiled
handlers:
- script: index.html
secure: optional
url: /
- secure: optional
static_dir: styles
url: /styles
- secure: optional
static_dir: scripts
url: /scripts
- secure: optional
static_dir: views
url: /views
- secure: optional
static_dir: fonts
url: /fonts
- secure: optional
static_dir: images
url: /images
- secure: optional
static_dir: res
url: /res
module: default
runtime: php
threadsafe: true
version: 20150612t130942
vm_settings:
module_yaml_path: app.yaml
INFO: Attempting refresh to obtain initial access_token
INFO: Refreshing access_token
Updating module [default].../DEBUG: Got http error 400.
DEBUG: Unexpected results: {'status': '400', 'alternate-protocol': '443:quic,p=1', 'content-length': '318', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'server': 'Google Frontend', 'cache-control': 'no-cache', 'date': 'Fri, 12 Jun 2015 18:09:47 GMT', 'content-type': 'text/plain'}
Updating module [default]...done.
DEBUG: (gcloud.preview.app.deploy) Server responded with code [400]:
Bad Request Unexpected HTTP status 400
Traceback (most recent call last):
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/calliope/cli.py", line 538, in Execute
result = args.cmd_func(cli=self, args=args)
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/calliope/backend.py", line 1124, in Run
result = command_instance.Run(args)
File "/Users/[ME]/Applications/google-cloud-sdk/lib/googlecloudsdk/appengine/app_commands/deploy.py", line 119, in Run
client.DeployModule(module, version, info.parsed, info.file)
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/appengine_client.py", line 276, in DeployModule
return appversion.DoUpload()
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/appengine_deployments.py", line 1016, in DoUpload
missing_files = self.Begin()
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/appengine_deployments.py", line 561, in Begin
payload=config_copy.ToYAML())
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/util.py", line 288, in Send
result = self.rpcserver.Send(url, payload=payload, **kwargs)
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/util.py", line 353, in Send
response = self._server.Send(*args, **kwargs)
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/external/tools/appengine_rpc_httplib2.py", line 269, in Send
'Unexpected HTTP status %s' % status)
File "/Users/[ME]/Applications/google-cloud-sdk/./lib/googlecloudsdk/appengine/lib/external/tools/appengine_rpc_httplib2.py", line 67, in RaiseHttpError
raise urllib2.HTTPError(url, response_info.status, msg, response_info, stream)
RPCError: Server responded with code [400]:
Bad Request Unexpected HTTP status 400
ERROR: (gcloud.preview.app.deploy) Server responded with code [400]:
Bad Request Unexpected HTTP status 400
You might have to set the project id again if you have disabled/removed previous application from google cloud console.
gcloud config set project PROJECT_ID
The generic issue is that the error did not have a message.
Starting in the cloud SDK release tomorrow, the reason for whatever error (billing issue, not enough quota, whatever) will be displayed, so please try to get the newer cloud SDK tomorrow.
For me I hadn't enabled billing in Compute > Compute Engine > VM instances on my Google Console project. It works now!
If you have appcfg.py installed, you can run that to deploy and it will give the exact error message, I found mine to be an invalid api_version for the java runtime (to which i can't find the valid number and 1 isn't it)
My initial deployment was fine and after I uploaded the update, it started to fail and get the same errors as you did. I found the issue with oauth. Logout from google and running:
$ gcloud auth login
After relogin, I was able to deploy. No re-coding or Managed VM setting changes were done.

Resources