-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (32 loc) · 1.05 KB
/
index.js
File metadata and controls
38 lines (32 loc) · 1.05 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
require("dotenv").config();
const express = require("express");
const locationsController = require("./src/locations/locations.controller");
const usersController = require("./src/users/users.controller");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
require("./src/authentication/local.strategy");
require("./src/authentication/jwt.strategy");
const passport = require("passport");
const cors = require("cors");
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.use(cors("*"));
// Protect all /locations route with JWT Authentication
app.use(
"/locations",
passport.authenticate("jwt", { session: false }),
locationsController
);
app.use("/users", usersController);
app.get("/", (req, res) => res.status(200).json({ message: "Hello World !" }));
async function main() {
await mongoose.connect(process.env.MONGO_URI);
console.log("Connected to Mongo Database");
app.listen(port, () => {
console.log(
`API listening on port ${port}, visit http://localhost:${port}/`
);
});
}
main();