Files
freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/basic-node-and-express/serve-static-assets.chinese.md
Beau Carnes 6b1992ee7c fix: Add Api challenges - Chinese translation (#35164)
* fix: Add Api challenges - Chinese translation

* fix: md formatting

* fix: md formatting
2019-05-06 06:31:26 -05:00

42 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 587d7fb0367417b2b2512bf0
title: Serve Static Assets
localeTitle: 服务静态资产
challengeType: 2
---
## Description
<section id='description'>
HTML服务器通常有一个或多个用户可以访问的目录。您可以放置应用程序所需的静态资产样式表脚本图像。在Express中您可以使用中间件<code>express.static(path)</code>来实现此功能,其中参数是包含资产的文件夹的绝对路径。如果您不知道中间件是什么,请不要担心。我们稍后会详细讨论它。基本上,中间件是拦截路由处理程序,添加某种信息的函数。需要使用<code>app.use(path, middlewareFunction)</code>方法<code>app.use(path, middlewareFunction)</code> 。第一个路径参数是可选的。如果您没有通过它,将为所有请求执行中间件。 <code>0</code>使用<code>app.use()</code>为所有请求安装<code>express.static()</code>中间件。 assets文件夹的绝对路径是<code>__dirname + /public</code><code>0</code>现在您的应用应该能够提供CSS样式表。从公共文件夹外部将显示挂载到根目录。你的头版现在应该看起来好一点
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: 您的应用应该从<code>/public</code>目录提供资产文件
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/style.css'').then(data => { assert.match(data, /body\s*\{[^\}]*\}/, ''Your app does not serve static assets''); }, xhr => { throw new Error(xhr.responseText); })'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>