Skip to content

Commit ec0a670

Browse files
authored
Merge pull request #11 from techstartucalgary/reconstruct-backend-pipeline
reconstruct CI for backend
2 parents 2a60821 + 80484c0 commit ec0a670

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

.github/workflows/ci-backend.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI - Build Backend
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'shatter-backend/**'
8+
9+
pull_request:
10+
branches: [main]
11+
paths:
12+
- 'shatter-backend/**'
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: "20"
26+
27+
- name: Install dependencies
28+
run: |
29+
cd shatter-backend
30+
npm ci
31+
32+
- name: Build project
33+
run: |
34+
cd shatter-backend
35+
npm run build
36+
37+
- name: Package build artifacts
38+
run: |
39+
cd shatter-backend
40+
mkdir output
41+
cp -r dist package.json package-lock.json vercel.json output/
42+
tar -czf node-backend-${{ github.run_number }}.tar.gz output
43+
mv node-backend-${{ github.run_number }}.tar.gz $GITHUB_WORKSPACE/
44+
45+
- name: Upload artifact
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: node-backend-${{ github.run_number }}
49+
path: node-backend-${{ github.run_number }}.tar.gz

shatter-backend/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Express framework gives us fucnctions to creeate web server, handle routes, process HTTP req and send responses
22
import express from 'express';
3-
import userRoutes from './routes/user_route.ts'; // these routes define how to handel requests to /api/users
3+
import userRoutes from './routes/user_route'; // these routes define how to handel requests to /api/users
44

55
// Creating express application as a single "app" object, started in server.ts
66
// This object represents entire web server and will be used to:

shatter-backend/src/controllers/user_controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import req and res types for type safety
22
import { Request, Response } from 'express';
3-
import { User } from '../models/user_model.ts'; // imports user model created with mongoose
3+
import { User } from '../models/user_model'; // imports user model created with mongoose
44

55
// controller: GET /api/users
66
// This function handles GET reqs to /api/users

shatter-backend/src/routes/user_route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// router is like a mini-express app that allows grouping of related routes together
22
import { Router } from 'express';
3-
import { getUsers, createUser } from '../controllers/user_controller.ts';
3+
import { getUsers, createUser } from '../controllers/user_controller';
44
// Importing controller functions that handle logic for each route
55
// These function define what happens when a req is received
66

shatter-backend/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import 'dotenv/config'; // loads .env file and populates process.env (the node.js object)
44
import mongoose from 'mongoose'; // mongoose is an Object Data Modelling (ODM) livrary for MongoDB
5-
import app from './app.ts'; // Import the express app
5+
import app from './app'; // Import the express app
66

77

88
// config

shatter-backend/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"sourceMap": true,
99
"outDir": "dist",
1010
"lib": ["ES2021"],
11-
"allowImportingTsExtensions": true,
12-
"noEmit": true
11+
"noEmit": false
1312
},
1413
"include": ["src/**/*"]
1514
}

shatter-backend/vercel.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 2,
3+
"builds": [
4+
{ "src": "dist/server.js", "use": "@vercel/node" }
5+
],
6+
"routes": [
7+
{ "src": "/(.*)", "dest": "dist/server.js" }
8+
]
9+
}

0 commit comments

Comments
 (0)