Directly opening url with stateparam not working in angularjs - angular-ui-router

I have url like
http://localhost:8000/articles/2345 when clicked within angular, it works fine. This URL's have to be linked from other websites also. But i get error like
Uncaught SyntaxError: Unexpected token <
I am using ui-router like below
.state('kbca', {
parent : 'root',
url: "/articles/:articleId",
templateUrl: "views/abc/abc.html,
controller: "abcCtrl",
data : {
authorizedRoles : [ROLES.PUBLIC]
}
})
and config like
.config(function($locationProvider){
$locationProvider.html5Mode(true).hashPrefix('!');
});
and i have index.html where in i have made base as
<div id="wrap">
<div ui-view></div>
</div> <!-- end wrap -->
<base href="/">
i tried lots of options on web. But nothing seems to be working for me.
Here is my server conf
server {
listen 8000;
root D:/xampp/htdocs/web/myweb/app;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /mysvcs {
proxy_pass http://localhost:8080/mymvc;
proxy_set_header Host localhost;
}
location /mymvc {
proxy_pass http://localhost:8080/mymvc;
proxy_set_header Host localhost;
}
}

Related

How to solve blank page while running second vue app under nginx?

Need to run multiple Vue.js v3 apps with ngnix under macOS Big Sur.
First app located in: /Users/kharraz/Developer/code/homeapp/dist;
Second app: /Users/kharraz/Developer/code/businessapp/dist;
The two folders contains yarn build output;
The goal is when i tape localhost or localhost/homeapp takes me to the first app and when i type localhost/businessapp takes me to the second app.
With my current conf, localhost/homeapp/index.html is working but the second localhost/businessapp/index.html is giving me a blank page.
Both apps are working fine under localhost:8001 and localhost:8002.
Here is my nginx.conf file:
http {
server {
listen 8080;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forward-Host $host;
proxy_pass http://127.0.0.1:8001;
break;
}
location /markets {
proxy_set_header X-Forward-Host $host;
proxy_pass http://127.0.0.1:8002;
}
}
server {
listen 8001;
location / {
root /Users/kharraz/Developer/code/homeapp/dist;
try_files $uri /index.html;
include /opt/homebrew/etc/nginx/mime.types;
}
}
server {
server_name businessapp;
listen 8002;
location / {
root /Users/kharraz/Developer/code/businessapp/dist;
try_files $uri /index.html;
include /opt/homebrew/etc/nginx/mime.types;
}
}
}
Manually make the App route to path '/' instead of depending on Vue to take to homepage.
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
export default {
setup() {
const route = useRouter();
const doOpeningCeremony = async () => {
route.push({path: '/'});
}
onMounted(doOpeningCeremony);
},
}

Why subdomain is not working in Ubuntu nginx server?

There a running Laravel application in the root folder of my ubuntu nginx server. Now i am trying to create a subdomain and run another Laravel application there. For instance,
findosman.xyz (root, running laravel app)
api.devport.findosman.xyz (another Laravel API)
Here is my current configuration;
In /etc/nginx/sites-available/api.devport.findosman.xyz
server {
listen 80;
listen [::]:80;
root /var/www/api-devport;
index index.php index.html index.htm;
server_name api.devport.findosman.xyz;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
}
location ~ /\.ht {
deny all;
}
}
Here is the /etc/nginx/sites-enabled/api.devport.findosman.xyz
server {
listen 80;
listen [::]:80;
root /var/www/api-devport;
index index.php index.html index.htm;
server_name api.devport.findosman.xyz;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
}
location ~ /\.ht {
deny all;
}
}
In /var/www/api-devport I have currently only a index.php file which only has <?php echo "hello world"?>
the root folder project is running fine. but wherever I am trying to access devport.findosman.xyz it shows The site can't be reached.
How to overcome this problem ? Thanks in advance.

send cookies from quasar ssr to laravel backend

I am building a web app using Quasar SSR for the front-end and Laravel for the backend.
For Authentication, I use the new Laravel Sanctum Package which uses cookies for user authentication.
Building the app in SPA, I have no problem to authenticate users. Unfortunately in SSR mode, no cookies are sent to the server thus making user authentication impossible.
I use axios to handle ajax request. I set it in a boot file.
Can someone help me send the cookies to the backend?
Editing to add some precisions. I am using nginx as a web server and my configuration is as follow:
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /var/www/certs/www.mysite/fullchain.pem;
ssl_certificate_key /var/www/certs/www.mysite/privkey.pem;
ssl_protocols TLSv1.2;
root /var/www/next/mysite/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name next.mysite.net;
location / {
#try_files $uri $uri/ /index.php?$args;
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /storage/ {
}
location /vendor/ {
}
location /server {
try_files $uri $uri/ /index.php?$args;
}
location /prequel-api {
try_files $uri $uri/ /index.php?$args;
}
location /api {
try_files $uri $uri/ /index.php?$args;
}
location /graphql {
try_files $uri $uri/ /index.php?$args;
}
location /sanctum {
try_files $uri $uri/ /index.php?$args;
}
location ~ [^/]\.php(/|$) {
#try_files $uri =404;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#if (!-f $document_root$fastcgi_script_name) {
# return 404;
#}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
# include the fastcgi_param setting
include fastcgi_params;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
import Axios from "axios";
import { boot } from "quasar/wrappers";
import { Cookies } from "quasar";
const axios = Axios.create({
baseUrl: "https://next.mysite.net"
});
axios.defaults.withCredentials = true;
axios.interceptors.response.use(
response => {
return response.data;
},
error => {
return Promise.reject(error.response);
}
);
export default boot(async ({ Vue, ssrContext }) => {
if (process.env.SERVER) {
//Check if cookies are available
var cookies = JSON.stringify(Cookies.parseSSR(ssrContext).getAll()).replace(
/[{}]/g,
""
);
console.log("cookies: ", cookies);
}
Vue.prototype.$axios = axios;
});
export { axios };
I solved a similar problem by extending the axios instance with cookies when creating the instance
//boot/axios.js (inside callback function)
if (ssrContext) {
const cookies = ssrContext.$q.cookies.getAll();
instance.interceptors.request.use(function (config) {
const cookiesSet = Object.keys(cookies).
reduce((prev, curr) => prev + curr + '=' + cookies[curr] + ';', '');
if (cookiesSet.length > 0) {
config.headers.Cookie = cookiesSet;
}
return config;
});
}

Nginx configuration for angular and magento

I want to do nginx setup for handing two project with same domain.
Example domain: example.com
Angular project should run with example.com
magento2 project should run with example.com/shop
I tried the code below, but its not working.
location /shop {
alias /var/www/www.example.com/shop/;
index index.html;
try_files $uri $uri/
autoindex on;
}
Can please someone help me to do this.
You should use official NGINX configuration sample as provided here.
Naturally, you will prefix all the Magento 2 locations with /shop/, for your specific case.
So you will end up with this kind of config:
server {
listen 80;
server_name example.com;
location / {
root /path/to/your/generated/angular/resources;
try_files $uri$args $uri$args/ /index.html;
}
# Magento 2 directives start here...
location ~* ^/shop/setup($|/) {
# ...
}
# The rest of Magento 2 directives...
}
You can start with the following config to serve your Applications:
server {
listen 80;
server_name example.com;
location / {
root /path/to/your/generated/angular/resources;
try_files $uri$args $uri$args/ /index.html;
}
location /shop {
root /path/to/shop/;
index index.html;
try_files $uri $uri/;
}
}
I'm not 100% sure if the shop route will work. Maybe you need to configure php to serve it. Therefore you can follow this official example.
If you want to serve also to www.example.com you can set server_name *.example.com (docs).

laravel project with nginx errors

I have upload my laravel project to remote linux host .This project works well on my local windows homestead.But when I put it on linux host,it does not work .
The project root is :/var/www/html/blog . the nginx config as follwing:
`server
{
listen 80;
#listen [::]:80;
server_name www.antichina.us ;
index index.html index.htm index.php default.html default.htm default.php;
root /var/www/html/blog/public;
# include other.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
`
when I visit the project with the domain,(http://mydomain),it give an http 500 error. but when I set the root as /var/www/html/blog in the nginx config file, the index page of the project is working by visit: http://mydomain/public, other routes are all return 404 error.
I have tried my method,but it seems none is working.Any on ecould help me?thank you !
Add this to your nginx config
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Your index line only needs to this also:
index index.php;
What's in this this file?
include enable-php.conf;

Resources