Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 2e54cb8

Browse files
committed
1. Server supports hot reloading
2. Improved performance 3. Server supports phar-archive (can be packed and work fine) 4. More elegant server usage in docker, with `server` global command 5. PID of master process can be saved to /var/run/server.pid if need (default behavior).
1 parent e7b1e1f commit 2e54cb8

36 files changed

+3649
-685
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ vendor/
44
example/vue-app/dist
55
.phpunit.result.cache
66
.DS_Store
7+
bin/server.phar

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
FROM roquie/composer-parallel
22

33
COPY . /app
4-
RUN composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader --ignore-platform-reqs
4+
5+
RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs \
6+
&& vendor/bin/box compile
57

68
FROM roquie/docker-swoole-webapp:php7.3-latest-brotli
79

8-
COPY --from=0 /app /srv/server
10+
COPY --from=0 /app/bin/server.phar /usr/bin/server
911
COPY --from=0 /app/dist /app
1012
COPY --from=0 /app/configuration /app/configuration
1113

14+
RUN chmod +x /usr/bin/server
15+
1216
EXPOSE 8080
1317
WORKDIR /app
1418

15-
ENTRYPOINT /srv/server/bin/static-server run
19+
ENTRYPOINT server run

README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ Server created for javascript SPA apps like: Vue, React, Angular, etc.
1919
* Corporate config standard supported by default and injected too.
2020
* Brotli-compression. Compression based on `Accept-Encoding` header. [More](#Compression).
2121
* Deny all `robots.txt` by default.
22+
* Hot reload
2223

2324
## Docker usage
2425

2526
```Dockerfile
26-
FROM microparts/static-server-php:1.1.4
27+
FROM microparts/static-server-php:1.2.0
2728

2829
COPY dist/ /app
2930
# frontend yaml configuration
@@ -43,22 +44,43 @@ CLI usage implies 2 commands for usage:
4344

4445
1) Start server:
4546
```bash
46-
bin/static-server run
47+
server run
4748
```
4849

4950
Result:
5051
```bash
51-
[2019-06-19 08:54:52] Server.INFO: CONFIG_PATH = /app/configuration
52-
[2019-06-19 08:54:52] Server.INFO: STAGE = dev
53-
[2019-06-19 08:54:52] Server.INFO: Configuration loaded.
54-
[2019-06-19 08:54:52] Server.INFO: Application state is: STAGE=dev SHA1=55b5293
55-
[2019-06-19 08:54:52] Server.INFO: HTTP static server started at 0.0.0.0:8080
52+
[2019-08-07 18:05:17] Server.INFO: State: STAGE=dev SHA1=55b5293 WORKERS=16 PID=10768 CONFIG_PATH=/app/configuration
53+
[2019-08-07 18:05:17] Server.INFO: Server started at 0.0.0.0:8080
5654
```
5755

56+
2) Reload
5857

59-
2) Dump loaded configuration:
58+
After editing files or configuration you can reload server without restart master process.
59+
60+
```bash
61+
server reload
62+
```
63+
64+
Reload command result:
65+
```bash
66+
[2019-08-07 18:07:00] Reload.INFO: CONFIG_PATH = /app/configuration
67+
[2019-08-07 18:07:00] Reload.INFO: STAGE = dev
68+
[2019-08-07 18:07:00] Reload.INFO: Configuration loaded.
69+
70+
Server reloaded
71+
```
72+
73+
Server result:
74+
```bash
75+
[2019-08-07 18:05:17] Server.INFO: State: STAGE=dev SHA1=55b5293 WORKERS=16 PID=10768 CONFIG_PATH=/app/configuration
76+
[2019-08-07 18:05:17] Server.INFO: Server started at 0.0.0.0:8080
77+
[2019-08-07 21:07:00 $10889.0] INFO Server is reloading all workers now
78+
```
79+
80+
81+
3) Dump loaded configuration:
6082
```bash
61-
bin/static-server dump
83+
server dump
6284
```
6385

6486
Result:
@@ -105,6 +127,9 @@ server:
105127
worker_num: 4
106128
log_level: 0
107129
buffer_output_size: 33554432
130+
pid:
131+
location: /var/run/server.pid
132+
save: true
108133
mimes:
109134
map: application/json
110135
xml: application/xml
@@ -150,13 +175,13 @@ server:
150175
- autoplay 'none'
151176
referer_policy: no-referrer
152177
pragma: public
153-
cache_control: public, must-revalidate, proxy-revalidate, max-age=31536000
178+
cache_control: public, must-revalidate, proxy-revalidate, max-age=604800
154179
frame_options: sameorigin
155180
xss_protection: 1; mode=block
156181
x_content_type: nosniff
157182
x_content_type_options: nosniff
158183
x_ua_compatible: IE=edge
159-
sts: 'max-age=31536000; includeSubDomains; preload'
184+
sts: 'max-age=604800; includeSubDomains; preload'
160185
```
161186

162187
Comments about server configuration can be found [here](./configuration/defaults).
@@ -186,7 +211,7 @@ Also, will be injected `<link>` tag with `rel=preload`. [More](https://developer
186211
By default will be added following headers to response:
187212
```http
188213
Pragma: public
189-
Cache-Control: public, must-revalidate, proxy-revalidate, max-age=31536000
214+
Cache-Control: public, must-revalidate, proxy-revalidate, max-age=604800
190215
X-XSS-Protection: 1; mode=block
191216
X-Frame-Options: SAMEORIGIN
192217
X-Content-Type: nosniff
@@ -195,7 +220,7 @@ X-Ua-Compatible: IE=edge
195220
Referrer-Policy: no-referrer
196221
Feature-Policy: geolocation 'none'; payment 'none'; microphone 'none'; camera 'none'; autoplay 'none'
197222
Content-Security-Policy: default-src 'self'; script-src 'self' cdnjs.cloudflare.com; img-src 'self' data:; style-src 'self' 'unsafe-inline' fonts.googleapis.com cdnjs.cloudflare.com; font-src 'self' data: fonts.gstatic.com cdnjs.cloudflare.com; form-action 'self'
198-
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
223+
Strict-Transport-Security: max-age=604800; includeSubDomains; preload
199224
```
200225

201226
`A+` rating issued by the site https://securityheaders.com.
@@ -228,7 +253,7 @@ And it edit in accordance with business logic of application.
228253
229254
### Link header
230255
231-
As new feature since `1.1.4` version you able to use `Link` header
256+
As new feature since `1.2.0` version you able to use `Link` header
232257
for server configuration.
233258

234259
* How it use for `<link rel=preload>` requirements (lighthouse), – https://w3c.github.io/preload/#example-3 , https://w3c.github.io/preload/#example-6

bin/static-server renamed to bin/server

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?php
33

44
use StaticServer\Console\DumpConfigCommand;
5+
use StaticServer\Console\ReloadServerCommand;
56
use StaticServer\Console\RunServerCommand;
67
use Symfony\Component\Console\Application;
78

@@ -18,7 +19,8 @@ foreach ($locations as $file) {
1819
}
1920
}
2021

21-
$app = new Application('Static server', '1.0.3');
22+
$app = new Application('Static server', '1.2.0');
2223
$app->add(new RunServerCommand());
2324
$app->add(new DumpConfigCommand());
25+
$app->add(new ReloadServerCommand());
2426
$app->run();

box.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"output": "bin/server.phar",
3+
"main": "bin/server"
4+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"roave/security-advisories": "dev-master",
2323
"eaglewu/swoole-ide-helper": "dev-master",
2424
"symfony/var-dumper": "^4",
25-
"phpunit/phpunit": "^8"
25+
"phpunit/phpunit": "^8",
26+
"humbug/box": "^3.8"
2627
},
2728
"autoload": {
2829
"psr-4": {

0 commit comments

Comments
 (0)