mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
add upload config
This commit is contained in:
16
backend/src/config/upload.ts
Normal file
16
backend/src/config/upload.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import path from "path";
|
||||||
|
import multer from "multer";
|
||||||
|
|
||||||
|
const publicFolder = path.resolve(__dirname, "..", "..", "public");
|
||||||
|
export default {
|
||||||
|
directory: publicFolder,
|
||||||
|
|
||||||
|
storage: multer.diskStorage({
|
||||||
|
destination: publicFolder,
|
||||||
|
filename(req, file, cb) {
|
||||||
|
const fileName = new Date().getTime() + path.extname(file.originalname);
|
||||||
|
|
||||||
|
return cb(null, fileName);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
@@ -1,25 +1,33 @@
|
|||||||
|
import "reflect-metadata";
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
import "express-async-errors";
|
import "express-async-errors";
|
||||||
import express, { Request, Response, NextFunction } from "express";
|
import express, { Request, Response, NextFunction } from "express";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import AppError from "./errors/AppError";
|
import multer from "multer";
|
||||||
|
import Sentry from "@sentry/node";
|
||||||
|
|
||||||
|
import uploadConfig from "./config/upload";
|
||||||
|
import AppError from "./errors/AppError";
|
||||||
import routes from "./routes";
|
import routes from "./routes";
|
||||||
import "./database";
|
import "./database";
|
||||||
|
|
||||||
// import path from "path";
|
// import path from "path";
|
||||||
// import multer from "multer";
|
|
||||||
// import Sentry from "@sentry/node";
|
|
||||||
|
|
||||||
// const { initWbot } = require("./libs/wbot");
|
// const { initWbot } = require("./libs/wbot");
|
||||||
// const wbotMessageListener = require("./services/wbotMessageListener");
|
// const wbotMessageListener = require("./services/wbotMessageListener");
|
||||||
// const wbotMonitor = require("./services/wbotMonitor");
|
// const wbotMonitor = require("./services/wbotMonitor");
|
||||||
// const Whatsapp = require("./models/Whatsapp");
|
// const Whatsapp = require("./models/Whatsapp");
|
||||||
|
|
||||||
|
Sentry.init({ dsn: process.env.SENTRY_DSN });
|
||||||
|
|
||||||
|
const upload = multer(uploadConfig);
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
app.use(Sentry.Handlers.requestHandler());
|
||||||
|
app.use(upload.single("media"));
|
||||||
|
app.use("/public", express.static(uploadConfig.directory));
|
||||||
app.use(routes);
|
app.use(routes);
|
||||||
|
|
||||||
app.use(async (err: Error, req: Request, res: Response, _: NextFunction) => {
|
app.use(async (err: Error, req: Request, res: Response, _: NextFunction) => {
|
||||||
@@ -35,22 +43,6 @@ const server = app.listen(process.env.PORT, () => {
|
|||||||
console.log(`Server started on port: ${process.env.PORT}`);
|
console.log(`Server started on port: ${process.env.PORT}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sentry.init({ dsn: process.env.SENTRY_DSN });
|
|
||||||
|
|
||||||
// const fileStorage = multer.diskStorage({
|
|
||||||
// destination: (req, file, cb) => {
|
|
||||||
// cb(null, path.resolve(__dirname, "..", "public"));
|
|
||||||
// },
|
|
||||||
// filename: (req, file, cb) => {
|
|
||||||
// cb(null, new Date().getTime() + path.extname(file.originalname));
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// app.use(Sentry.Handlers.requestHandler());
|
|
||||||
// app.use(multer({ storage: fileStorage }).single("media"));
|
|
||||||
// app.use("/public", express.static(path.join(__dirname, "..", "public")));
|
|
||||||
// app.use(Router);
|
|
||||||
|
|
||||||
// const io = require("./libs/socket").init(server);
|
// const io = require("./libs/socket").init(server);
|
||||||
// io.on("connection", socket => {
|
// io.on("connection", socket => {
|
||||||
// console.log("Client Connected");
|
// console.log("Client Connected");
|
||||||
|
|||||||
Reference in New Issue
Block a user