簡體   English   中英

需要全棧JavaScript路由說明

[英]Full stack javascript routing explanation needed

我使用yeoman和Angular Fullstack生成器搭建了一個全棧Mongo,Express,Angular,Node應用程序

它創建了一個server / app.js文件,該文件執行一個route.js來處理快遞服務器提供的資源。

route.js的內容如下所示:

  // Insert routes below
  app.use('/api/things', require('./api/thing'));
  app.use('/api/users', require('./api/user'));

  app.use('/auth', require('./auth'));

  // All undefined asset or api routes should return a 404
  app.route('/:url(api|auth|components|app|bower_components|assets)/*')
   .get(errors[404]);

  // All other routes should redirect to the index.html
  app.route('/*')
    .get(function(req, res) {
      res.sendfile(app.get('appPath') + '/index.html');
    });

我的問題是如何將除index.html之外的任何文件提供給瀏覽器。 我已經測試過,例如文件“ http:// localhost:9000 / assets / images / yeoman.png ”確實返回到瀏覽器。 但是如何? 根據我在routes.js中閱讀的內容,對該png的請求返回index.html的文本

我對此感到有些困惑,非常感謝您的解釋。

謝謝!

如果進入config / express.js,您將看到類似以下內容:

    app.use(express.static(path.join(config.root, 'public')));

這應該是不言自明的。

UPD。 使用路由,您可以覆蓋特定文件的此行為(如果確實需要)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM