-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
27 lines (22 loc) · 961 Bytes
/
server.js
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
const express = require("express");
const handleError = require("./middleware/error");
const auth = require("./middleware/auth");
const examples = require("./handlers/examples-handlers");
const users = require("./handlers/users-handlers");
require("dotenv").config();
const PORT = process.env.PORT || 3000;
const server = express();
server.use(express.json());
server.get("/", examples.getAllExamples);
server.post("/examples", auth, examples.postExample);
server.get("/examples/:id", examples.getExample);
server.delete("/examples/:id", auth, examples.deleteExample);
server.put("/examples/:id", auth, examples.updateExample);
server.post("/signup", users.signup);
server.post("/login", users.login);
server.use(handleError);
// If this env exists we are in testing mode so don't start the server
if (process.env.PGDATABASE !== "localtest") {
server.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`));
}
module.exports = server;