Skip to content
Open

. #197

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: cd

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25.1"
- name: Run production build script
run: |
chmod +x scripts/buildprod.sh
./scripts/buildprod.sh
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: ci

on:
pull_request:
branches: [main]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25.1"

- name: run auth tests
run: go test -cover ./...
style:

name: Style
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.25.1"

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: run staticcheck
run: staticcheck ./...

- name: check formatting
run: go test -z $(go fmt ./...)

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
- name: run gosec
run: gosec ./...
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
coverage/
dist/
.env
.vscode
node_modules/
coverage/
dist/
.env
.vscode
22 changes: 11 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM --platform=linux/amd64 node:18-slim

WORKDIR /usr/src/app

ADD . .

RUN npm ci

RUN npm run build

CMD ["node", "dist/main.js"]
FROM node:18-slim
WORKDIR /usr/src/app
ADD . .
RUN npm ci
RUN npm run build
CMD ["node", "dist/main.js"]
50 changes: 26 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# learn-cicd-typescript-starter (Notely)

This repo contains the typescript starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).

## Local Development

Make sure you're on Node version 18+.

Create a `.env` file in the root of the project with the following contents:

```bash
PORT="8080"
```

Run the server:

```bash
npm install
npm run dev
```

_This starts the server in non-database mode._ It will serve a simple webpage at `http://localhost:8080`.

You do _not_ need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course!
# learn-cicd-typescript-starter (Notely)
![Tests](https://github.com/AdlanAdi/learn-cicd-typescript-starter/actions/workflows/ci.yml/badge.svg)

This repo contains the typescript starter code for the "Notely" application for the "Learn CICD" course on [Boot.dev](https://boot.dev).

## Local Development

Make sure you're on Node version 18+.

Create a `.env` file in the root of the project with the following contents:

```bash
PORT="8080"
```

Run the server:

```bash
npm install
npm run dev
```

_This starts the server in non-database mode._ It will serve a simple webpage at `http://localhost:8080`.

You do _not_ need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course!
ADLAN's version of Boot.dev's Notely app."
24 changes: 12 additions & 12 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defineConfig } from "drizzle-kit";

import { config } from "./src/config";

export default defineConfig({
out: "./src/db/migrations",
schema: "./src/db/schema.ts",
dialect: "turso",
dbCredentials: {
url: config.db.url || "",
},
});
import { defineConfig } from "drizzle-kit";
import { config } from "./src/config";
export default defineConfig({
out: "./src/db/migrations",
schema: "./src/db/schema.ts",
dialect: "turso",
dbCredentials: {
url: config.db.url || "",
},
});
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/AdlanAdi/learn-cicd-typescript-starter

go 1.25.1
21 changes: 21 additions & 0 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package auth

import (
"net/http"
"strings"
)

// GetAPIKey extracts the API key from the Authorization header.
func GetAPIKey(headers http.Header) string {
authHeader := headers.Get("Authorization")
if authHeader == "" {
return ""
}

parts := strings.SplitN(authHeader, " ", 2)
if len(parts) < 2 || parts[0] != "ApiKey" {
return ""
}

return parts[1]
}
36 changes: 36 additions & 0 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package auth

import (
"net/http"
"testing"
)

func TestGetAPIKey_Valid(t *testing.T) {

headers := http.Header{}
headers.Set("Authorization", "ApiKey my-secret-key")

got := GetAPIKey(headers)
if got != "my-secret-key" {
t.Errorf("expected %q, got %q", "my-secret-key", got)
}
}

func TestGetAPIKey_InvalidPrefix(t *testing.T) {
headers := http.Header{}
headers.Set("Authorization", "Bearer something")

got := GetAPIKey(headers)
if got != "" {
t.Errorf("expected empty string, got %q", got)
}
}

func TestGetAPIKey_Missing(t *testing.T) {
headers := http.Header{}

got := GetAPIKey(headers)
if got != "" {
t.Errorf("expected empty string, got %q", got)
}
}
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"crypto/sha256"
"fmt"
)

func hashWithSHA256(input string) string {
hash := sha256.Sum256([]byte(input))
return fmt.Sprintf("%x", hash)
}

func main() {
data := "supersecret"
fmt.Println("SHA-256:", hashWithSHA256(data))
}
Binary file added notely
Binary file not shown.
Loading