Routing to webdev serve in AngularDart - angular-dart

I have an AngularDart site in a docker container, with a Nginx routing in front like: http://<ip>/site. I can attach to the container and start webdev serve.
But when I curl http://<ip>/site
I get:
Could not find web/site/index.html or any files in web/site
In my attempt to solve this I am looking at the following description:
In this routing description:
<script>
// WARNING: DO NOT set the <base href> like this in production!
// Details: https://webdev.dartlang.org/angular/guide/router
(function () {
var m = document.location.pathname.match(/^(\/[-\w]+)+\/web($|\/)/);
document.write('<base href="' + (m ? m[0] : '/') + '" />');
}());
</script>
Update: If I fix set:
document.write('<base href="/site/"/>');
It works with an error in the browser unable to find main.js - but it still works.
Do you know how to fix the routing problem og maybe just what is the /web($|\/)/ doing?

Related

Vue router - How to open in new tab in production?

I am using Vue, Vuetify and my database is in postgreSQL with an API-backend from postgREST (https://postgrest.org/en/stable/). When using the localhost and hash mode everything is fine locally. I can open the component product in a new tab when using this syntax:
const route = this.$router.resolve({ path: `/product/${value.id}` }) (1)
window.open(route.href, '_blank') (2)
However, in the production environment with postgREST-server when opening in a new tab, I get the wrong url :
http:server_name/api/#/product/1 (3)
When I remove /api from the above url (3) and rewrite it like this :
http:server_name/#/product (4)
I get the correct page.
Is it a possible nginx rule that can be written to make sure that
http:server_name/api/#/product/1 is automatically rewritten to the correct url http:server_name/#/product? or How can I change vue-router or vue config file in order to get same behavior in production as in locahost ?
A possible client-side workaround is to strip the /api prefix in production mode:
const url = process.env.NODE_ENV === 'production'
? route.href.replace('/api', '')
: route.href
window.open(url, '_blank')

Routing to a URL behaves differently in config

I am attempting to get familiar with spring-cloud-gateway and I am having a problem configuring routes in YAML. I am attempting to do a simple redirect based on path to httpbin.org. This works fine when I do this in code but when I am attempting this in YAML config I get a 404.
YAML:
- id: demo
uri: http://httpbin.org
predicates:
- Path=/demo
When I attempt this route, it looks like the route is getting matched- I dont see a 404 for the route itself. What I get in the response is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try
again.</p>
What am I doing wrong here?

Beginner Bottle and static files question

After using the Python http.server module I'm now trying to convert everything to Bottle and can't even get started. My problem is locating static files - everything I've tried results in a "404" error. So I've tried to reduce everything to the simplest possible example. My top level directory is in "/home/dave/test" and under that is a single file (test.py), and a subdirectory ("/home/dave/test/static") containing the single file "index.html". The html file is pretty basic:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bottle Test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Hello, World</h1>
</body>
</html>
If I double click on the file itself, it opens a new browser page and displays the "Hello, World" message. The test.py file is:
#!/usr/bin/env python3
from bottle import route, run, static_file
#route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='/home/dave/test/static')
run(host='localhost', port=8080, debug=True)
If I open a browser window and enter "localhost:8080/index.html" I get back the "Error: 404 Not Found" message and the terminal window where I'm running the script looks like:
$ ./test.py
Bottle v0.12.16 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
127.0.0.1 - - [06/Apr/2019 15:31:25] "GET /index.html HTTP/1.1" 404 740
I've tried various permutations of the URL and root parameter but nothing I've tried works. Clearly I'm missing something very basic here. Can somebody tell me what is wrong in in the above files (or URL)?
Thanks,
Dave
I was able to contact the author of Bottle and he responded:
a route matches against the path-part of an HTTP request URL. In your
example, '/static/' would match requests to
http://localhost:8080/static/index.html and serve 'index.html' file
from the '/home/dave/test/static' directory.
"http://localhost:8080/index.html" does not match the route you
specified, thus the 404 error.
I tried this and it did indeed fix the problem.

How to setup elasticsearch secure connection using HTTPS through REST API

I want to query my data indexed by elasticsearch in Lucene engine, but I want this connection to be secure by using SSL:
https://x.y.z.w:9200/index_name/_search?&q=field:value
And this is my whole code:
<!doctype html>
<html lang="fa">
<head>
<title>XHR App Test</title>
<script>
function send() {
var xhr = new XMLHttpRequest(),
url = 'https://x.y.z.w:9200/index_name/_search?&q=field:value',
sendButton = document.getElementById('sendButton');
xhr.onreadystatechange = function(e) {
console.log(e);
if (e.currentTarget.readyState > 2) {
document.getElementById('result').innerHTML = e.currentTarget.responseText;
}
};
xhr.open('GET', url, true);
xhr.send(null);
}
</script>
</head>
<body>
<h1>XHR App Test</h1>
<button id='sendButton' onclick="send()">Send</button>
<div id="result"></div>
</body>
</html>
I also added these configs in elasticsearch.yml file:
http.port: 9200
http.cors.enabled : true
http.cors.allow-origin: /https?:\/\//
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : "X-Requested-With,X-Auth-Token,Content-Type, Content-Length, Authorization"
# http.cors.allow-credentials : true
But only be able to query by http protocol not https.
How to resolve this?
Elasticsearch doesn't support SSL out-of-the-box. The http.cors settings are for enabling and setting up the CORS (Cross-origin resource sharing) mechanism but have nothing to do with SSL.
If you want your ES cluster to serve requests over HTTPS/SSL, you need to setup SSL/TLS either using the Shield plugin or preferably with XPack if you're running ES 5.

Code runs fine on localhost but not on Facebook. Maybe because of CURL?

The following code gives fine output while running on localhost. Earlier it was giving some error related to CURL so i fixed it and now its running fine on localhost.
But my app is not running on facebook.I am using HEROKU so is it having same problem of CURL?? If so than how can i fix it?? I hav even uploaded PHP SDK on heroku. My IE gives error 500 and firefox gives a blank screen.
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
include 'libs/facebook.php';
$facebook=new Facebook(array(
'appId'=>'************',
'secret'=>'********************',
'cookie'=>true
));
$me=null;
if($me)
{
$logoutUrl=$facebook->getLogoutUrl();
echo "<a href'$logoutUrl'>Logout</a>";
}
else
{
$loginUrl=$facebook->getLoginUrl();
echo "<a href='$loginUrl'>Login</a>";
}
?>
</body>
</html>
The code you posted will always ask for the login url because $me will always be null.
As to the rest of the errors, try adding error reporting to the top of your file
error_reporting(E_ALL);
ini_set("display_errors", 1);
Then deploy, then run heroku logs --tail locally to see what is going on in the file.
Also place your PHP section above your HTML outside the <html> tag.