@kirschbaum-development/sst-laravel 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/docs/api.md +13 -0
- package/laravel-sst.ts +31 -36
- package/package.json +1 -1
- package/src/load-balancer.ts +60 -0
package/README.md
CHANGED
|
@@ -103,6 +103,21 @@ const app = new LaravelService('MyLaravelApp', {
|
|
|
103
103
|
|
|
104
104
|
All [`loadBalancer.health` options](https://sst.dev/docs/component/aws/service/#loadbalancer-health) are supported (`interval`, `timeout`, `healthyThreshold`, `unhealthyThreshold`, `successCodes`). If you set `web.loadBalancer` explicitly, `healthCheck` is ignored — configure `loadBalancer.health` directly there.
|
|
105
105
|
|
|
106
|
+
#### HTTP to HTTPS redirect
|
|
107
|
+
|
|
108
|
+
When you configure a `domain` (which provisions an SSL certificate and an HTTPS listener), HTTP (port 80) traffic is redirected to HTTPS (port 443) by default. To keep forwarding HTTP traffic straight to your application instead, set `httpsRedirect: false`:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
const app = new LaravelService('MyLaravelApp', {
|
|
112
|
+
web: {
|
|
113
|
+
domain: { name: 'app.example.com' },
|
|
114
|
+
httpsRedirect: false,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This has no effect when no `domain` is set, or when you provide an explicit `web.loadBalancer` (configure `loadBalancer.ports` yourself in that case).
|
|
120
|
+
|
|
106
121
|
### Reverb
|
|
107
122
|
|
|
108
123
|
You can deploy a dedicated Laravel Reverb service for WebSocket traffic. Reverb runs as a worker-style container using `php artisan reverb:start`, but SST Laravel also attaches a load balancer so you can give it its own public domain.
|
package/docs/api.md
CHANGED
|
@@ -279,6 +279,19 @@ web: {
|
|
|
279
279
|
}
|
|
280
280
|
```
|
|
281
281
|
|
|
282
|
+
#### `web.httpsRedirect`
|
|
283
|
+
- **Type:** `boolean`
|
|
284
|
+
- **Default:** `true`
|
|
285
|
+
- **Description:** When a `domain` is configured, redirect HTTP (port 80) traffic to the HTTPS (port 443) listener instead of forwarding it straight to the application. Set to `false` to keep forwarding HTTP traffic to the app. Has no effect when no `domain` is set (there is no HTTPS listener to redirect to) or when an explicit `loadBalancer` is provided.
|
|
286
|
+
|
|
287
|
+
**Example:**
|
|
288
|
+
```typescript
|
|
289
|
+
web: {
|
|
290
|
+
domain: { name: 'app.example.com' },
|
|
291
|
+
httpsRedirect: false,
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
282
295
|
#### `web.executionRole`
|
|
283
296
|
- **Type:** `ServiceArgs["executionRole"]`
|
|
284
297
|
- **Description:** Execution role for the web service.
|
package/laravel-sst.ts
CHANGED
|
@@ -27,18 +27,11 @@ import { getPackagePath } from './src/config';
|
|
|
27
27
|
import { RemoteEnvFile } from './src/remote-env-file';
|
|
28
28
|
import { buildReverbEnvironmentVariables } from './src/reverb';
|
|
29
29
|
import { getSecretsFingerprint } from './src/secrets-manager';
|
|
30
|
+
import { buildDefaultPublicPorts, Port } from './src/load-balancer';
|
|
30
31
|
|
|
31
32
|
// Re-export RemoteEnvVault for external use
|
|
32
33
|
export { RemoteEnvVault, RemoteEnvVaultArgs };
|
|
33
34
|
|
|
34
|
-
// duplicate from cluster.ts
|
|
35
|
-
type Port = `${number}/${'http' | 'https' | 'tcp' | 'udp' | 'tcp_udp' | 'tls'}`;
|
|
36
|
-
|
|
37
|
-
type Ports = {
|
|
38
|
-
listen: Port;
|
|
39
|
-
forward: Port;
|
|
40
|
-
}[];
|
|
41
|
-
|
|
42
35
|
enum ImageType {
|
|
43
36
|
Web = 'web',
|
|
44
37
|
Worker = 'worker',
|
|
@@ -198,6 +191,27 @@ export interface LaravelWebArgs extends LaravelServiceArgs {
|
|
|
198
191
|
* ```
|
|
199
192
|
*/
|
|
200
193
|
healthCheck?: Input<LaravelHealthCheck>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* When a `domain` is configured, redirect HTTP (port 80) traffic to the
|
|
197
|
+
* HTTPS (port 443) listener instead of forwarding it straight to the
|
|
198
|
+
* application. Set to `false` to keep forwarding HTTP traffic to the app.
|
|
199
|
+
*
|
|
200
|
+
* Has no effect when no `domain` is set (there is no HTTPS listener to
|
|
201
|
+
* redirect to) or when an explicit `loadBalancer` is provided (configure
|
|
202
|
+
* `loadBalancer.ports` yourself in that case).
|
|
203
|
+
*
|
|
204
|
+
* @default `true`
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```js
|
|
208
|
+
* web: {
|
|
209
|
+
* domain: 'example.com',
|
|
210
|
+
* httpsRedirect: false,
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
httpsRedirect?: boolean;
|
|
201
215
|
}
|
|
202
216
|
|
|
203
217
|
export interface LaravelReverbArgs extends LaravelServiceArgs {
|
|
@@ -473,9 +487,11 @@ export class LaravelService extends Component {
|
|
|
473
487
|
? args.web.loadBalancer
|
|
474
488
|
: {
|
|
475
489
|
domain: args.web?.domain,
|
|
476
|
-
ports:
|
|
477
|
-
args.web?.domain,
|
|
478
|
-
|
|
490
|
+
ports: buildDefaultPublicPorts({
|
|
491
|
+
hasDomain: Boolean(args.web?.domain),
|
|
492
|
+
httpsRedirect:
|
|
493
|
+
args.web?.httpsRedirect ?? true,
|
|
494
|
+
}),
|
|
479
495
|
...(args.web?.healthCheck
|
|
480
496
|
? {
|
|
481
497
|
health: {
|
|
@@ -645,10 +661,10 @@ export class LaravelService extends Component {
|
|
|
645
661
|
name: 'reverb',
|
|
646
662
|
loadBalancer: reverbConfig.loadBalancer ?? {
|
|
647
663
|
domain: reverbConfig.domain,
|
|
648
|
-
ports:
|
|
649
|
-
reverbConfig.domain,
|
|
650
|
-
reverbConfig.port,
|
|
651
|
-
),
|
|
664
|
+
ports: buildDefaultPublicPorts({
|
|
665
|
+
hasDomain: Boolean(reverbConfig.domain),
|
|
666
|
+
forwardPort: reverbConfig.port,
|
|
667
|
+
}),
|
|
652
668
|
health: {
|
|
653
669
|
[reverbPort]: {
|
|
654
670
|
path: '/apps',
|
|
@@ -728,27 +744,6 @@ export class LaravelService extends Component {
|
|
|
728
744
|
};
|
|
729
745
|
}
|
|
730
746
|
|
|
731
|
-
function getDefaultPublicPorts(
|
|
732
|
-
domain?: LaravelDomain,
|
|
733
|
-
forwardPortNumber = 8080,
|
|
734
|
-
): Ports {
|
|
735
|
-
let ports;
|
|
736
|
-
const forwardPort: Port = `${forwardPortNumber}/http`;
|
|
737
|
-
const portHttp: Port = '80/http';
|
|
738
|
-
const portHttps: Port = '443/https';
|
|
739
|
-
|
|
740
|
-
if (domain) {
|
|
741
|
-
ports = [
|
|
742
|
-
{ listen: portHttp, forward: forwardPort },
|
|
743
|
-
{ listen: portHttps, forward: forwardPort },
|
|
744
|
-
];
|
|
745
|
-
} else {
|
|
746
|
-
ports = [{ listen: portHttp, forward: forwardPort }];
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
return ports;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
747
|
// TODO: We have to test if it works when a custom image is provided in sst.config.js
|
|
753
748
|
function getImage(imgType: ImageType, extraArgs: object = {}) {
|
|
754
749
|
const img = getDefaultImage(imgType, extraArgs);
|
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type Port = `${number}/${'http' | 'https' | 'tcp' | 'udp' | 'tcp_udp' | 'tls'}`;
|
|
2
|
+
|
|
3
|
+
export type Ports = {
|
|
4
|
+
listen: Port;
|
|
5
|
+
forward?: Port;
|
|
6
|
+
redirect?: Port;
|
|
7
|
+
}[];
|
|
8
|
+
|
|
9
|
+
export interface DefaultPublicPortsOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether a custom domain (and therefore an HTTPS listener) is configured.
|
|
12
|
+
*/
|
|
13
|
+
hasDomain: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Container port the load balancer forwards application traffic to.
|
|
17
|
+
*
|
|
18
|
+
* @default 8080
|
|
19
|
+
*/
|
|
20
|
+
forwardPort?: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* When a domain is configured, redirect the HTTP (port 80) listener to the
|
|
24
|
+
* HTTPS (port 443) listener instead of forwarding it to the application.
|
|
25
|
+
* Ignored when no domain is configured, since there is no HTTPS listener to
|
|
26
|
+
* redirect to.
|
|
27
|
+
*
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
httpsRedirect?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Builds the default load balancer port mapping for a public service.
|
|
35
|
+
*
|
|
36
|
+
* Without a domain, only an HTTP listener is created (forwarding to the app).
|
|
37
|
+
* With a domain, both HTTP and HTTPS listeners are created; the HTTP listener
|
|
38
|
+
* redirects to HTTPS by default, or forwards to the app when
|
|
39
|
+
* `httpsRedirect` is disabled.
|
|
40
|
+
*/
|
|
41
|
+
export function buildDefaultPublicPorts({
|
|
42
|
+
hasDomain,
|
|
43
|
+
forwardPort = 8080,
|
|
44
|
+
httpsRedirect = true,
|
|
45
|
+
}: DefaultPublicPortsOptions): Ports {
|
|
46
|
+
const forward: Port = `${forwardPort}/http`;
|
|
47
|
+
const portHttp: Port = '80/http';
|
|
48
|
+
const portHttps: Port = '443/https';
|
|
49
|
+
|
|
50
|
+
if (!hasDomain) {
|
|
51
|
+
return [{ listen: portHttp, forward }];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return [
|
|
55
|
+
httpsRedirect
|
|
56
|
+
? { listen: portHttp, redirect: portHttps }
|
|
57
|
+
: { listen: portHttp, forward },
|
|
58
|
+
{ listen: portHttps, forward },
|
|
59
|
+
];
|
|
60
|
+
}
|