fixed docker deployment
This commit is contained in:
parent
b82c2dc1d6
commit
a1890acad0
|
@ -130,3 +130,13 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
build/
|
||||
.env
|
||||
|
||||
backend/build
|
||||
backend/node-modules
|
||||
|
||||
frontend/build
|
||||
frontend/node-modules
|
||||
|
||||
data/
|
||||
|
|
|
@ -2,7 +2,8 @@ FROM node:22-bullseye
|
|||
|
||||
WORKDIR /opt/backend
|
||||
|
||||
COPY . .
|
||||
COPY backend .
|
||||
COPY .env .
|
||||
RUN npm i
|
||||
|
||||
EXPOSE 3000
|
|
@ -1,7 +1,7 @@
|
|||
import express from "express";
|
||||
import { AppDataSource } from "./data-source";
|
||||
import UserRouter from "./routers/user";
|
||||
import bodyParser from "body-parser";
|
||||
import fs from 'fs';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import PostRouter from "./routers/post";
|
||||
import session from "express-session";
|
||||
|
@ -17,6 +17,8 @@ app.use(session({
|
|||
saveUninitialized: false,
|
||||
}));
|
||||
|
||||
if (!fs.existsSync(process.env.UPLOAD_DESTINATION)) fs.mkdirSync(process.env.UPLOAD_DESTINATION);
|
||||
|
||||
AppDataSource.initialize().then(() => {
|
||||
app.use('/api/v1/user/', UserRouter);
|
||||
app.use('/api/v1/post/', PostRouter);
|
||||
|
|
|
@ -20,7 +20,7 @@ const handlePostData = async (req: Request, res: Response, next: NextFunction):
|
|||
|
||||
if (postToUpdate.type == 1) {
|
||||
const filename = postToUpdate.message;
|
||||
fs.rmSync(`${process.env.UPLOAD_DESTINATION}/${filename}`);
|
||||
fs.unlinkSync(`${process.env.UPLOAD_DESTINATION}/${filename}`);
|
||||
}
|
||||
}
|
||||
if (req.file) {
|
||||
|
@ -33,9 +33,10 @@ const handlePostData = async (req: Request, res: Response, next: NextFunction):
|
|||
const hash = crypto.createHash('md5');
|
||||
hash.update(buffer);
|
||||
const newFilename = `${hash.digest('hex')}${extension}`;
|
||||
fs.renameSync(`./${req.file.path}`, `${process.env.UPLOAD_DESTINATION}/${newFilename}`)
|
||||
post.message = newFilename
|
||||
post.type = 1
|
||||
fs.copyFileSync(`./${req.file.path}`, `${process.env.UPLOAD_DESTINATION}/${newFilename}`);
|
||||
fs.unlinkSync(`./${req.file.path}`);
|
||||
post.message = newFilename;
|
||||
post.type = 1;
|
||||
} else {
|
||||
post.type = 0;
|
||||
post.message = message;
|
||||
|
|
|
@ -11,7 +11,9 @@ services:
|
|||
healthcheck:
|
||||
test: pg_isready -U $${DB_USER} -d $${DB_NAME}
|
||||
backend:
|
||||
build: backend
|
||||
build:
|
||||
context: .
|
||||
dockerfile: backend.Dockerfile
|
||||
env_file: .env
|
||||
ports:
|
||||
- 8080:${APP_PORT}
|
||||
|
@ -19,4 +21,4 @@ services:
|
|||
- database
|
||||
restart: on-failure
|
||||
volumes:
|
||||
- ./data/files:${PWD}/${UPLOAD_DESTINATION}
|
||||
- ./data/files:${UPLOAD_DESTINATION}
|
||||
|
|
Loading…
Reference in New Issue