{"size": 939, "ext": "js", "max_stars_repo_path": "uploadservice/index.js", "max_stars_repo_name": "ngid-dev/ngid-upload", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "uploadservice/index.js", "max_issues_repo_name": "ngid-dev/ngid-upload", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "uploadservice/index.js", "max_forks_repo_name": "ngid-dev/ngid-upload", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0769230769, "max_line_length": 101, "alphanum_fraction": 0.6059637913}
const express = require("express");
const multer = require("multer");
const cors = require('cors');

const storage = multer.diskStorage({
  destination: (req, file, cb) => {
      cb(null, 'upload');
  },
  filename: (req, file, cb) => {
    const fileName = Date.now() + "-" + file.originalname;
    cb(null, fileName);
  },
});

const upload = multer({ storage });

const app = express();

app.use(cors({ origin: '*'}))

app.use(express.json());

app.get("/", (req, res) => {
  res.status(200).send("Ok!!!");
});

app.post("/api/v1/upload", upload.single("files"), (req, res) => {
  console.log(req.file);
  console.log(req.files);
  return res.status(200).send({ fileUrl: `http://locahost:3000/api/v1/upload/${req.file.filename}`});
});

app.get('/api/v1/upload/:fileName', (req, res) => {
    console.log(req.params.fileName);
    return res.status(200).send({ message: 'Ok'});
})

app.listen(3000, () => console.log("Server is up"));
