Skip to content

Commit 2466a75

Browse files
committed
fix(deploy): data sources, cors and other settings
1 parent f2c8895 commit 2466a75

File tree

20 files changed

+8485
-1985
lines changed

20 files changed

+8485
-1985
lines changed

.env.example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Server Configuration
22
PORT=4000
33

4-
# Data Path (relative to server package)
5-
# Default points to repository root data folder
6-
DATA_PATH=../../data/structure
4+
# Data Path (relative to project root)
5+
# Default points to data folder in project root
6+
DATA_PATH=./data/structure
77

88
# CORS Configuration
9-
# In production, set to your frontend domain(s)
9+
# This API is publicly accessible and defaults to allowing all origins (*)
10+
# Optionally restrict to specific domain(s) if needed
1011
# Example: https://www.freecodecamp.org
1112
# Multiple origins: https://app1.example.com,https://app2.example.com
1213
CORS_ORIGIN=*
1314

1415
# Environment
1516
# Set to 'production' in production environments
16-
# CORS_ORIGIN must be explicitly set when NODE_ENV=production
1717
NODE_ENV=development

.github/workflows/node.js-tests.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,47 @@ jobs:
196196

197197
- name: Run tests with coverage
198198
run: pnpm test:coverage
199+
env:
200+
CI: true
201+
202+
- name: Generate coverage summary
203+
if: always()
204+
run: |
205+
echo "## Test Coverage Summary" >> $GITHUB_STEP_SUMMARY
206+
echo "" >> $GITHUB_STEP_SUMMARY
207+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
208+
209+
# Extract coverage summary from packages/server
210+
if [ -f packages/server/coverage/coverage-summary.json ]; then
211+
node -e "
212+
const fs = require('fs');
213+
const coverage = JSON.parse(fs.readFileSync('packages/server/coverage/coverage-summary.json', 'utf8'));
214+
const total = coverage.total;
215+
216+
const formatPercent = (pct) => {
217+
const color = pct >= 90 ? '🟢' : pct >= 80 ? '🟡' : '🔴';
218+
return \`\${color} \${pct.toFixed(2)}%\`;
219+
};
220+
221+
console.log('Coverage Summary:');
222+
console.log('');
223+
console.log('Statements :', formatPercent(total.statements.pct));
224+
console.log('Branches :', formatPercent(total.branches.pct));
225+
console.log('Functions :', formatPercent(total.functions.pct));
226+
console.log('Lines :', formatPercent(total.lines.pct));
227+
console.log('');
228+
console.log('Files tested:', Object.keys(coverage).length - 1);
229+
" >> $GITHUB_STEP_SUMMARY
230+
else
231+
echo "Coverage report not found" >> $GITHUB_STEP_SUMMARY
232+
fi
233+
234+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
199235
200236
- name: Upload coverage reports
201237
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
202238
if: always()
203239
with:
204-
files: ./coverage/coverage-final.json
240+
files: ./packages/server/coverage/coverage-final.json
205241
flags: unittests
206242
name: codecov-curriculum-db

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm lint-staged

.husky/pre-push

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm pre-push

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ COPY --chown=node:node scripts/ scripts/
2323
# Install all dependencies (including dev dependencies for build)
2424
RUN pnpm install --frozen-lockfile
2525

26-
# Fetch curriculum data using git sparse-checkout
26+
# Fetch curriculum data using giget
2727
RUN node scripts/fetch-curriculum-data.mjs
2828

2929
# Build the TypeScript project

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,34 @@ pnpm fetch-data
1414
# Start development server (hot reload)
1515
pnpm develop
1616
```
17+
18+
## Build
19+
20+
Build and push locally:
21+
22+
```bash
23+
# 1. Install dependencies
24+
pnpm install
25+
26+
# 2. Fetch curriculum data
27+
pnpm fetch-data
28+
29+
# 3. Build TypeScript
30+
pnpm build
31+
32+
# 4. Build Docker image (fetches data again inside container)
33+
docker build -t curriculum-db .
34+
35+
# 5. Tag for DOCR
36+
docker tag curriculum-db registry.digitalocean.com/{DOCR_NAME}/dev/curriculum-db:latest
37+
38+
# 6. Push to DOCR
39+
docker push registry.digitalocean.com/{DOCR_NAME}/dev/curriculum-db:latest
40+
41+
```
42+
43+
OR with CI:
44+
45+
```bash
46+
gh workflow run docker-docr.yml -f site_tld={SITE_TLD}
47+
```

package.json

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"test:ui": "turbo run test:ui",
1919
"test:coverage": "turbo run test:coverage",
2020
"fetch-data": "node scripts/fetch-curriculum-data.mjs",
21-
"start": "node packages/server/dist/index.js"
21+
"start": "node packages/server/dist/index.js",
22+
"prepare": "husky",
23+
"pre-push": "pnpm lint && pnpm format:check && pnpm type-check && pnpm test"
2224
},
2325
"keywords": [
2426
"freecodecamp",
@@ -30,14 +32,28 @@
3032
"license": "BSD-3-Clause",
3133
"packageManager": "[email protected]",
3234
"devDependencies": {
33-
"@types/node": "^24.8.1",
34-
"@vitest/coverage-v8": "^3.2.4",
35-
"@vitest/ui": "^3.2.4",
36-
"oxlint": "^0.18.0",
37-
"prettier": "^3.3.3",
38-
"tsx": "^4.19.2",
35+
"@types/node": "^24.9.1",
36+
"@vitest/coverage-v8": "^4.0.4",
37+
"@vitest/ui": "^4.0.4",
38+
"husky": "^9.1.7",
39+
"lint-staged": "^16.2.6",
40+
"oxlint": "^1.24.0",
41+
"prettier": "^3.6.2",
42+
"tsx": "^4.20.6",
3943
"turbo": "^2.5.8",
40-
"typescript": "^5.7.2",
41-
"vitest": "^3.2.4"
44+
"typescript": "^5.9.3",
45+
"vitest": "^4.0.4"
46+
},
47+
"dependencies": {
48+
"giget": "^2.0.0"
49+
},
50+
"lint-staged": {
51+
"*.{ts,tsx,js,jsx,mjs,cjs}": [
52+
"oxlint",
53+
"prettier --write"
54+
],
55+
"*.{json,md,yml,yaml}": [
56+
"prettier --write"
57+
]
4258
}
4359
}

packages/server/.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm test

packages/server/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"types": "./dist/index.d.ts",
88
"scripts": {
99
"develop": "tsx --watch src/index.ts",
10-
"build": "tsc --build",
10+
"build": "tsc --build && cp src/schema/schema.graphql dist/schema/",
1111
"type-check": "tsc --noEmit",
1212
"lint": "oxlint src",
1313
"format": "prettier --write src/",
@@ -27,10 +27,10 @@
2727
"author": "freeCodeCamp",
2828
"license": "BSD-3-Clause",
2929
"devDependencies": {
30-
"@graphql-codegen/cli": "^6.0.0",
31-
"@graphql-codegen/typescript": "^5.0.2",
32-
"@graphql-codegen/typescript-resolvers": "^5.1.0",
33-
"@graphql-tools/executor-http": "^1.3.3"
30+
"@graphql-codegen/cli": "^6.0.1",
31+
"@graphql-codegen/typescript": "^5.0.2",
32+
"@graphql-codegen/typescript-resolvers": "^5.1.0",
33+
"@graphql-tools/executor-http": "^3.0.4"
3434
},
3535
"dependencies": {
3636
"graphql": "^16.11.0",

0 commit comments

Comments
 (0)