-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
35 lines (29 loc) · 938 Bytes
/
index.ts
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
import express, { Application } from "express";
import cors = require("cors");
import { getCertification } from "./proxy";
import { server } from "./https";
import { fetch, save } from "./photoStorage";
const port = 3000;
const app: Application = express();
app.use(cors());
app.use(express.json({ limit: "5mb" }));
server(app, port, () => console.log(`https server listen on port ${port}`));
app.get("/certifications/:hashedCertificationId", (req, res) =>
getCertification(req.params.hashedCertificationId).then(cert =>
res.send(cert)
)
);
app.post("/photos", function(req, res) {
save(req.body).then(urls => {
res.send(urls);
}, console.error);
});
app.get("/photos/:certId", (req, res, next) => {
fetch({ certId: req.params.certId }).then(results => {
if (results.length > 0) {
res.send(results[0]);
} else {
res.status(404).send(`No photos found for ${req.params.certId}`);
}
});
});