|
1 | 1 | # Configuration |
2 | 2 |
|
3 | | -_This is just an example of the ts-cloud docs._ |
4 | | - |
5 | | -The Reverse Proxy can be configured using a `reverse-proxy.config.ts` _(or `reverse-proxy.config.js`)_ file and it will be automatically loaded when running the `reverse-proxy` command. |
6 | | - |
7 | | -```ts |
8 | | -// reverse-proxy.config.{ts,js} |
9 | | -import type { ReverseProxyOptions } from '@stacksjs/rpx' |
10 | | -import os from 'node:os' |
11 | | -import path from 'node:path' |
12 | | - |
13 | | -const config: ReverseProxyOptions = { |
14 | | - /** |
15 | | - * The from URL to proxy from. |
16 | | - * Default: localhost:5173 |
17 | | - */ |
18 | | - from: 'localhost:5173', |
19 | | - |
20 | | - /** |
21 | | - * The to URL to proxy to. |
22 | | - * Default: stacks.localhost |
23 | | - */ |
24 | | - to: 'stacks.localhost', |
25 | | - |
26 | | - /** |
27 | | - * The HTTPS settings. |
28 | | - * Default: true |
29 | | - * If set to false, the proxy will use HTTP. |
30 | | - * If set to true, the proxy will use HTTPS. |
31 | | - * If set to an object, the proxy will use HTTPS with the provided settings. |
32 | | - */ |
33 | | - https: { |
34 | | - domain: 'stacks.localhost', |
35 | | - hostCertCN: 'stacks.localhost', |
36 | | - caCertPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.ca.crt`), |
37 | | - certPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.crt`), |
38 | | - keyPath: path.join(os.homedir(), '.stacks', 'ssl', `stacks.localhost.crt.key`), |
39 | | - altNameIPs: ['127.0.0.1'], |
40 | | - altNameURIs: ['localhost'], |
41 | | - organizationName: 'stacksjs.com', |
42 | | - countryName: 'US', |
43 | | - stateName: 'California', |
44 | | - localityName: 'Playa Vista', |
45 | | - commonName: 'stacks.localhost', |
46 | | - validityDays: 180, |
47 | | - verbose: false, |
| 3 | +ts-cloud uses a `cloud.config.ts` file to define your infrastructure. |
| 4 | + |
| 5 | +## Basic Configuration |
| 6 | + |
| 7 | +Create a `cloud.config.ts` in your project root: |
| 8 | + |
| 9 | +```typescript |
| 10 | +import type { CloudConfig } from 'ts-cloud' |
| 11 | + |
| 12 | +export default { |
| 13 | + name: 'my-app', |
| 14 | + region: 'us-east-1', |
| 15 | + |
| 16 | + environments: { |
| 17 | + dev: { |
| 18 | + account: '123456789012', |
| 19 | + region: 'us-east-1', |
| 20 | + }, |
| 21 | + prod: { |
| 22 | + account: '987654321098', |
| 23 | + region: 'us-west-2', |
| 24 | + }, |
| 25 | + }, |
| 26 | + |
| 27 | + stacks: { |
| 28 | + network: './stacks/network.ts', |
| 29 | + database: './stacks/database.ts', |
| 30 | + application: './stacks/application.ts', |
| 31 | + }, |
| 32 | +} satisfies CloudConfig |
| 33 | +``` |
| 34 | + |
| 35 | +## Configuration Options |
| 36 | + |
| 37 | +### Core Options |
| 38 | + |
| 39 | +| Option | Type | Default | Description | |
| 40 | +|--------|------|---------|-------------| |
| 41 | +| `name` | `string` | required | Project name, used for resource naming | |
| 42 | +| `region` | `string` | `'us-east-1'` | Default AWS region | |
| 43 | +| `environments` | `object` | `{}` | Environment-specific settings | |
| 44 | +| `stacks` | `object` | `{}` | Stack definitions | |
| 45 | + |
| 46 | +### Environment Configuration |
| 47 | + |
| 48 | +```typescript |
| 49 | +environments: { |
| 50 | + dev: { |
| 51 | + account: '123456789012', |
| 52 | + region: 'us-east-1', |
| 53 | + variables: { |
| 54 | + LOG_LEVEL: 'debug', |
| 55 | + }, |
| 56 | + }, |
| 57 | + staging: { |
| 58 | + account: '123456789012', |
| 59 | + region: 'us-east-1', |
| 60 | + variables: { |
| 61 | + LOG_LEVEL: 'info', |
| 62 | + }, |
| 63 | + }, |
| 64 | + prod: { |
| 65 | + account: '987654321098', |
| 66 | + region: 'us-west-2', |
| 67 | + variables: { |
| 68 | + LOG_LEVEL: 'warn', |
| 69 | + }, |
48 | 70 | }, |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### Stack Configuration |
| 75 | + |
| 76 | +```typescript |
| 77 | +stacks: { |
| 78 | + // Reference external files |
| 79 | + network: './stacks/network.ts', |
| 80 | + |
| 81 | + // Or define inline |
| 82 | + storage: { |
| 83 | + resources: { |
| 84 | + Bucket: { |
| 85 | + Type: 'AWS::S3::Bucket', |
| 86 | + Properties: { |
| 87 | + BucketName: 'my-bucket', |
| 88 | + }, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Static Site Configuration |
| 96 | + |
| 97 | +For static site deployments, use `StaticSiteConfig`: |
| 98 | + |
| 99 | +```typescript |
| 100 | +import type { StaticSiteConfig } from 'ts-cloud' |
| 101 | + |
| 102 | +const config: StaticSiteConfig = { |
| 103 | + siteName: 'my-docs', |
| 104 | + region: 'us-east-1', |
| 105 | + |
| 106 | + // Domain configuration |
| 107 | + domain: 'docs.example.com', |
| 108 | + // Or use subdomain + baseDomain |
| 109 | + subdomain: 'docs', |
| 110 | + baseDomain: 'example.com', |
| 111 | + |
| 112 | + // S3 configuration |
| 113 | + bucket: 'my-docs-bucket', // auto-generated if not specified |
| 114 | + |
| 115 | + // CloudFront configuration |
| 116 | + defaultRootObject: 'index.html', |
| 117 | + errorDocument: '404.html', |
| 118 | + cacheControl: 'max-age=31536000, public', |
| 119 | + |
| 120 | + // SSL/TLS |
| 121 | + certificateArn: 'arn:aws:acm:...', // auto-created if not specified |
| 122 | + hostedZoneId: 'Z1234567890', // auto-detected if not specified |
49 | 123 |
|
50 | | - /** |
51 | | - * The verbose setting. |
52 | | - * Default: false |
53 | | - * If set to true, the proxy will log more information. |
54 | | - */ |
55 | | - verbose: false, |
| 124 | + // CloudFormation |
| 125 | + stackName: 'my-docs-stack', // auto-generated if not specified |
| 126 | + |
| 127 | + // Tags |
| 128 | + tags: { |
| 129 | + Project: 'MyDocs', |
| 130 | + Environment: 'production', |
| 131 | + }, |
56 | 132 | } |
| 133 | +``` |
| 134 | + |
| 135 | +## Preset Configuration |
| 136 | + |
| 137 | +### Static Site Preset |
| 138 | + |
| 139 | +```typescript |
| 140 | +import { createStaticSitePreset } from 'ts-cloud/presets' |
| 141 | + |
| 142 | +export default createStaticSitePreset({ |
| 143 | + name: 'My Website', |
| 144 | + slug: 'my-website', |
| 145 | + domain: 'example.com', |
| 146 | + |
| 147 | + // Optional overrides |
| 148 | + cdn: { |
| 149 | + priceClass: 'PriceClass_100', // US & Europe only |
| 150 | + }, |
| 151 | +}) |
| 152 | +``` |
| 153 | + |
| 154 | +### Full-Stack Preset |
| 155 | + |
| 156 | +```typescript |
| 157 | +import { createFullStackAppPreset } from 'ts-cloud/presets' |
| 158 | + |
| 159 | +export default createFullStackAppPreset({ |
| 160 | + name: 'My App', |
| 161 | + slug: 'my-app', |
| 162 | + domain: 'app.example.com', |
| 163 | + apiSubdomain: 'api.example.com', |
| 164 | + |
| 165 | + // Compute configuration |
| 166 | + compute: { |
| 167 | + cpu: 512, |
| 168 | + memory: 1024, |
| 169 | + desiredCount: 2, |
| 170 | + }, |
| 171 | + |
| 172 | + // Database configuration |
| 173 | + database: { |
| 174 | + engine: 'postgres', |
| 175 | + instanceClass: 'db.t3.medium', |
| 176 | + allocatedStorage: 20, |
| 177 | + multiAz: true, |
| 178 | + }, |
| 179 | + |
| 180 | + // Cache configuration |
| 181 | + cache: { |
| 182 | + engine: 'redis', |
| 183 | + nodeType: 'cache.t3.micro', |
| 184 | + numNodes: 1, |
| 185 | + }, |
| 186 | +}) |
| 187 | +``` |
| 188 | + |
| 189 | +### API Backend Preset |
| 190 | + |
| 191 | +```typescript |
| 192 | +import { createApiBackendPreset } from 'ts-cloud/presets' |
| 193 | + |
| 194 | +export default createApiBackendPreset({ |
| 195 | + name: 'My API', |
| 196 | + slug: 'my-api', |
| 197 | + domain: 'api.example.com', |
| 198 | + |
| 199 | + // Lambda configuration |
| 200 | + lambda: { |
| 201 | + runtime: 'nodejs20.x', |
| 202 | + memorySize: 256, |
| 203 | + timeout: 30, |
| 204 | + }, |
57 | 205 |
|
58 | | -export default config |
| 206 | + // DynamoDB configuration |
| 207 | + dynamodb: { |
| 208 | + billingMode: 'PAY_PER_REQUEST', |
| 209 | + tables: [ |
| 210 | + { name: 'users', partitionKey: 'id' }, |
| 211 | + { name: 'orders', partitionKey: 'userId', sortKey: 'createdAt' }, |
| 212 | + ], |
| 213 | + }, |
| 214 | +}) |
59 | 215 | ``` |
60 | 216 |
|
61 | | -_Then run:_ |
| 217 | +## Environment Variables |
| 218 | + |
| 219 | +ts-cloud reads credentials from environment variables: |
| 220 | + |
| 221 | +| Variable | Description | |
| 222 | +|----------|-------------| |
| 223 | +| `AWS_ACCESS_KEY_ID` | AWS access key | |
| 224 | +| `AWS_SECRET_ACCESS_KEY` | AWS secret key | |
| 225 | +| `AWS_DEFAULT_REGION` | Default region | |
| 226 | +| `AWS_PROFILE` | Named profile from `~/.aws/credentials` | |
| 227 | +| `AWS_SESSION_TOKEN` | Session token for temporary credentials | |
62 | 228 |
|
63 | | -```bash |
64 | | -./rpx start |
| 229 | +## TypeScript Configuration |
| 230 | + |
| 231 | +For best type checking, add ts-cloud to your `tsconfig.json`: |
| 232 | + |
| 233 | +```json |
| 234 | +{ |
| 235 | + "compilerOptions": { |
| 236 | + "types": ["ts-cloud"] |
| 237 | + } |
| 238 | +} |
65 | 239 | ``` |
66 | 240 |
|
67 | | -To learn more, head over to the [documentation](https://reverse-proxy.sh/). |
| 241 | +## Next Steps |
| 242 | + |
| 243 | +- [Getting Started](/guide/getting-started) - Create your first stack |
| 244 | +- [Providers](/guide/providers) - AWS resource builders |
| 245 | +- [Deployment](/guide/deployment) - Deploy your infrastructure |
0 commit comments