How to hide Angularjs source codes?

前端 未结 5 993
有刺的猬
有刺的猬 2021-02-02 00:36

How to hide app.js, controller.js files or code?

They are visible in html source. Is there anyway to hide them?

5条回答
  •  -上瘾入骨i
    2021-02-02 00:54

    You can hide your javascript code using NGINX server subrequest.

    If you have /admin route in angular, backbone or other js framework and you want to hide it for unauthorized users, you can make subrequest in NGINX to backend, which checks if user is authorized. If not, then you throw 404 or make redirect to homepage.

    This is nginx module which contains more details: http://nginx.org/en/docs/http/ngx_http_auth_request_module.html

    The code in NGINX looks more or less like this:

    location ^~ /admin {
        # checking in background if user is privileged
        auth_request /auth;
        root   /var/www/angular-client/;
    }
    
    location = /auth {
        proxy_pass http://backend.cms/api/v1/users/admin.json;
        proxy_set_header X-Original-URI http://backend.cms/api/v1/users/admin.json;/
    }
    

提交回复
热议问题