SpaceX上的Javascript 这下面试造火箭没准真就去造火箭了

在上个月SpaceX 成功发射了载人火箭Dragon 2,其中的飞行界面就是由ChromiumJavaScript进行构建的,当然只有图形界面是,系统的其他部分还是由c++来完成的。

Also, only the actual graphical display application uses Chromium/JS. The rest of the system is all C++. The display code has 100% test coverage, down to validation of graphical output (for example if you have a progress bar and you set it to X% the tests verify that it is actually drawn correctly).

不知道会不会出现氧气剩余 NaN%着陆地点undefined

undefined

火箭的操作界面估计是不会开源了,但是SpaceX-API倒是在GitHub上开源了。

阿波罗登月的代码之后又参与了SpaceX-API review,以后面试问我参与过什么项目就可以说参与过阿波罗登月计划SpaceX 载人航天计划code review。感觉准备个PPT可以去融资了。

什么是SpaceX-API

SpaceX-API 是一个用于火箭、核心舱、太空舱、发射台和发射数据的开源 REST API。

接口文档展示了所提供的 API接口,还包括多种语言的接口调用。

比如dragons的信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
[
{
"id": "dragon1",
"name": "Dragon 1",
"type": "capsule",
"active": true,
"crew_capacity": 0,
"sidewall_angle_deg": 15,
"orbit_duration_yr": 2,
"dry_mass_kg": 4200,
"dry_mass_lb": 9300,
"first_flight": "2010-12-8",
"heat_shield": {
"material": "PICA-X",
"size_meters": 3.6,
"temp_degrees": 3000,
"dev_partner": "NASA"
},
"thrusters": [
{
"type": "Draco",
"amount": 18,
"pods": 4,
"fuel_1": "nitrogen tetroxide",
"fuel_2": "monomethylhydrazine",
"thrust": {
"kN": 0.4,
"lbf": 90
}
}
],
"launch_payload_mass": {
"kg": 6000,
"lb": 13228
},
"launch_payload_vol": {
"cubic_meters": 25,
"cubic_feet": 883
},
"return_payload_mass": {
"kg": 3000,
"lb": 6614
},
"return_payload_vol": {
"cubic_meters": 11,
"cubic_feet": 388
},
"pressurized_capsule": {
"payload_volume": {
"cubic_meters": 11,
"cubic_feet": 388
}
},
"trunk": {
"trunk_volume": {
"cubic_meters": 14,
"cubic_feet": 494
},
"cargo": {
"solar_array": 2,
"unpressurized_cargo": true
}
},
"height_w_trunk": {
"meters": 7.2,
"feet": 23.6
},
"diameter": {
"meters": 3.7,
"feet": 12
},
"wikipedia": "https://en.wikipedia.org/wiki/SpaceX_Dragon",
"description": "Dragon is a reusable spacecraft developed by SpaceX, an American private space transportation company based in Hawthorne, California. Dragon is launched into space by the SpaceX Falcon 9 two-stage-to-orbit launch vehicle. The Dragon spacecraft was originally designed for human travel, but so far has only been used to deliver cargo to the International Space Station (ISS)."
},
{
"id": "dragon2",
"name": "Dragon 2",
"type": "capsule",
"active": false,
"crew_capacity": 7,
"sidewall_angle_deg": 15,
"orbit_duration_yr": 2,
"dry_mass_kg": 6350,
"dry_mass_lb": 14000,
"first_flight": null,
"heat_shield": {
"material": "PICA-X",
"size_meters": 3.6,
"temp_degrees": 3000,
"dev_partner": "NASA"
},
"thrusters": [
{
"type": "Draco",
"amount": 18,
"pods": 4,
"fuel_1": "nitrogen tetroxide",
"fuel_2": "monomethylhydrazine",
"thrust": {
"kN": 0.4,
"lbf": 90
}
},
{
"type": "SuperDraco",
"amount": 8,
"pods": 4,
"fuel_1": "dinitrogen tetroxide",
"fuel_2": "monomethylhydrazine",
"thrust": {
"kN": 71,
"lbf": 16000
}
}
],
"launch_payload_mass": {
"kg": 6000,
"lb": 13228
},
"launch_payload_vol": {
"cubic_meters": 25,
"cubic_feet": 883
},
"return_payload_mass": {
"kg": 3000,
"lb": 6614
},
"return_payload_vol": {
"cubic_meters": 11,
"cubic_feet": 388
},
"pressurized_capsule": {
"payload_volume": {
"cubic_meters": 11,
"cubic_feet": 388
}
},
"trunk": {
"trunk_volume": {
"cubic_meters": 14,
"cubic_feet": 494
},
"cargo": {
"solar_array": 2,
"unpressurized_cargo": true
}
},
"height_w_trunk": {
"meters": 7.2,
"feet": 23.6
},
"diameter": {
"meters": 3.7,
"feet": 12
},
"wikipedia": "https://en.wikipedia.org/wiki/Dragon_2",
"description": "Dragon 2 (also Crew Dragon, Dragon V2, or formerly DragonRider) is the second version of the SpaceX Dragon spacecraft, which will be a human-rated vehicle. It includes a set of four side-mounted thruster pods with two SuperDraco engines each, which can serve as a launch escape system or launch abort system (LAS). In addition, it has much larger windows, new flight computers and avionics, and redesigned solar arrays, and a modified outer mold line from the initial cargo Dragon that has been flying for several years."
}
]

其中使用的技术栈:

  1. 后台框架使用的是 Koa

  2. 内容缓存使用的是 RedisNginxCloudflare

  3. 测试使用的是 JestSupertest

  4. 使用 Circle CI 进行持续集成/部署。

  5. 数据库使用的是 *MongoDB *

本地部署

  1. 首先clone项目

    1
    git clone https://github.com/r-spacex/SpaceX-API.git && cd SpaceX-API
  2. 安装并启动MongoDB数据库

  3. 安装依赖

    1
    npm i

    or

    1
    yarn
  4. 运行测试

    1
    npm test
  5. 启动

    1
    npm start

    or

    1
    yarn start

使用Docker部署

当然也可以使用Docker来进行部署:

1
2
3
git clone https://github.com/r-spacex/SpaceX-API.git && cd SpaceX-API
docker-compose build
docker-compose up

总结

虽然这个项目不是真的造火箭,但好歹也能吹吹牛逼。而且代码质量和工程结构都可以学习学习。

复制粘贴一把梭

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×