From f01973f9c1f2a3eb56938ea536f574be12d95b84 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 14:03:27 +0100 Subject: [PATCH 1/6] [Task] #6 provide fallback index.html --- httpdocs/index.html | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 httpdocs/index.html diff --git a/httpdocs/index.html b/httpdocs/index.html new file mode 100644 index 00000000..9a20fce2 --- /dev/null +++ b/httpdocs/index.html @@ -0,0 +1,52 @@ + + + + + + Welcome Page + + + +

Welcome

+ + From c19508ff0afd2dc9d8bb73ed69c5ef6d36b07871 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 14:47:11 +0100 Subject: [PATCH 2/6] [Task] #6 production ready code (m) move httpdocs folder to dist have compile without sourcemaps for faster speed --- .github/workflows/build.yml | 2 +- package.json | 5 ++++- tsconfig.prod.json | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tsconfig.prod.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 097687ed..57fe368a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: - run: node --version - uses: actions/checkout@v3 - run: npm ci - - run: npm run build --if-present + - run: npm run build:prod --if-present - name: Start server and test server response run: | npm start & diff --git a/package.json b/package.json index c555c50b..7d9bdd96 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "type": "module", "scripts": { - "build": "npx tsc", + "build": "npx tsc && cp -R httpdocs/ dist/", + "build:prod": "npx tsc -p ./tsconfig.prod.json && cp -R httpdocs/ dist/", "start": "node dist/app.js", "dev": "nodemon src/app.ts", "lint": "eslint . --fix" @@ -27,3 +28,5 @@ "express": "^4.18.2" } } + + diff --git a/tsconfig.prod.json b/tsconfig.prod.json new file mode 100644 index 00000000..513a96cc --- /dev/null +++ b/tsconfig.prod.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "sourceMap": false + } +} \ No newline at end of file From e09f9789eb032c1220b7fca8af1e9509148cef73 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 15:41:34 +0100 Subject: [PATCH 3/6] [Task] #6 create github action for upload when main is updated (#21) --- .github/workflows/ftp.yml | 25 +++++++++++++++++++++++++ .github/workflows/label.yml | 22 ---------------------- 2 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ftp.yml delete mode 100644 .github/workflows/label.yml diff --git a/.github/workflows/ftp.yml b/.github/workflows/ftp.yml new file mode 100644 index 00000000..b379796b --- /dev/null +++ b/.github/workflows/ftp.yml @@ -0,0 +1,25 @@ +name: Deploy via ftp +on: + push: + branches: [ "main" ] +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 20 + - name: Install dependencies + run: npm i + - name: Build + run: npm run build:prod + - name: Upload ftp + uses: GenieTim/ftp-action@v4.0.1 + with: + host: ${{ secrets.FTP_SERVER }} + user: ${{ secrets.FTP_USERNAME }} + password: ${{ secrets.FTP_PASSWORD }} + localDir: "dist" diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml deleted file mode 100644 index 46135690..00000000 --- a/.github/workflows/label.yml +++ /dev/null @@ -1,22 +0,0 @@ -# This workflow will triage pull requests and apply a label based on the -# paths that are modified in the pull request. -# -# To use this workflow, you will need to set up a .github/labeler.yml -# file with configuration. For more information, see: -# https://github.com/actions/labeler - -name: Labeler -on: [pull_request_target] - -jobs: - label: - - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - - steps: - - uses: actions/labeler@v4 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" From 9c2a2fce30d47758629a36c7ac827bb27d2e869f Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 15:57:41 +0100 Subject: [PATCH 4/6] [change] #6 new ftp upload action --- .github/workflows/ftp.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ftp.yml b/.github/workflows/ftp.yml index b379796b..01aa3d61 100644 --- a/.github/workflows/ftp.yml +++ b/.github/workflows/ftp.yml @@ -17,9 +17,9 @@ jobs: - name: Build run: npm run build:prod - name: Upload ftp - uses: GenieTim/ftp-action@v4.0.1 + uses: airvzxf/ftp-deployment-action@latest with: host: ${{ secrets.FTP_SERVER }} user: ${{ secrets.FTP_USERNAME }} password: ${{ secrets.FTP_PASSWORD }} - localDir: "dist" + local_dir: "dist" From bae1b4e379595c8696f6d789101e2722e939c8cc Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 16:13:30 +0100 Subject: [PATCH 5/6] [Fix] #6 replace host with server in ftp action --- .github/workflows/ftp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ftp.yml b/.github/workflows/ftp.yml index 01aa3d61..eb615d8f 100644 --- a/.github/workflows/ftp.yml +++ b/.github/workflows/ftp.yml @@ -19,7 +19,7 @@ jobs: - name: Upload ftp uses: airvzxf/ftp-deployment-action@latest with: - host: ${{ secrets.FTP_SERVER }} + server: ${{ secrets.FTP_SERVER }} user: ${{ secrets.FTP_USERNAME }} password: ${{ secrets.FTP_PASSWORD }} local_dir: "dist" From 861336bef72cd39a8fed89576ce1f44f84e10f93 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 17:14:37 +0100 Subject: [PATCH 6/6] [Task] #6 basic log (#26) --- package.json | 5 +++-- src/app.ts | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7d9bdd96..c485f044 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,11 @@ "main": "index.js", "type": "module", "scripts": { - "build": "npx tsc && cp -R httpdocs/ dist/", + "clean": "rm -rf dist/*", + "build": "rm -rf dist/* && npx tsc && cp -R httpdocs/ dist/", "build:prod": "npx tsc -p ./tsconfig.prod.json && cp -R httpdocs/ dist/", "start": "node dist/app.js", - "dev": "nodemon src/app.ts", + "dev": "rm -rf dist/* && cp -R httpdocs/ dist/ && nodemon src/app.ts", "lint": "eslint . --fix" }, "keywords": [], diff --git a/src/app.ts b/src/app.ts index 9aafa271..a2daf093 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,14 +1,22 @@ import express from 'express'; import { Request, Response } from 'express'; +import fs from 'fs'; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const app = express(); const port = 80; app.get('/', (req: Request, res: Response) => { - res.send('Hello World, via TypeScript and Node.js!'); - + res.send('Hello World, via TypeScript and Node.js!'); }); app.listen(port, () => { - console.log(`Server running at http://localhost:${port}`); + const date = new Date().toLocaleString('de-DE', { hour12: false }); + const logPath = join(__dirname, 'httpdocs', 'log.txt'); + fs.appendFileSync(logPath, `Express: Server: ${date} \n`); + console.log(`Server läuft unter http://localhost:${port}`); }); \ No newline at end of file