Category: Node js

 

Solution on Error [WDS] Disconnected! angular

Solution on Error [WDS] Disconnected! angular
By ng serve —disable-host-check worked for me…


client?bf7e:146 [WDS] Disconnected!
close @ client?bf7e:146
sock.onclose @ socket.js:15
webpackJsonp.../../../../sockjs-client/lib/event/eventtarget.js.EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:356
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:425
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask @ zone.js:192
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:499
ZoneTask.invoke @ zone.js:488
timer @ zone.js:2040
setTimeout (async)
scheduleTask @ zone.js:2056
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:411
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:236
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.scheduleMacroTask @ zone.js:259
----

Solution
1- Configure Nginx….

on Ubuntu, add the next code on default.conf
/etc/nginx/conf.g/default.conf


 location /sockjs-node/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        rewrite ^/(.*)$  /$1  break;
        proxy_set_header Host localhost;
        proxy_pass http://localhost:1355/;
    }

2- And to server ng add the option –public-host=httpfake://0.0.0.0/

sudo forever start node_modules/@angular/cli/bin/ng serve -w –port 1355 –live-reload 1356 –aot –env=prod –public-host=httpfake://0.0.0.0/


How to keep ng serve, angular running on production server on ubuntu using nginx as website server

How to keep ng serve, angular running on production server on ubuntu using nginx as website server

Solution 1

$ sh -c ng serve -w –port 1355 –live-reload 1356 –aot –env=prod “/home/ubuntu/project/ukgoodbye/”

Solution 2

$ forever start node_modules/@angular/cli/bin/ng serve -w –port 1355 –live-reload 1356 –aot –env=prod “/home/ubuntu/project/ukgoodbye/”


sudo forever start node_modules/@angular/cli/bin/ng serve -w --port 1355 --live-reload 1356 --aot --env=prod 
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: node_modules/@angular/cli/bin/ng

Check the log:
$ nano -v /home/ubuntu/.forever/dfyn.log

sudo forever start –watch app.js that will run sails lift

Nginx configuration location on AWS ubuntu, /etc/nginx/nginx.conf

Nginx configuration location on AWS ubuntu, /etc/nginx/nginx.conf

Here an example of nginx.conf


user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
          ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

         gzip_vary on;
          gzip_proxied any;
         gzip_comp_level 9;
         gzip_buffers 16 8k;
         gzip_http_version 1.1;
         gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text$

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

It says that it include sites-enabled/*. cd /etc/nginx/sites-enabled/ to find out, www.ukgoodbye.co.uk

Content of the enabled site:


....
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        # listen 80 default_server;
        # listen [::]:80 default_server;

        # SSL configuration
        #
        listen 443;
        listen [::]:443;

        ssl on;
        ssl_certificate /etc/nginx/ssl/ssl_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/ukgoodbye_com.key;

        ssl_dhparam /etc/nginx/ssl/dhparam.pem;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        #
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name www.ukgoodbye.co.uk;


        location / {
                #rewrite ^/ukgoodbye(.*) $1 break;
                #add_header "Access-Control-Allow-Origin" "*, *";
                proxy_pass http://127.0.0.1:1355;
        }
        location /ukgoodbye-services/ {
                rewrite ^/ukgoodbye-services(.*) $1 break;
                #add_header "Access-Control-Allow-Origin" "*, *";
                proxy_pass http://127.0.0.1:1337;
        }

#       location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
#               try_files $uri $uri/ =404;
#       }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
server {
        listen 80;
        listen [::]:80;
        # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
        return 301 https://$host$request_uri;
        server_name www.ukgoodbye.co.uk;

#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
}

Angular 2 Remove Hash (#) from the URL,use theme cleanui-admin-template-angular

Angular 2 Remove Hash (#) from the URL,use theme cleanui-admin-template-angular

Example from the localhost, http://localhost:4200/#
Step 1: Modify the on Theme\cleanui-admin-template-angular\src\app\app.routing.ts, to next line

export const routing: ModuleWithProviders = RouterModule.forRoot(routes, { useHash: true });

to

export const routing: ModuleWithProviders = RouterModule.forRoot(routes);

Step 2: Add this code to index.html
Add this on file Theme\cleanui-admin-template-angular\src\index.html
….

<base href=”/”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>

….

sails lift, error: A hook (`userconfig`) failed to load!

sails lift, error: A hook (`userconfig`) failed to load!, and solution


C:\Users\Windows10HP\MySailsProject>lift

sails lift

 info: Starting app...

 info: No local Sails install detected; using globally-installed Sails.
error: A hook (`userconfig`) failed to load!
error:
error: Attempted to `require('C:\Users\Windows10HP\MySailsProject\config\http.js')`, but an error occurred:
--
Error: Cannot find module 'passport'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object. (C:\Users\Windows10HP\MySailsProject\config\http.js:32:23)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at C:\Users\Windows10HP\AppData\Roaming\npm\node_modules\sails\node_modules\include-all\lib\help-include-all-sync.js:293:33
    at Array.forEach ()
    at _recursivelyIncludeAll (C:\Users\Windows10HP\AppData\Roaming\npm\node_modules\sails\node_modules\include-all\lib\help-include-all-sync.js:178:11)
    at includeAll (C:\Users\Windows10HP\AppData\Roaming\npm\node_modules\sails\node_modules\include-all\lib\help-include-all-sync.js:317:5)
--

error: Could not load Sails app.
error:
error: Tips:
error:  • First, take a look at the error message above.
error:  • Make sure you've installed dependencies with `npm install`.
error:  • Check that this app was built for a compatible version of Sails.
error:  • Have a question or need help?  (http://sailsjs.com/support)

Solution: error: A hook (`userconfig`) failed to load

1- Make sure that sails npm is installed with dependencies with npm install, to do install npm gobally


>nmpnpm install sails -g

After that, installed the mongodb because the project use mongodb and it is not installed.


>npm install mongodb

After installed mongodb, tried again to run Sails, by sails lift and now is working et voilà!


>sails lift


 info: Starting app...

MongoService url====
mongodb://localhost:27017/ukgoodbye
(node:8624) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:8624) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
MongoService:connect err
null
MongoService:connect successfully
info:
info:                .-..-.
info:
info:    Sails              <|    .-..-.
info:    v0.12.14            |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------'
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info:
info: Server lifted in `C:\Users\Windows10HP\ukgoodbye2`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press  + C at any time.

debug: -------------------------------------------------------
debug: :: Wed Sep 25 2019 19:05:29 GMT+0100 (British Summer Time)

debug: Environment : development
debug: Port        : 1337