Score:0

Ngnix + django +nodejs : Uncaught SyntaxError: Unexpected token '<'

in flag

This is first time using nginx and nodejs. I have two apps one is built using django and other is built using nodejs (expressjs +openvidu). I am trying to configure nginx, django app works fine, I am having trouble with nodejs. nginx is not serving js files. I am getting the below error in console,(I suspect it is because browser is not able to find JavaScript file) both of my js files present under public folder.

Uncaught SyntaxError: Unexpected token '<'

Could you also suggest me if this is not the proper way to deploy django and nodejs

Below is my nginx configuration. /meeting is the node app.

 server {

  server_name sophie.ovgu.de;

  location /meeting {
    proxy_pass https://localhost:5000;
    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 /videoapp {
    proxy_pass http://unix:/run/gunicorn.sock;
    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;
   }


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/sophie.ovgu.de/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/sophie.ovgu.de/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = sophie.ovgu.de) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


  listen 80;
  listen [::]:80;

  server_name sophie.ovgu.de;
    return 404; # managed by Certbot


}

Please note "proxy_pass https://localhost:5000" this should be https as openvidu server requires it. Please refer this link

This is my folder structure

├───node_modules
├───public
│     app.js
│     openvidu-browser-2.18.0.js   
│───views
        index.ejs
│   openviducert.pem
│   openvidukey.pem
│   package-lock.json
│   package.json
│   README.md
│   server.js

This is how I am calling js file in index.html

>       <script src="/openvidu-browser-2.18.0.js"></script>
>       <script src="/app.js"></script>
>       <script>
Michael Hampton avatar
cz flag
Where is your `root` directive?
djdomi avatar
za flag
@MichaelHampton its using reverse-proxy for what should a root be used? I bet there is some "<" misspelled
Michael Hampton avatar
cz flag
@djdomi For service of static content. The OP appears to have forgotten to look at the Network tab and see that he has received some 4xx error and checked to see what it was and where it came from.
Raviteja Sutrave avatar
in flag
I am sorry I am on vacation. "Uncaught SyntaxError: Unexpected token '<'" is because the browser is not able to find .js file (https://stackoverflow.com/a/43781649/7359052) app.js and openvidu-browser-2.18.0.js in my case. For some reason it is not able to find javascript file under public folder. The nodeapp is working, if I use it without nginx
Michael Hampton avatar
cz flag
When you return from vacation, go back to read the very first comment.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.