Polymer 2 iron-ajax is loading the wrong local file - polymer

When loading a local json file with the iron-ajax Polymer web component the response returned is the contents of index.html, not the json file.
<iron-ajax auto url="data.json" on-response="handleResponse" handle-as="json"></iron-ajax>
I am checking the response in Chrome developer tools under "Network" and the response given is the same as the index.html file. I am using Polymer 2.0 starter kit as a front end with Flask on the back end. Apologies if this is a simple mistake but I am new to JavaScript.
My simplified file structure looks like:
/app
|-- app.py
|-- /static
|-- index.html
|-- /bower_components
|-- /src
|-- data.json *(file to be loaded)*
|-- my-app.html
|-- my-view.html *(view to load file)*
EDIT:
I believe the problem may be to do with this catch-all in the app.py file from the boiler plate I am using. I realise I do not understand how the relative url's are working in this application.
#app.route("/static/<path:path>")
def static_c(path):
return current_app.send_static_file(path)
#app.route('/', defaults={'path': ''})
#app.route('/<path:path>')
def catch_all(path):
return current_app.send_static_file("index.html")

Related

Angular6 change site log depending on build configuration

I have 2 environment setup in my angular 6 web app.
Here I need to change the site logo depending on the environment.
The logo is returned from api. Depending on env how to run the api. And how to use this in components.
I implemented the static logo integration with env config by
environment.dev
production: true,
logourl: 'assets/images/logo.png',
environment.test
production: true,
logourl: 'assets/images/logo1.png',
Now the logo url is returned from api as
Dev: http://url.com/getlog?cliid=1
test: http://url.com/getlog?cliid=2
Where to run this api. If so how to configure this api response to env file.
Please help me to do this.
You just need to get reference to that environment variable in typescript and use binding to update logo source in HTML.
Typescript:
import { environment } from './../../../environments/environment.dev';
logoUrl: string;
constructor{
this.logoUrl= environment.logourl;
}
You can now bind logo url to HTML image like so:
<img [src]="logourl" />
Depending on your project setup, when you run Angular in prod, it should replace the import with the corresponding environment file.
When you generate a new project, Angular gives you environment.ts for development and environment.prod.ts for production.
You'd by default import environment in all your components and when you build project for production, Angular swaps the references to production.

jmeter.functions.FileToString not finding file location

In JMeter I am passing multiple JSON inputs as body, Variable name is defined as JSON_FILE and coming from CSV Data Config
${__FileToString(${__eval(${JSON_FILE})}.json,,)}
CSV Data
designO1015643320
.
.
designO1077673985
designO1088516727
Running load test from Jmeter UI works fine, but running as mvn project is giving error about FileNotFoundException even though .csv file and .json files are in same folder as .jmx file
Error from .jmx.log:
WARN - jmeter.functions.FileToString: Could not read file: designO1015643320.json File 'designO1015643320.json' does not exist java.io.FileNotFoundException: File 'designO1015643320.json' does not exist
Response in .jtl:
httpSample t="4" lt="0" ts="1508530091457" s="false" lb="CreateDesign_PUT" rc="Non HTTP response code: org.apache.jorphan.util.JMeterStopThreadException" rm="Non HTTP response message: End of sequence" tn="Design_APIs 1-1" dt="text" by="1822" ng="1" na="1"/>
JMeter GUI default relative path is the bin folder
Relative paths are resolved relative to the current working directory (which defaults to the bin/ directory).
Maven search in different default path for files src/test/jmeter directory
See guide:
in the src/test/jmeter directory. When running the project, the JMeter Maven plugin searches for tests to run in this directory.
And you can find this path dynamically
I heard Groovy is a new black so I would recommend replacing your __FileToString() function with __groovy() function, the Groovy equivalent of dynamically getting the file path relative to Maven's plugin current working directory would be something like:
${__groovy(new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + System.getProperty('file.separator') + vars.get('JSON_FILE') + '.json').text,)}
See JavaDoc on FileServer class for more details.

ReactJS: JSON file is fetched from localhost instead of project directory

I have following directory structure of my project.
I have following code in my index.js file for loading website.json file.
index.js
componentDidMount() {
$.ajax({
url: "../website.json",
type: "GET",
dataType: 'json',
ContentType: 'application/json',
success: function(data) {
this.setState({data: data});
console.log(data);
}.bind(this),
error: function(jqXHR) {
console.log(jqXHR);
}.bind(this)
})
}
The problem is that I am using npm start command to server my react app from local directory of my application. This serves my app at http://localhost:3000/ . Now the problem is that the application tries to load the website.json file from http://localhost:3000/website.json which gives a 404 not found error.
So, my question is how my website.json file can be loaded from my project directory instead of localhost.
Note: my project folder is not at localhost but at virtual host.
Update: I am specifically asking why the ajax call is unable to load data from my project folder (I am using relative addressing) and instead including path from localhost. I want to load data using ajax call is it possible or not.
Your webserver (I would guess Express) will be serving files from the 'public' folder.
For security reasons, web servers do not allow access to files outside of the directory root (/public in your case), so you will not be able to get the file by ajax (or from the browser).
If you really want to, you could either:
Copy/Move the file into the public folder
Create a symlink to the file in the public folder
You may include it inside source as
var website = require('../website.json');
So it will be embedded during compile time.
Another way to do it - move website.json to public folder, than you may access it as ajax('/website.json'...
I assume you are using ES6/ES2015 since you are using react. So instead of doing it in componentDidMount you can just add this at the top:
import websiteData from '../website.json';
And then you can just use websiteData as a variable in your component.

How to customize error pages Symfony?

I followed the instructions on the page https://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-error-templates and have created my own errors templates to display error pages depending on status code of the error (i.e. error.html.twig contains {{status_code}} variable):
|-- app/
|-- Resources/
|-- TwigBundle/
|-- views/
|-- Exception/
|-- error.html.twig
|-- exception.html.twig
But:
pages error.html.twig and exception.html.twig never shown, no matter what env is set.
in the production environment I can see fatal errors and every kind of Symfony Exceptions which it should never take place - yet it is prod env! (edit: The problem only occurs on my local machine - on remote server I see just default browser's error pages)
How to fix this? I found only 1 similar topic at stack (How to Customize Error Pages Template In symfony 3.1?) but it doesn't contain the right answer.

remove .html extension from url with app.yaml in google app engine for java for static pages

I am using Google app engine to serve static web pages but I want to remove .html extension in the URL. I created a App.yaml file. I created a folder called static with the app.yaml file included but it still does not work any ideas what I am doing wrong ?. I am using app engine with java.
application: Google App Engine JSF 2.2 Template
version: 1
runtime: java
handlers:
- url: /(.+)
mime_type: text/html
static_files: static/\1.html
upload: static/(.+)
Hey GAEfan here is my code with the indent and it is google app engine for java,thanks again for the help
application: Google App Engine JSF 2.2 Template
version: 1
runtime: java
handlers:
- url: /(.+)
static_files: static/\1.html
upload: static/\1.html
mime_type: text/html
Try this:
- url: /(.+)
file: static/\1.html
and put app.yaml at the root (war folder). And, make sure the indentation is as you see here. Your indentation is incorrect. Should be 2 spaces indented, except the - url line.