How to change file paths in an Angular app?

I am considering this sample Angular application .

There index.htmlare lines like

<script type="text/javascript" src="/static/angular.js"></script>

However, upon closer inspection, staticthere are no folders in the project .

How it works? How does Angular find these links?

+4
source share
3 answers

Angular has nothing to do with it. This is a server expressthat takes care of the paths. Take a look at server/config.js. You will see there staticUrl: '/static'.

server/server.js (server.js - script, , - , ), 21 require('./lib/routes/static').addRoutes(app, config);. static.js, /static ( config.js) , CSS javascript.

+1

HTML , HTTP- :

/static/angular.js

, static . Node.js Express , / .

, :

https://github.com/angular-app/angular-app/blob/master/server/config.js

:

staticUrl: '/static', // The base url from which we serve static files (such as js, css and images)

, /static :

distFolder: path.resolve(__dirname, '../client/dist'), // The folder that contains the application files (note that the files are in a different repository) - relative to this file

dist Grunt, grunt, grunt, .

https://github.com/angular-app/angular-app/blob/master/client/gruntFile.js

+1

. server/lib/routes/static.js:

: 9 app.use(config.server.staticUrl, express.static(config.server.distFolder));

What it is: if any HTTP request is started from config.server.staticUrl(whitch is /staticfor this application), the server tries to respond with the resource stored in the folder config.server.distFolder(which is the / dist client for this application).

For example: when you request this url /static/angular.js, the middleware tries to find the angular.jsfile in client/dist/. Because the directory client/distmaps to a URL starting with /staticmiddleware.

+1
source

All Articles