AngularJS page refresh problems - angularjs

When working with Angular and its routes, if you reload the page in, let's say, localhost:9000/products, the response will be a 404.
I am using Python server created using python -m SimpleHTTPServer port no. How to solve this problem since .htaccess file is not working in this?

.htaccess files are for apache http server not the python server, the .htaccess is for setting up redirects that the apache server will observe but if you use nginx or in this case python simple http server you'd have to use redirects specific to that particular http server this may help:
https://gist.github.com/chrisbolin/2e90bc492270802d00a6
copied here not written by myself apparently also from SO
''' Taken from: http://stackoverflow.com/users/1074592/fakerainbrigand http://stackoverflow.com/questions/15401815/python-simplehttpserver '''
import SimpleHTTPServer, SocketServer import urlparse, os
PORT = 3000 INDEXFILE = 'index.html'
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self):
# Parse query data to find out what was requested
parsedParams = urlparse.urlparse(self.path)
# See if the file requested exists
if os.access('.' + os.sep + parsedParams.path, os.R_OK):
# File exists, serve it up
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self);
else:
# send index.html, but don't redirect
self.send_response(200)
self.send_header('Content-Type', 'text/html')
self.end_headers()
with open(INDEXFILE, 'r') as fin:
self.copyfile(fin, self.wfile)
Handler = MyHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT httpd.serve_forever()
Also personally I use apache locally and just have browsersync proxy to the apache server and that handles the redirect if a file isn't found, from there the angular page takes over and routing kicks in to restore the view or go to a page not found view.

Related

Nginx is redirecting subdomain to main domain

I have two domains,
zerp.io (ssl installed)
app.zerp.io (only http)
in zerp.io (main domain) a wordpress website is hosted and is working fine. I am trying to deploy a React app on app.zerp.io using nginx. I deleted the default file and created new file app.zerp.io at /etc/nginx/sites-available/ I also created same file at /etc/nginx/sites-enabled/ and created a symlink between them. I checked the DNS entry, app.zerp.io and www.app.zerp.io is pointing to the public Ip of the correct server where React App resides.
Here's my /etc/nginx/sites-available/app.zerp.io file
server {
listen 80;
index index.html index.htm index.nginx-debian.html;
server_name www.app.zerp.io app.zerp.io;
location / {
proxy_pass localhost:3000;
proxy_ser_header host $host;
}
}
The problem is, whenever I try to reach http://app.zerp.io through web browser it redirects me to https://zerp.io. Here's what I did so far,
I checked DNS using an online tool, its correctly pointing to the server
I did not use any 301 redirects in the configuration file as you can see above
when I try curl app.zerp.io from the production server (in Germany), sometimes it gives 200 with correct response and sometimes it gives 301 (moved permanently) crazy isn't it
When I try curl app.zerp.io from my local computer it always give me 301 although I do not have any 301 in my nginx config file
I thought, may be its a cache issue on my chrome, to my surprise no, I cleared the cache and hard reload, I even tried incognito mode with no success, it always redirect me to https://zerp.io
When I try curl app.zerp.io from my local computer using a VPS it correctly opens the website app.zerp.io.
I do not have any ssl certificate so there are not redirects from http to https in http://app.zerp.io
Its been two days, Its making me crazy, I am assuming it has something to do with DNS resolution. Can some please help me out

Nginx config to redirect myserver.com to Tableau tabserver.com on login and logout

I want to redirect a user from my webapp(myserver.com) to Tableau server hosted at tabserver.com
Whenever I hit the login URL in the browser for tabserver.com the URL bar shows this: tabserver.com/signin or tabserver.com/signin?redirect=someURL
Similarly, when I logout from tableau server, the URL bar always show this:tabserver.com/signin?disableAutoSignin=yes
So login and logout URLs both point to /signin with change in URL parameters.
Can the nginx config be configured so that:
By hitting tabserver.com/#/site/, it redirects me to myserver.com?
And when logging out, it also redirects me to myserver.com?
If you are using NGINX’s main configuration file nginx.conf
without virtual hosts.
Sudo vi /etc/nginx/nginx.conf
(Sudo is for Linux systems)
configure separate virtual hosts for your website (e.g www.myweb.com), such as /etc/nginx/sites-enabled/myweb.conf
then open it with the following command.
/etc/nginx/sites-enabled/mysite.conf
(Use Sudo is for Linux systems)
For example if you want to redirect /login to new domain
(www.myserver.com), then add the following location block
inside your server block.
server{
location /login {
rewrite ^/login(.*)$ https://www.myserver.com/$1 redirect;
}
}
rewrite – rewrite command tells NGINX to change one or more
URLs that match a given pattern (e.g /login) to another URL.
^/login – URL paths that start with /login. You can change it to
another URL as you need it.
(.*) – match one or more characters. In our case, it means
anything that follows /login.
$ – end of string
$1 - URL part after /login

I can't fetch from external API in production

I want to fetch some info but when I try to implement this to server (Ubuntu 18.04) with Nginx I can't fetch...
Put certificate to enable HTTPS to my domain.
Create a .env with a variable that contains the complete url to API (Because Im using a proxy in development)
Put some headers to the petition
Try to change the config in nginx
But nothing... my application only works running in localhost
axios.get(process.env.REACT_APP_API_URL) ...
The console of the browser (Safari):
Origin https://mysubdomain.com is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load https://mysubdomain.com due to access control checks.
Failed to load resource: Origin https://mysubdomain.com is not allowed by Access-Control-Allow-Origin.
You Server needs to return below header value
Access-Control-Allow-Origin: *
which means anyone can connect to API.
Work Around
Go to chrome folder.
chrome.exe --user-data-dir="<Some directory name to store temporary chrome data>" --disable-web-security
I'm not expert in nginx but this works!
I edit my site file in /etc/nginx/sites-available/mysite like this:
location /anyAppLocation/ {
proxy_method GET;
proxy_pass_request_headers on;
proxy_pass https://api.site.com;
proxy_redirect default;
}

Setup Roundup with WSGI and Apache

I was install Roundup 1.4 by Debian Squeeze official repo and want to run it with my Apache server using mod_wsgi. Host configuration:
<VirtualHost *:80>
ServerName support.domain.com
WSGIScriptAlias / /var/roundup/support/apache/roundup.wsgi
WSGIDaemonProcess support.roundup user=roundup group=roundup threads=25
WSGIProcessGroup support.roundup
<Directory /var/roundup/support>
<Files roundup.wsgi>
Order allow,deny
Allow from all
</Files>
</Directory>
# ... some logging configuration
</VirtualHost>
I was install tracker in /var/roundup/support using roundup-admin install, configure it and next initialise using roundup-admin initialise. Then I was created apache/roundup.wsgi:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
When opening my site at http://support.domain.com (ofcourse this url is bit different) I have HTTP response 500 Internal Server Error and log with:
mod_wsgi (pid=17433): Exception occured processing WSGI script '/var/roundup/support/apache/roundup.wsgi'.
RuntimeError: response has not been started
What's going on? How to run roundup with wsgi (not cgi) properly? Or where to look why response has not been started?
EDIT
Roundup's install manual says that wsgi handler would look like this:
from wsgiref.simple_server import make_server
# obtain the WSGI request dispatcher
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = 'demo'
app = RequestDispatcher(tracker_home)
httpd = make_server('', 8917, app)
httpd.serve_forever()
But this make no response. Browser loading it forever without message or server log. I think starting another server from script running by apache module isn't good idea. So I tried another code sample:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
from flup.server.fcgi import WSGIServer
WSGIServer(application).run()
But this throws some errors like:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
There must be a way to run my application from RequestDispatcher...
According to this issue this is an permission's problem. Solved using:
WSGIDaemonProcess support.roundup user=roundup group=roundup threads=25
WSGIProcessGroup support.roundup
where files in /var/roundup/support/ has roundup as owner and group with appropriate access permissions.
Try:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
All mod_wsgi needs is an 'application' object which is a valid WSGI application entry point.
You do not need to start a WSGI server or FASTCGI adapter yourself as you have been trying to do.

GAE dev_appserver.py over HTTPS

Has anyone cracked how to get HTTPS working on the dev_appserver.py? I need it for Facebook canvas app testing. I've had a search of the docs and nothing suggests there's a way to do it (sticking 'secure' in the app.yaml doesn't nothing locally).
I was think there may be a way to proxy it, but has anyone got any experience of this?
The dev_appserver doesn't support HTTPS. The only practical way to do this is to set up a reverse proxy in front of your app - such as with nginx or Apache - and have it proxy SSL traffic to your app.
I know this is late, in case anybody else finds this question:
ngrok is quiet easy to setup for a custom reverse HTTPS proxy..
The only downside is that my webapp2 application still believes it's being served over HTTP, so using redirect() doesn't work well because it resolves relative URLs to absolute URLs using request.url.
My workaround was to overwrite RequestHandler.redirect as follows:
class BaseRequestHandler(RequestHandler):
def redirect(self, uri, permanent = False, abort = False, code = None, body = None):
if uri.startswith(('.', '/')):
base_url = self.request.url
if base_url.startswith('http://'):
base_url = 'https://' + base_url[7:]
uri = str(urlparse.urljoin(base_url, uri))
super(RequestHandler, self).redirect(uri, permanent, abort, code, body)
I needed a BaseRequestHandler class anyways for implementing other utility functions.
I put this in my Appache httpd.conf to proxy the connection:
<Location /myproject/>
ProxyPass http://localhost:8080/
</Location>
Now going to https://localhost/myproject/ in my browser worked.
Note: SSL needs to be enabled on your Apache server. On my OS X machine I uncommented out the line Include /private/etc/apache2/extra/httpd-ssl.conf in /etc/apache2/httpd.conf and ran sudo apachectl restart

Resources