2019-05-06 07:31:26 -04:00
|
|
|
|
---
|
|
|
|
|
id: bd7158d8c443edefaeb5bdff
|
2021-02-16 13:01:20 -08:00
|
|
|
|
title: 请求头解析器微服务
|
2019-05-06 07:31:26 -04:00
|
|
|
|
challengeType: 4
|
2020-09-18 00:11:18 +08:00
|
|
|
|
forumTopicId: 301507
|
2021-01-13 03:31:00 +01:00
|
|
|
|
dashedName: request-header-parser-microservice
|
2019-05-06 07:31:26 -04:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
|
|
|
|
|
2021-09-18 11:22:53 -07:00
|
|
|
|
构建一个 JavaScript 的全栈应用,在功能上与这个应用相似:<https://request-header-parser-microservice.freecodecamp.rocks/>。 在这个项目中,你将使用以下方法之一编写你的代码:
|
2019-05-06 07:31:26 -04:00
|
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
|
- 克隆 [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-headerparser/) 并在本地完成项目。
|
2021-05-12 21:25:58 +05:30
|
|
|
|
- 使用[我们的 Replit 初始化项目](https://replit.com/github/freeCodeCamp/boilerplate-project-headerparser)来完成你的项目。
|
2021-09-18 11:22:53 -07:00
|
|
|
|
- 使用你选择的网站生成器来完成项目。 需要包含我们 GitHub 仓库的所有文件。
|
2019-05-06 07:31:26 -04:00
|
|
|
|
|
2021-09-18 11:22:53 -07:00
|
|
|
|
完成本项目后,请将一个正常运行的 demo(项目演示)托管在可以公开访问的平台。 然后在 `Solution Link` 字段中提交它的 URL。 此外,还可以将项目的源码提交到 `GitHub Link` 中。
|
2019-05-06 07:31:26 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2019-05-06 07:31:26 -04:00
|
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
|
提交自己的项目,而不是示例的 URL。
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
(getUserInput) => {
|
|
|
|
|
assert(
|
|
|
|
|
!/.*\/request-header-parser-microservice\.freecodecamp\.rocks/.test(
|
|
|
|
|
getUserInput('url')
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
|
向 `/api/whoami` 发送请求,返回一个 JSON 对象,这个JSON 对象应该含有存放 IP 地址的 `ipaddress` 键中。
|
2019-05-06 07:31:26 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
(getUserInput) =>
|
|
|
|
|
$.get(getUserInput('url') + '/api/whoami').then(
|
|
|
|
|
(data) => assert(data.ipaddress && data.ipaddress.length > 0),
|
|
|
|
|
(xhr) => {
|
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
|
}
|
|
|
|
|
);
|
2019-05-06 07:31:26 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
|
向 `/api/whoami` 发送请求,返回一个 JSON 对象,这个 JSON 对象应该含有存放语言首选项的 `language` 键。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
(getUserInput) =>
|
|
|
|
|
$.get(getUserInput('url') + '/api/whoami').then(
|
|
|
|
|
(data) => assert(data.language && data.language.length > 0),
|
|
|
|
|
(xhr) => {
|
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
|
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
|
向 `/api/whoami` 发送请求,返回一个 JSON 对象,这个 JSON 对象应该含有存放(发送请求的)软件的 `software` 键。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
(getUserInput) =>
|
|
|
|
|
$.get(getUserInput('url') + '/api/whoami').then(
|
|
|
|
|
(data) => assert(data.software && data.software.length > 0),
|
|
|
|
|
(xhr) => {
|
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
```js
|
|
|
|
|
/**
|
|
|
|
|
Backend challenges don't need solutions,
|
|
|
|
|
because they would need to be tested against a full working project.
|
|
|
|
|
Please check our contributing guidelines to learn more.
|
|
|
|
|
*/
|
|
|
|
|
```
|