From f01973f9c1f2a3eb56938ea536f574be12d95b84 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 14:03:27 +0100 Subject: [PATCH 1/8] [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/8] [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/8] [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/8] [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/8] [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/8] [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 From 63b352543670021a7ba02e47fd0b0853c663e8e1 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Fri, 12 Jan 2024 18:32:29 +0100 Subject: [PATCH 7/8] [CHANGE] #6 revert back to require output for production --- package.json | 1 - src/app.ts | 11 ++++------- tsconfig.json | 12 ++++++------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index c485f044..166a51b9 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "version": "0.0.1", "description": "Leaflet Osmand React ExpressJS Coordinates (X)\r > Remember an \"X\" marks the spot.", "main": "index.js", - "type": "module", "scripts": { "clean": "rm -rf dist/*", "build": "rm -rf dist/* && npx tsc && cp -R httpdocs/ dist/", diff --git a/src/app.ts b/src/app.ts index a2daf093..9537cc7b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,11 +1,7 @@ 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); +import path from 'path'; const app = express(); const port = 80; @@ -16,7 +12,8 @@ app.get('/', (req: Request, res: Response) => { app.listen(port, () => { const date = new Date().toLocaleString('de-DE', { hour12: false }); - const logPath = join(__dirname, 'httpdocs', 'log.txt'); + const logPath = path.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 +}); diff --git a/tsconfig.json b/tsconfig.json index 7a568e39..19cde211 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,11 +3,11 @@ "include": ["src/**/*"], "exclude": ["node_modules"], "compilerOptions": { - "rootDir": "src", - "outDir": "dist", - "module": "NodeNext", - "moduleResolution": "NodeNext", - "target": "ES2022", - "sourceMap": true + "rootDir": "src", + "outDir": "dist", + "module": "CommonJS", + "moduleResolution": "node", + "target": "ES6", + "sourceMap": true } } \ No newline at end of file From 95aec15a0eb212ea2b3a6bb351f1dfc8802b5022 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Sun, 14 Jan 2024 22:05:33 +0100 Subject: [PATCH 8/8] [Task] #6 add ability to manually upload to prod --- .github/workflows/ftp.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ftp.yml b/.github/workflows/ftp.yml index eb615d8f..7d206528 100644 --- a/.github/workflows/ftp.yml +++ b/.github/workflows/ftp.yml @@ -1,5 +1,6 @@ name: Deploy via ftp on: + workflow_dispatch: push: branches: [ "main" ] jobs: