npmrun 2 years ago
parent
commit
8916ac3be5
  1. 17
      Dockerfile
  2. 9
      package.json
  3. 2000
      pnpm-lock.yaml
  4. 2
      pnpm-workspace.yaml
  5. 4
      route.txt
  6. 47
      script/zip.js
  7. BIN
      source/db/data.db
  8. 4
      source/route/views/index.ts
  9. 1
      tsconfig.json

17
Dockerfile

@ -5,20 +5,17 @@ RUN npm install -g pnpm@7.1.0 && \
WORKDIR /usr/src/app
COPY package.json pnpm-lock.yaml tsconfig*.json ./
COPY ./packages/hapi-router/dist ./packages/hapi-router/dist
COPY ./packages/hapi-router/package*.json ./packages/hapi-router/
COPY ./public/js ./public/js
COPY ./public/style ./public/style
COPY ./source ./source
COPY ./dist ./dist
COPY ./template ./template
COPY ./types ./types
COPY ./patches ./patches
COPY ./public ./public
COPY .env.production ./
COPY package.json ./
COPY pnpm-lock.yaml ./
RUN pnpm install && \
pnpm build
RUN pnpm install
EXPOSE 3000
CMD [ "node", "-r", "dotenv/config dist/main.js", "dotenv_config_path=.env.production" ]
CMD [ "pnpm", "start" ]

9
package.json

@ -6,6 +6,7 @@
"main": "index.js",
"scripts": {
"init": "ts-node --respawn --project ./tsconfig.json -r tsconfig-paths/register source/db/init.ts alter",
"zip": "node script/zip.js",
"build": "tsc && tsc-alias",
"start": "node -r dotenv/config dist/main.js dotenv_config_path=.env.production",
"dev": "ts-node-dev --watch ./source/route --ignore-watch ./source/route/route.txt --respawn --project ./tsconfig.json -r tsconfig-paths/register -r dotenv/config ./source/main.ts dotenv_config_path=.env.development",
@ -25,11 +26,12 @@
"@types/hapi__hapi": "^20.0.10",
"@types/hapi__vision": "^5.5.3",
"@types/hapi__yar": "^10.1.1",
"archiver": "^5.3.1",
"bcrypt": "^5.0.1",
"fs-extra": "^10.1.0",
"hapi-auth-jwt2": "^10.2.0",
"hapi-pino": "^11.0.1",
"hapi-sequelizejs": "^4.5.0",
"hapi-sequelizejs": "4.5.0",
"hapi-swagger": "^14.2.0",
"joi": "^17.4.0",
"json-merge-patch": "^1.0.1",
@ -38,6 +40,7 @@
"markdown-it": "^13.0.1",
"multiparty": "^4.2.2",
"nodemon": "^2.0.7",
"pino": "^8.11.0",
"pino-pretty": "^9.1.1",
"pug": "^3.0.2",
"pug-alias": "^2.0.1",
@ -48,11 +51,11 @@
"@hapi/code": "^9.0.1",
"@hapi/lab": "^25.0.1",
"@hapi/vision": "^6.1.0",
"@noderun/hapi-router": "link:packages\\hapi-router",
"@noderun/hapi-router": "workspace:*",
"@types/fs-extra": "^9.0.13",
"@types/hapi__cookie": "^10.1.4",
"@types/hapi__crumb": "^7.3.3",
"@types/node": "^17.0.21",
"@types/node": "^17.0.45",
"cross-env": "^7.0.3",
"dotenv": "^10.0.0",
"ejs": "^3.1.6",

2000
pnpm-lock.yaml

File diff suppressed because it is too large

2
pnpm-workspace.yaml

@ -0,0 +1,2 @@
packages:
- 'packages/*'

4
route.txt

@ -1,6 +1,6 @@
/home/topuser/桌面/demo/hapi-demo/source/route/htmx对应路径:
D:\1XYX\pro\hapi-demo\dist\route\htmx对应路径:
不需权限 : GET /htmx/clicked
/home/topuser/桌面/demo/hapi-demo/source/route/views对应路径:
D:\1XYX\pro\hapi-demo\dist\route\views对应路径:
不需权限(提供无需验证): GET /404
不需权限 : GET /css
不需权限(提供无需验证): GET /

47
script/zip.js

@ -0,0 +1,47 @@
const fs = require("fs")
const path = require("path")
const archiver = require("archiver")
const output = fs.createWriteStream(path.resolve(__dirname, "../release_v0.1.zip"))
const archive = archiver("zip", {
zlib: { level: 9 },
})
output.on("close", function () {
console.log(archive.pointer() + " total bytes")
console.log("archiver has been finalized and the output file descriptor has closed.")
})
output.on("end", function () {
console.log("Data has been drained")
})
archive.on("warning", function (err) {
if (err.code === "ENOENT") {
} else {
throw err
}
})
archive.on("error", function (err) {
throw err
})
archive.on("progress", function (progress) {
// const percent = progress.fs.processedBytes / totalSize * 100;
// let percent =
// progress.entries.total > 0 ? Math.round((progress.entries.processed * 100.0) / progress.entries.total) : -1
// console.log("TOTAL", progress.entries.total, "PROCESSED", progress.entries.processed, "|", percent, "%")
const percent = Math.round(progress.entries.processed * 100.0 / progress.entries.total);
console.log(`\rZipping: ${percent.toFixed(2)}%`);
})
archive.pipe(output)
archive.directory("node_modules/")
archive.directory("dist/")
archive.directory("template/")
archive.directory("patches/")
archive.directory("public/")
archive.file(".env.production")
archive.file("package.json")
archive.file("pnpm-lock.yaml")
archive.finalize()

BIN
source/db/data.db

Binary file not shown.

4
source/route/views/index.ts

@ -54,7 +54,7 @@ export default class {
@route("/register")
@auth("try")
@method(["POST", "GET"])
@method("GET")
async registerView(request: Req, h: Res): ReturnValue {
if (request.auth.isAuthenticated) {
request.yar.flash("warning", "您已经登陆")
@ -85,7 +85,7 @@ export default class {
}
let salt = bcrypt.genSaltSync(10)
let pwdLock = bcrypt.hashSync(password, salt)
await User.create({ username, password: pwdLock })
await User.create({ username, password: pwdLock, nickname: username })
request.yar.flash("success", "用户注册成功")
return h.redirect("/login")
} catch (e) {

1
tsconfig.json

@ -13,6 +13,7 @@
"esModuleInterop": true, // esModuleInterop使import d from 'cjs'commonjs
"baseUrl": ".",
"paths": {
"@noderun/hapi-router": ["packages/hapi-router/src/index.ts"],
"@/*": ["source/*"],
"#/*": ["types/*"]
}

Loading…
Cancel
Save