mirror of
https://github.com/Ryujinx/Ryujinx-Ldn-Website.git
synced 2025-08-11 11:11:06 +00:00
Switch to node package
Setup environment for: - Typescript - express with ejs as the view engine
This commit is contained in:
parent
434ca00447
commit
3bcc7d8a22
1
.eslintignore
Normal file
1
.eslintignore
Normal file
|
@ -0,0 +1 @@
|
|||
**/*.js
|
7
.eslintrc.js
Normal file
7
.eslintrc.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* eslint-env node */
|
||||
module.exports = {
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
root: true,
|
||||
};
|
15
.github/dependabot.yml
vendored
Normal file
15
.github/dependabot.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
reviewers:
|
||||
- TSRBerry
|
||||
schedule:
|
||||
interval: daily
|
||||
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
reviewers:
|
||||
- TSRBerry
|
||||
schedule:
|
||||
interval: daily
|
51
.github/workflows/check.yml
vendored
Normal file
51
.github/workflows/check.yml
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
on:
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
checks: write
|
||||
|
||||
concurrency:
|
||||
group: check-${{ github.ref_name }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run ESLint
|
||||
run: node_modules/.bin/eslint .
|
||||
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run Prettier
|
||||
run: node_modules/.bin/prettier -c .
|
93
.github/workflows/code-quality.yml
vendored
Normal file
93
.github/workflows/code-quality.yml
vendored
Normal file
|
@ -0,0 +1,93 @@
|
|||
on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- "master"
|
||||
- "dependabot/**"
|
||||
paths-ignore:
|
||||
- ".*"
|
||||
- "README.md"
|
||||
- "tsconfig.json"
|
||||
- "nodemon.json"
|
||||
|
||||
permissions:
|
||||
checks: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config --global user.name github-actions[bot]
|
||||
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run ESLint
|
||||
run: node_modules/.bin/eslint --fix .
|
||||
|
||||
- name: Check if files have been modified
|
||||
id: mod_check
|
||||
run: |
|
||||
[[ $(git status -s | wc -l) -le 1 ]] \
|
||||
&& echo "is-dirty=false" >> "$GITHUB_OUTPUT" \
|
||||
|| echo "is-dirty=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Commit and push changes
|
||||
if: steps.mod_check.outputs.is-dirty == 'true'
|
||||
run: |
|
||||
git add .
|
||||
git commit -m "Apply linter fixes"
|
||||
git push
|
||||
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config --global user.name github-actions[bot]
|
||||
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run Prettier
|
||||
run: node_modules/.bin/prettier -w .
|
||||
|
||||
- name: Check if files have been modified
|
||||
id: mod_check
|
||||
run: |
|
||||
[[ $(git status -s | wc -l) -le 1 ]] \
|
||||
&& echo "is-dirty=false" >> "$GITHUB_OUTPUT" \
|
||||
|| echo "is-dirty=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Commit and push changes
|
||||
if: steps.mod_check.outputs.is-dirty == 'true'
|
||||
run: |
|
||||
git add .
|
||||
git commit -m "Apply prettier formatting"
|
||||
git push
|
50
.github/workflows/npm-deps.yml
vendored
Normal file
50
.github/workflows/npm-deps.yml
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
name: Fix dependabot PRs
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "dependabot/**"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
pnpm-lock:
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: latest
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version-file: ".nvmrc"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config --global user.name github-actions[bot]
|
||||
git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
|
||||
- name: Install dependencies (no-frozen-lockfile)
|
||||
run: pnpm install --no-frozen-lockfile
|
||||
|
||||
- name: Check if files have been modified
|
||||
id: mod_check
|
||||
run: |
|
||||
[[ $(git status -s | wc -l) -le 1 ]] \
|
||||
&& echo "is-dirty=false" >> "$GITHUB_OUTPUT" \
|
||||
|| echo "is-dirty=true" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Commit and push changes
|
||||
if: steps.mod_check.outputs.is-dirty == 'true'
|
||||
run: |
|
||||
git add .
|
||||
git commit -m "Update pnpm-lock.yaml"
|
||||
git push
|
140
.gitignore
vendored
Normal file
140
.gitignore
vendored
Normal file
|
@ -0,0 +1,140 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# IDE / Code editor directories
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Direnv files
|
||||
.envrc
|
||||
|
||||
# Data directory
|
||||
data/
|
6
.prettierignore
Normal file
6
.prettierignore
Normal file
|
@ -0,0 +1,6 @@
|
|||
dist/
|
||||
public/
|
||||
*.js
|
||||
.github/
|
||||
pnpm-lock.yaml
|
||||
nodemon.json
|
8
.prettierrc.json
Normal file
8
.prettierrc.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"endOfLine": "lf",
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"bracketSpacing": true
|
||||
}
|
0
data/.gitkeep
Normal file
0
data/.gitkeep
Normal file
13
nodemon.json
Normal file
13
nodemon.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"verbose": true,
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"watch": [
|
||||
"src",
|
||||
"public",
|
||||
"views"
|
||||
],
|
||||
"ext": "ts,js,html,css,ejs,png",
|
||||
"exec": "pnpm run dev"
|
||||
}
|
41
package.json
Normal file
41
package.json
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"name": "ryujinx-ldn-website",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"author": "Ryujinx",
|
||||
"license": "MIT",
|
||||
"description": "Ryujinx LDN website",
|
||||
"repository": {
|
||||
"url": "https://github.com/Ryujinx/Ryujinx-Ldn-Website"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"format": "prettier -w .",
|
||||
"lint": "eslint --fix .",
|
||||
"build": "tsc",
|
||||
"prestart": "pnpm build",
|
||||
"start": "node .",
|
||||
"dev": "pnpm build && pnpm start",
|
||||
"serve": "nodemon",
|
||||
"prepack": "pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"ejs": "^3.1.9",
|
||||
"express": "~4.18.2",
|
||||
"express-actuator": "^1.8.4",
|
||||
"winston": "^3.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/recommended": "^1.0.2",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/express-actuator": "^1.8.0",
|
||||
"@types/node": "^20.2.5",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
||||
"@typescript-eslint/parser": "^5.59.7",
|
||||
"eslint": "^8.41.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"nodemon": "^2.0.22",
|
||||
"prettier": "2.8.8",
|
||||
"typescript": "^5.0.4"
|
||||
}
|
||||
}
|
1828
pnpm-lock.yaml
Normal file
1828
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
41
src/app.ts
Normal file
41
src/app.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import express from "express";
|
||||
import actuator from "express-actuator";
|
||||
import winston from "winston";
|
||||
import { errorLogger, requestLogger } from "./middleware";
|
||||
|
||||
// Init logger
|
||||
const loggerInstance = winston.createLogger({
|
||||
level: process.env.NODE_ENV === "production" ? "info" : "debug",
|
||||
transports: [
|
||||
new winston.transports.Console(),
|
||||
new winston.transports.File({
|
||||
filename: `data/ryujinx-ldn-website.log`,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
export const logger = loggerInstance.child({
|
||||
source: "Node",
|
||||
});
|
||||
|
||||
// Init express server
|
||||
export const app = express();
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
// This is set by NODE_ENV
|
||||
if (app.get("env") === "production") {
|
||||
// Trust first proxy
|
||||
app.set("trust proxy", 1);
|
||||
}
|
||||
|
||||
// Readiness/Liveness probes and other application info
|
||||
app.use(actuator());
|
||||
|
||||
// Logger middleware
|
||||
app.use(requestLogger);
|
||||
|
||||
// Set up routes
|
||||
app.use(express.static("public"));
|
||||
|
||||
// Error-handling
|
||||
app.use(errorLogger);
|
14
src/index.ts
Executable file
14
src/index.ts
Executable file
|
@ -0,0 +1,14 @@
|
|||
import { env } from "process";
|
||||
import { app, logger } from "./app";
|
||||
import http from "http";
|
||||
|
||||
const server = http.createServer(app);
|
||||
server.listen(parseInt(env.PORT || "3000"), (env.HOST || "127.0.0.1"));
|
||||
|
||||
server.on("error", (error: Error) => {
|
||||
logger.error("An error occurred.", error);
|
||||
});
|
||||
|
||||
server.on("listening", () => {
|
||||
logger.info("Startup done!", server.address());
|
||||
});
|
21
src/middleware.ts
Normal file
21
src/middleware.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Request, Response, NextFunction } from "express";
|
||||
import { logger } from "./app";
|
||||
import { loggerDefaultMetadata } from "./utils";
|
||||
|
||||
export function requestLogger(req: Request, res: Response, next: NextFunction) {
|
||||
logger.debug("Incoming request.", loggerDefaultMetadata(req));
|
||||
next();
|
||||
}
|
||||
|
||||
export function errorLogger(
|
||||
err: Error,
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
logger.error(err.message, {
|
||||
error: err,
|
||||
...loggerDefaultMetadata(req),
|
||||
});
|
||||
next(err);
|
||||
}
|
9
src/utils.ts
Normal file
9
src/utils.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { Request } from "express";
|
||||
|
||||
export function loggerDefaultMetadata(request: Request): object {
|
||||
return {
|
||||
userAgent: request.header("User-Agent"),
|
||||
url: request.url,
|
||||
ip: request.ip,
|
||||
};
|
||||
}
|
8
tsconfig.json
Normal file
8
tsconfig.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "@tsconfig/recommended/tsconfig.json",
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["**/*.spec.ts"],
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue