改进 打包以及 Dockerfile
This commit is contained in:
parent
4d84f44ea4
commit
bad16623be
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ temp/
|
||||
yarn.lock
|
||||
ormconfig.json
|
||||
.env
|
||||
dist/
|
17
Dockerfile
17
Dockerfile
@ -2,18 +2,9 @@ FROM node:20
|
||||
LABEL authors="ivamp"
|
||||
|
||||
WORKDIR /app
|
||||
# 忽略 node_modules 目录
|
||||
COPY src /app/src
|
||||
COPY package.json /app/package.json
|
||||
COPY .env.example /app/.env.example
|
||||
COPY main.ts /app/main.ts
|
||||
|
||||
RUN npm config set registry https://registry.npm.taobao.org/
|
||||
RUN npm install
|
||||
# 将本文件夹 dist 下的目录复制
|
||||
ADD ./dist /app
|
||||
|
||||
|
||||
CMD [ "npm", "run", "migrate" ]
|
||||
|
||||
CMD [ "npm", "run", "start" ]
|
||||
|
||||
EXPOSE 8080
|
||||
EXPOSE 3000
|
||||
ENTRYPOINT ["node", "index.js"]
|
||||
|
@ -23,6 +23,9 @@
|
||||
"start": "ts-node main.ts",
|
||||
"typeorm": "typeorm-ts-node-commonjs",
|
||||
"migrate": "typeorm-ts-node-commonjs migration:run -d src/config/typeorm.ts",
|
||||
"migrate:rollback": "typeorm-ts-node-commonjs migration:revert -d src/config/typeorm.ts"
|
||||
"migrate:rollback": "typeorm-ts-node-commonjs migration:revert -d src/config/typeorm.ts",
|
||||
"make:migration": "typeorm-ts-node-commonjs migration:create",
|
||||
"migration:fresh": "typeorm-ts-node-commonjs schema:drop -d src/config/typeorm.ts",
|
||||
"build": "ncc build main.ts -o dist"
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,12 @@ import typeorm from "./typeorm";
|
||||
|
||||
typeorm.initialize().then(async () => {
|
||||
console.log("Datasource initialized.")
|
||||
}).catch(error => console.log(error))
|
||||
|
||||
|
||||
typeorm.runMigrations().then(async () => {
|
||||
console.log("Run database migrations.")
|
||||
typeorm.runMigrations().then(async () => {
|
||||
console.log("Migration run successfully.")
|
||||
}).catch(error => console.log(error))
|
||||
}).catch(error => console.log(error))
|
||||
|
||||
|
||||
export default typeorm.manager
|
@ -1,8 +1,19 @@
|
||||
import {NextFunction, Request, Response} from 'express'
|
||||
import {NextFunction, Response} from 'express'
|
||||
import {JWTRequest} from "../types/JWTRequest";
|
||||
|
||||
const getUser = (req: JWTRequest, res: Response, next: NextFunction) => {
|
||||
|
||||
// 检测有无 authorization
|
||||
if (!req.headers.authorization) {
|
||||
return res.status(401).send({
|
||||
'message': 'Unauthorized with no authorization header.'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 从 header 中获取 token
|
||||
|
||||
|
||||
const token = req.headers.authorization.split(' ')[1]
|
||||
|
||||
// 获取 JWT 的用户部分
|
||||
|
Loading…
Reference in New Issue
Block a user