@tamyla/clodo-framework 2.0.4 → 2.0.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/CHANGELOG.md +7 -0
- package/package.json +2 -1
- package/templates/generic/.env.example +37 -0
- package/templates/generic/README.md +206 -0
- package/templates/generic/package.json +27 -0
- package/templates/generic/scripts/deploy.ps1 +2 -0
- package/templates/generic/scripts/setup.ps1 +2 -0
- package/templates/generic/src/config/domains.js +105 -0
- package/templates/generic/src/worker/index.js +183 -0
- package/templates/generic/wrangler.toml +27 -0
- package/templates/scripts/deploy.js +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.0.5](https://github.com/tamylaa/clodo-framework/compare/v2.0.4...v2.0.5) (2025-10-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* include templates directory in published package ([8d5c1ff](https://github.com/tamylaa/clodo-framework/commit/8d5c1ffc6090c35751d926042c784ae9b4d711b1))
|
|
7
|
+
|
|
1
8
|
## [2.0.4](https://github.com/tamylaa/clodo-framework/compare/v2.0.3...v2.0.4) (2025-10-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamyla/clodo-framework",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Reusable framework for Clodo-style software architecture on Cloudflare Workers + D1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"bin/service-management",
|
|
59
59
|
"bin/security",
|
|
60
60
|
"bin/shared/config",
|
|
61
|
+
"templates",
|
|
61
62
|
"docs/README.md",
|
|
62
63
|
"docs/overview.md",
|
|
63
64
|
"docs/SECURITY.md",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# {{SERVICE_DISPLAY_NAME}} Environment Variables
|
|
2
|
+
# Copy this file to .env and configure your values
|
|
3
|
+
|
|
4
|
+
# Domain Configuration
|
|
5
|
+
DOMAIN_NAME={{SERVICE_NAME}}
|
|
6
|
+
ENVIRONMENT=development
|
|
7
|
+
|
|
8
|
+
# Cloudflare Configuration (required for deployment)
|
|
9
|
+
CLOUDFLARE_ACCOUNT_ID=your-cloudflare-account-id
|
|
10
|
+
CLOUDFLARE_ZONE_ID=your-zone-id
|
|
11
|
+
|
|
12
|
+
# Domain URLs (customize as needed)
|
|
13
|
+
PRODUCTION_DOMAIN=api.{{SERVICE_NAME}}.com
|
|
14
|
+
STAGING_DOMAIN=staging-api.{{SERVICE_NAME}}.com
|
|
15
|
+
DEVELOPMENT_DOMAIN=dev-api.{{SERVICE_NAME}}.com
|
|
16
|
+
|
|
17
|
+
# Service Configuration
|
|
18
|
+
SERVICE_NAME={{SERVICE_NAME}}
|
|
19
|
+
SERVICE_TYPE={{SERVICE_TYPE}}
|
|
20
|
+
LOG_LEVEL=info
|
|
21
|
+
|
|
22
|
+
# CORS Configuration
|
|
23
|
+
CORS_ORIGINS=*
|
|
24
|
+
|
|
25
|
+
# Rate Limiting
|
|
26
|
+
RATE_LIMIT_REQUESTS=100
|
|
27
|
+
RATE_LIMIT_WINDOW_MS=60000
|
|
28
|
+
|
|
29
|
+
# Metrics and Monitoring
|
|
30
|
+
ENABLE_METRICS=false
|
|
31
|
+
METRICS_ENDPOINT=
|
|
32
|
+
|
|
33
|
+
# Database Configuration (will be set up during deployment)
|
|
34
|
+
# DATABASE_ID=your-database-id
|
|
35
|
+
|
|
36
|
+
# Add your custom environment variables below
|
|
37
|
+
# CUSTOM_VAR=value
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# {{SERVICE_DISPLAY_NAME}}
|
|
2
|
+
|
|
3
|
+
A Clodo Framework {{SERVICE_TYPE}} service generated on {{CURRENT_DATE}}.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This service was created using the Clodo Framework template generator. It includes:
|
|
8
|
+
|
|
9
|
+
- Domain configuration management
|
|
10
|
+
- Feature flag system
|
|
11
|
+
- Automated deployment scripts
|
|
12
|
+
- Consistent service architecture
|
|
13
|
+
- Cloudflare Workers + D1 integration
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
1. **Install dependencies:**
|
|
18
|
+
```bash
|
|
19
|
+
npm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. **Configure your service:**
|
|
23
|
+
```bash
|
|
24
|
+
npm run setup
|
|
25
|
+
```
|
|
26
|
+
This will guide you through:
|
|
27
|
+
- Domain configuration
|
|
28
|
+
- Cloudflare account setup
|
|
29
|
+
- Feature flag configuration
|
|
30
|
+
|
|
31
|
+
3. **Start development:**
|
|
32
|
+
```bash
|
|
33
|
+
npm run dev
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
4. **Deploy to production:**
|
|
37
|
+
```bash
|
|
38
|
+
npm run deploy -- --Environment production
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Project Structure
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
src/
|
|
45
|
+
├── config/
|
|
46
|
+
│ ├── domains.js # Domain and feature configuration
|
|
47
|
+
│ └── features.js # Service-specific feature definitions
|
|
48
|
+
├── worker/
|
|
49
|
+
│ └── index.js # Cloudflare Worker entry point
|
|
50
|
+
├── routes/ # Route handlers
|
|
51
|
+
├── services/ # Business logic
|
|
52
|
+
└── utils/ # Utility functions
|
|
53
|
+
|
|
54
|
+
scripts/ # Deployment and setup scripts
|
|
55
|
+
tests/ # Test files
|
|
56
|
+
migrations/ # Database migrations
|
|
57
|
+
docs/ # Documentation
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
### Domain Configuration (`src/config/domains.js`)
|
|
63
|
+
|
|
64
|
+
Configure your Cloudflare account, domains, and feature flags:
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
export const domains = {
|
|
68
|
+
'your-domain': {
|
|
69
|
+
name: 'your-domain',
|
|
70
|
+
accountId: 'your-cloudflare-account-id',
|
|
71
|
+
zoneId: 'your-zone-id',
|
|
72
|
+
domains: {
|
|
73
|
+
production: 'api.yourdomain.com',
|
|
74
|
+
staging: 'staging-api.yourdomain.com'
|
|
75
|
+
},
|
|
76
|
+
features: {
|
|
77
|
+
// Enable/disable features
|
|
78
|
+
logging: true,
|
|
79
|
+
monitoring: true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Environment Variables
|
|
86
|
+
|
|
87
|
+
Create a `.env` file (copy from `.env.example`):
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
DOMAIN_NAME=your-domain
|
|
91
|
+
ENVIRONMENT=development
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
### Available Scripts
|
|
97
|
+
|
|
98
|
+
- `npm test` - Run test suite
|
|
99
|
+
- `npm run dev` - Start development server
|
|
100
|
+
- `npm run deploy` - Deploy to Cloudflare Workers
|
|
101
|
+
- `npm run setup` - Interactive setup wizard
|
|
102
|
+
- `npm run lint` - Lint code
|
|
103
|
+
- `npm run format` - Format code
|
|
104
|
+
|
|
105
|
+
### Testing
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Run all tests
|
|
109
|
+
npm test
|
|
110
|
+
|
|
111
|
+
# Run tests in watch mode
|
|
112
|
+
npm test -- --watch
|
|
113
|
+
|
|
114
|
+
# Run specific test file
|
|
115
|
+
npm test -- tests/worker.test.js
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Local Development
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Start local development server
|
|
122
|
+
npm run dev
|
|
123
|
+
|
|
124
|
+
# Access your service at:
|
|
125
|
+
# http://localhost:8787
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Deployment
|
|
129
|
+
|
|
130
|
+
### Staging Deployment
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm run deploy -- --Environment staging
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Production Deployment
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm run deploy -- --Environment production
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Custom Deployment
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Deploy with custom domain
|
|
146
|
+
npm run deploy -- --DomainName your-custom-domain --Environment production
|
|
147
|
+
|
|
148
|
+
# Dry run (see what would be deployed)
|
|
149
|
+
npm run deploy -- --DryRun
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Features
|
|
153
|
+
|
|
154
|
+
This service includes these Clodo Framework features:
|
|
155
|
+
|
|
156
|
+
- **Domain Configuration**: Centralized configuration management
|
|
157
|
+
- **Feature Flags**: Runtime feature toggling
|
|
158
|
+
- **Worker Integration**: Consistent service initialization
|
|
159
|
+
- **Deployment Automation**: One-command deployment
|
|
160
|
+
- **Health Checks**: Built-in service monitoring
|
|
161
|
+
- **Error Handling**: Comprehensive error management
|
|
162
|
+
|
|
163
|
+
## API Endpoints
|
|
164
|
+
|
|
165
|
+
### Health Check
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
GET /health
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Returns service health status and configuration information.
|
|
172
|
+
|
|
173
|
+
**Response:**
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"status": "healthy",
|
|
177
|
+
"service": "{{SERVICE_NAME}}",
|
|
178
|
+
"version": "1.0.0",
|
|
179
|
+
"features": ["logging", "monitoring"],
|
|
180
|
+
"domain": "your-domain",
|
|
181
|
+
"environment": "development"
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Clodo Framework
|
|
186
|
+
|
|
187
|
+
This service is built on the Clodo Framework v{{FRAMEWORK_VERSION}}. The framework provides:
|
|
188
|
+
|
|
189
|
+
- **Reusable Components**: Pre-built utilities and patterns
|
|
190
|
+
- **Consistent Architecture**: Standardized service structure
|
|
191
|
+
- **Automated Deployment**: One-command deployment to any environment
|
|
192
|
+
- **Feature Management**: Runtime feature toggling
|
|
193
|
+
- **Cross-Service Communication**: Service registry and communication patterns
|
|
194
|
+
|
|
195
|
+
Learn more: [Clodo Framework Documentation](../../packages/clodo-framework/README.md)
|
|
196
|
+
|
|
197
|
+
## Contributing
|
|
198
|
+
|
|
199
|
+
1. Follow the established code patterns
|
|
200
|
+
2. Add tests for new features
|
|
201
|
+
3. Update documentation as needed
|
|
202
|
+
4. Use the Clodo Framework utilities
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT License - see LICENSE file for details
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{SERVICE_NAME}}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Clodo Framework {{SERVICE_TYPE}} service",
|
|
5
|
+
"main": "src/worker/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"dev": "wrangler dev",
|
|
10
|
+
"deploy": "powershell .\\scripts\\deploy.ps1",
|
|
11
|
+
"setup": "powershell .\\scripts\\setup.ps1",
|
|
12
|
+
"lint": "eslint src/",
|
|
13
|
+
"format": "prettier --write src/"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@tamyla/clodo-framework": "^1.0.0",
|
|
17
|
+
"wrangler": "^3.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/jest": "^29.5.0",
|
|
21
|
+
"eslint": "^8.54.0",
|
|
22
|
+
"jest": "^29.7.0",
|
|
23
|
+
"prettier": "^3.1.0"
|
|
24
|
+
},
|
|
25
|
+
"author": "Generated by Clodo Framework",
|
|
26
|
+
"license": "MIT"
|
|
27
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createDomainConfigSchema } from '@tamyla/clodo-framework';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Domain configuration for {{SERVICE_DISPLAY_NAME}}
|
|
5
|
+
*
|
|
6
|
+
* This file contains domain-specific configuration including:
|
|
7
|
+
* - Cloudflare account and zone settings
|
|
8
|
+
* - Domain URLs for different environments
|
|
9
|
+
* - Feature flags and settings
|
|
10
|
+
* - Database and service bindings
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const domains = {
|
|
14
|
+
'{{SERVICE_NAME}}': {
|
|
15
|
+
...createDomainConfigSchema(),
|
|
16
|
+
name: '{{SERVICE_NAME}}',
|
|
17
|
+
displayName: '{{SERVICE_DISPLAY_NAME}}',
|
|
18
|
+
accountId: process.env.CLOUDFLARE_ACCOUNT_ID || '', // Configure in setup
|
|
19
|
+
zoneId: process.env.CLOUDFLARE_ZONE_ID || '', // Configure in setup
|
|
20
|
+
domains: {
|
|
21
|
+
production: process.env.PRODUCTION_DOMAIN || 'api.{{SERVICE_NAME}}.com',
|
|
22
|
+
staging: process.env.STAGING_DOMAIN || 'staging-api.{{SERVICE_NAME}}.com',
|
|
23
|
+
development: process.env.DEVELOPMENT_DOMAIN || 'dev-api.{{SERVICE_NAME}}.com'
|
|
24
|
+
},
|
|
25
|
+
services: [
|
|
26
|
+
'{{SERVICE_NAME}}'
|
|
27
|
+
],
|
|
28
|
+
databases: [
|
|
29
|
+
{
|
|
30
|
+
name: '{{SERVICE_NAME}}-db',
|
|
31
|
+
type: 'd1'
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
features: {
|
|
35
|
+
// Core features (always enabled)
|
|
36
|
+
logging: true,
|
|
37
|
+
monitoring: true,
|
|
38
|
+
errorReporting: true,
|
|
39
|
+
|
|
40
|
+
// Service-specific features (uncomment and modify based on SERVICE_TYPE)
|
|
41
|
+
// Data service features
|
|
42
|
+
// authentication: true,
|
|
43
|
+
// authorization: true,
|
|
44
|
+
// fileStorage: true,
|
|
45
|
+
// search: true,
|
|
46
|
+
// filtering: true,
|
|
47
|
+
// pagination: true,
|
|
48
|
+
|
|
49
|
+
// Auth service features
|
|
50
|
+
// authentication: true,
|
|
51
|
+
// authorization: true,
|
|
52
|
+
// userProfiles: true,
|
|
53
|
+
// emailNotifications: true,
|
|
54
|
+
// magicLinkAuth: true,
|
|
55
|
+
|
|
56
|
+
// Content service features
|
|
57
|
+
// fileStorage: true,
|
|
58
|
+
// search: true,
|
|
59
|
+
// filtering: true,
|
|
60
|
+
// pagination: true,
|
|
61
|
+
// caching: true,
|
|
62
|
+
|
|
63
|
+
// API Gateway features
|
|
64
|
+
// authentication: true,
|
|
65
|
+
// authorization: true,
|
|
66
|
+
// rateLimiting: true,
|
|
67
|
+
// caching: true,
|
|
68
|
+
// monitoring: true,
|
|
69
|
+
|
|
70
|
+
// Generic service features (customize as needed)
|
|
71
|
+
// authentication: false,
|
|
72
|
+
// caching: false,
|
|
73
|
+
},
|
|
74
|
+
settings: {
|
|
75
|
+
environment: process.env.ENVIRONMENT || 'development',
|
|
76
|
+
logLevel: process.env.LOG_LEVEL || 'info',
|
|
77
|
+
corsOrigins: process.env.CORS_ORIGINS ? process.env.CORS_ORIGINS.split(',') : ['*'],
|
|
78
|
+
rateLimitRequests: parseInt(process.env.RATE_LIMIT_REQUESTS) || 100,
|
|
79
|
+
rateLimitWindowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS) || 60000,
|
|
80
|
+
enableMetrics: process.env.ENABLE_METRICS === 'true',
|
|
81
|
+
metricsEndpoint: process.env.METRICS_ENDPOINT
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get domain configuration for current environment
|
|
88
|
+
* @param {string} domainName - Name of the domain
|
|
89
|
+
* @returns {Object} Domain configuration
|
|
90
|
+
*/
|
|
91
|
+
export function getDomainConfig(domainName = '{{SERVICE_NAME}}') {
|
|
92
|
+
const config = domains[domainName];
|
|
93
|
+
if (!config) {
|
|
94
|
+
throw new Error(`Domain configuration not found: ${domainName}`);
|
|
95
|
+
}
|
|
96
|
+
return config;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get all available domains
|
|
101
|
+
* @returns {string[]} Array of domain names
|
|
102
|
+
*/
|
|
103
|
+
export function getAvailableDomains() {
|
|
104
|
+
return Object.keys(domains);
|
|
105
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { initializeService, createFeatureGuard, COMMON_FEATURES } from '@tamyla/clodo-framework';
|
|
2
|
+
import { domains } from './config/domains.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* {{SERVICE_DISPLAY_NAME}} - Clodo Framework Service
|
|
6
|
+
*
|
|
7
|
+
* Generated on: {{CURRENT_DATE}}
|
|
8
|
+
* Service Type: {{SERVICE_TYPE}}
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
async fetch(request, env, ctx) {
|
|
13
|
+
try {
|
|
14
|
+
// Initialize service with Clodo Framework
|
|
15
|
+
const service = initializeService(env, domains);
|
|
16
|
+
|
|
17
|
+
// Log request (if logging is enabled)
|
|
18
|
+
if (service.features.includes(COMMON_FEATURES.LOGGING)) {
|
|
19
|
+
console.log(`${request.method} ${request.url} - ${service.domain} (${service.environment})`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const url = new URL(request.url);
|
|
23
|
+
|
|
24
|
+
// Health check endpoint
|
|
25
|
+
if (url.pathname === '/health') {
|
|
26
|
+
return new Response(JSON.stringify({
|
|
27
|
+
status: 'healthy',
|
|
28
|
+
service: '{{SERVICE_NAME}}',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
type: '{{SERVICE_TYPE}}',
|
|
31
|
+
features: service.features,
|
|
32
|
+
domain: service.domain,
|
|
33
|
+
environment: service.environment,
|
|
34
|
+
timestamp: new Date().toISOString()
|
|
35
|
+
}), {
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
'Cache-Control': 'no-cache'
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Service information endpoint
|
|
44
|
+
if (url.pathname === '/info') {
|
|
45
|
+
return new Response(JSON.stringify({
|
|
46
|
+
name: '{{SERVICE_NAME}}',
|
|
47
|
+
displayName: '{{SERVICE_DISPLAY_NAME}}',
|
|
48
|
+
type: '{{SERVICE_TYPE}}',
|
|
49
|
+
version: '1.0.0',
|
|
50
|
+
framework: 'Clodo Framework',
|
|
51
|
+
frameworkVersion: '{{FRAMEWORK_VERSION}}',
|
|
52
|
+
domain: service.domain,
|
|
53
|
+
environment: service.environment,
|
|
54
|
+
features: service.features
|
|
55
|
+
}), {
|
|
56
|
+
headers: { 'Content-Type': 'application/json' }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Add your service-specific routes here
|
|
61
|
+
// Example routes for different service types:
|
|
62
|
+
|
|
63
|
+
// Data Service Routes (uncomment and implement for data-service type)
|
|
64
|
+
// if (url.pathname.startsWith('/api/data')) {
|
|
65
|
+
// return handleDataRoutes(request, env, ctx, service);
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
// Auth Service Routes (uncomment and implement for auth-service type)
|
|
69
|
+
// if (url.pathname.startsWith('/auth')) {
|
|
70
|
+
// return handleAuthRoutes(request, env, ctx, service);
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
// Content Service Routes (uncomment and implement for content-service type)
|
|
74
|
+
// if (url.pathname.startsWith('/content')) {
|
|
75
|
+
// return handleContentRoutes(request, env, ctx, service);
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
// API Gateway Routes (uncomment and implement for api-gateway type)
|
|
79
|
+
// return handleGatewayRoutes(request, env, ctx, service);
|
|
80
|
+
|
|
81
|
+
// Default response for unmatched routes
|
|
82
|
+
return new Response(JSON.stringify({
|
|
83
|
+
error: 'Not Found',
|
|
84
|
+
message: 'The requested endpoint does not exist',
|
|
85
|
+
service: '{{SERVICE_NAME}}',
|
|
86
|
+
availableEndpoints: [
|
|
87
|
+
'/health',
|
|
88
|
+
'/info'
|
|
89
|
+
// Add your endpoints here
|
|
90
|
+
]
|
|
91
|
+
}), {
|
|
92
|
+
status: 404,
|
|
93
|
+
headers: { 'Content-Type': 'application/json' }
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Service error:', error);
|
|
98
|
+
|
|
99
|
+
// Return appropriate error response
|
|
100
|
+
const errorResponse = {
|
|
101
|
+
error: 'Internal Server Error',
|
|
102
|
+
message: error.message,
|
|
103
|
+
service: '{{SERVICE_NAME}}',
|
|
104
|
+
timestamp: new Date().toISOString()
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Include stack trace in development
|
|
108
|
+
if (env.ENVIRONMENT === 'development') {
|
|
109
|
+
errorResponse.stack = error.stack;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return new Response(JSON.stringify(errorResponse), {
|
|
113
|
+
status: 500,
|
|
114
|
+
headers: { 'Content-Type': 'application/json' }
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Placeholder route handlers - implement these based on your service needs
|
|
121
|
+
|
|
122
|
+
async function handleDataRoutes(request, env, ctx, service) {
|
|
123
|
+
const url = new URL(request.url);
|
|
124
|
+
|
|
125
|
+
switch (request.method) {
|
|
126
|
+
case 'GET':
|
|
127
|
+
if (url.pathname === '/api/data') {
|
|
128
|
+
// Return data list
|
|
129
|
+
return new Response(JSON.stringify({
|
|
130
|
+
data: [],
|
|
131
|
+
message: 'Data endpoint - implement your data retrieval logic'
|
|
132
|
+
}), {
|
|
133
|
+
headers: { 'Content-Type': 'application/json' }
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case 'POST':
|
|
139
|
+
if (url.pathname === '/api/data') {
|
|
140
|
+
// Create new data
|
|
141
|
+
return new Response(JSON.stringify({
|
|
142
|
+
success: true,
|
|
143
|
+
message: 'Data creation endpoint - implement your creation logic'
|
|
144
|
+
}), {
|
|
145
|
+
status: 201,
|
|
146
|
+
headers: { 'Content-Type': 'application/json' }
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return new Response(JSON.stringify({ error: 'Method not allowed' }), {
|
|
153
|
+
status: 405,
|
|
154
|
+
headers: { 'Content-Type': 'application/json' }
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function handleAuthRoutes(request, env, ctx, service) {
|
|
159
|
+
// Implement authentication routes
|
|
160
|
+
return new Response(JSON.stringify({
|
|
161
|
+
message: 'Auth service - implement authentication logic'
|
|
162
|
+
}), {
|
|
163
|
+
headers: { 'Content-Type': 'application/json' }
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function handleContentRoutes(request, env, ctx, service) {
|
|
168
|
+
// Implement content management routes
|
|
169
|
+
return new Response(JSON.stringify({
|
|
170
|
+
message: 'Content service - implement content management logic'
|
|
171
|
+
}), {
|
|
172
|
+
headers: { 'Content-Type': 'application/json' }
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function handleGatewayRoutes(request, env, ctx, service) {
|
|
177
|
+
// Implement API gateway logic
|
|
178
|
+
return new Response(JSON.stringify({
|
|
179
|
+
message: 'API Gateway - implement routing logic'
|
|
180
|
+
}), {
|
|
181
|
+
headers: { 'Content-Type': 'application/json' }
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name = "{{SERVICE_NAME}}-dev"
|
|
2
|
+
main = "src/worker/index.js"
|
|
3
|
+
compatibility_date = "{{CURRENT_DATE}}"
|
|
4
|
+
|
|
5
|
+
[env.development]
|
|
6
|
+
name = "{{SERVICE_NAME}}-dev"
|
|
7
|
+
|
|
8
|
+
[env.staging]
|
|
9
|
+
name = "{{SERVICE_NAME}}-staging"
|
|
10
|
+
|
|
11
|
+
[env.production]
|
|
12
|
+
name = "{{SERVICE_NAME}}"
|
|
13
|
+
|
|
14
|
+
# Database bindings will be added during deployment
|
|
15
|
+
# [[d1_databases]]
|
|
16
|
+
# binding = "{{SERVICE_NAME}}-db"
|
|
17
|
+
# database_name = "{{SERVICE_NAME}}-db"
|
|
18
|
+
|
|
19
|
+
# Environment variables
|
|
20
|
+
[vars]
|
|
21
|
+
DOMAIN_NAME = "{{SERVICE_NAME}}.yourdomain.com"
|
|
22
|
+
ENVIRONMENT = "development"
|
|
23
|
+
SERVICE_NAME = "{{SERVICE_NAME}}"
|
|
24
|
+
SERVICE_TYPE = "{{SERVICE_TYPE}}"
|
|
25
|
+
|
|
26
|
+
# Add your custom environment variables here
|
|
27
|
+
# CUSTOM_VAR = "value"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cross-platform deployment helper
|
|
5
|
+
*
|
|
6
|
+
* Handles npm config variables properly across Windows, Linux, and Mac.
|
|
7
|
+
* PowerShell doesn't expand $npm_config_customer, so we use process.env instead.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* npm run deploy:dev --customer=wetechfounders
|
|
11
|
+
* npm run deploy:staging --customer=wetechfounders
|
|
12
|
+
* npm run deploy:prod --customer=wetechfounders
|
|
13
|
+
*
|
|
14
|
+
* Or use the framework CLI directly:
|
|
15
|
+
* npx clodo-service deploy --customer=wetechfounders --env=development
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { execSync } from 'child_process';
|
|
19
|
+
|
|
20
|
+
const environment = process.argv[2] || 'development';
|
|
21
|
+
const customer = process.env.npm_config_customer;
|
|
22
|
+
|
|
23
|
+
if (!customer) {
|
|
24
|
+
console.error('❌ Error: Customer name required');
|
|
25
|
+
console.error('');
|
|
26
|
+
console.error('Usage:');
|
|
27
|
+
console.error(' npm run deploy:dev --customer=wetechfounders');
|
|
28
|
+
console.error(' npm run deploy:staging --customer=greatidude');
|
|
29
|
+
console.error(' npm run deploy:prod --customer=tamyla');
|
|
30
|
+
console.error('');
|
|
31
|
+
console.error('Or use the framework CLI directly:');
|
|
32
|
+
console.error(' npx clodo-service deploy --customer=wetechfounders --env=development');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log(`🚀 Deploying ${customer} to ${environment}...`);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
// Use framework CLI (clodo-service has more features than clodo-security)
|
|
40
|
+
execSync(`npx clodo-service deploy --customer=${customer} --env=${environment}`, {
|
|
41
|
+
stdio: 'inherit'
|
|
42
|
+
});
|
|
43
|
+
} catch (error) {
|
|
44
|
+
process.exit(error.status || 1);
|
|
45
|
+
}
|