-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (46 loc) · 1.6 KB
/
server.js
File metadata and controls
51 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import express from "express";
import { generateUploadURL, delArt } from "./s3.js";
import cors from "cors";
import bp from "body-parser";
//const express = require('express');
//const s3 = require('s3')
const app = express();
// uses body parser json for parsing json string sent from client
app.use(bp.json());
app.use(bp.urlencoded({ extended: true }));
app.use(express.static("front"));
app.use(cors({
origin: process.env.CLIENT_ALLOWED_URLS.split(" ")
}))
// uploads to profile-pics folder
app.get("/upload-profile-pic", async (req, res) => {
const url = await generateUploadURL('profile-pics/');
console.log(url)
res.send({url});
});
// uploads to artworks folder
// TODO: think abt changing design of uploads
app.get("/upload-art", async (req, res) => {
const url = await generateUploadURL('user-artwork/');
console.log(url)
res.send({url});
});
// deletes specified artwork url from db received from client
app.post("/delete-art", (req, res) => {
// parses json object of response first
console.log("hello client")
// const object = JSON.parse(req);
// gets url of artwork to be deleted
console.log("REQ", req.body.val)
const url = req.body.val;
console.log("URL", url)
// gets key from url (file path in s3 bucket)
const key = url.split("https://lasco-dev.s3.amazonaws.com/")[1];
// calls delArt fun in s3 with argument as artwork key so it can call s3
delArt(key)
res.send('hello')
});
// app.get("/art", async (req, res) => {
// // generates upload url, and sends it back
// })
app.listen(process.env.SERVER_PORT, () => console.log(`server listening at ${process.env.SERVER_PORT}`));