-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
39 lines (32 loc) · 1.18 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const jwt = require('jsonwebtoken');
const passport = require("passport");
const config = require('./config/index.js');
const authRoute = require("./server/routes/auth.js");
const noteRoute = require("./server/routes/notes.js");
var cors = require('cors')
// Database
// var databaseUri = 'mongodb://localhost/noteyDb';
const localSignup = require("./server/passport/local-signup.js");
const localLogin = require("./server/passport/local-login.js");
// const PORT = process.env.PORT || 3001;
const app = express();
// Configure body parser for AJAX requests
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static("client/build"));
passport.use("local-signup", localSignup)
passport.use("local-login", localLogin)
// Add routes, both API and view
app.use("/auth", authRoute);
app.use("/", noteRoute);
app.use(cors())
mongoose.connect(config.MONGO_URI, (err) => {
if (err) throw err;
console.log('Database successfully connected');
app.listen(config.PORT, () => {
console.log(`App listening on PORT ${config.PORT}`);
});
});