-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (30 loc) · 950 Bytes
/
app.js
File metadata and controls
36 lines (30 loc) · 950 Bytes
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
require("dotenv").config();
// const bodyParser = require("body-parser");
const multer = require("multer");
const express = require("express");
const cors = require("cors");
const consola = require("consola");
const helmet = require("helmet");
const routes = require("./routes");
const upload = multer();
const app = express();
app.use(cors());
// app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({ extended: false }));
// app.use(helmet());
// app.use(helmet.xssFilter());
// app.use(helmet.noSniff());
app.disable("x-powered-by");
app.use("/api", upload.single("image"), routes);
app.get("/ping", (req, res) => {
res.send(`Ping test working - ${Date.now()}`);
});
// throws error if API not listed above
app.use((req, res, next) => {
const error = new Error("API endpoint is not valid");
error.status = 400;
res.status(error);
});
app.listen(8080, () => {
consola.success("server is live on http://localhost:8080");
});