-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
28 lines (22 loc) · 914 Bytes
/
Copy pathapi.js
File metadata and controls
28 lines (22 loc) · 914 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
require('dotenv').config()
const express = require('express')
const spell = require('./spells.controller')
const mongoose = require('mongoose')
const { Auth, isAuthenticated } = require('./auth.controller')
mongoose.connect(`mongodb+srv://${process.env.MONGODB_USER}:${process.env.MONGODB_PASSWORD}@cluster0.klxnqmt.mongodb.net/spellsproject?retryWrites=true&w=majority`)
const app = express();
app.use(express.json())
app.get('/spells', isAuthenticated, spell.listAll)
app.get('/spells/:id', isAuthenticated, spell.get)
app.post('/spells', isAuthenticated, spell.create)
app.delete('/spells/:id', isAuthenticated, spell.delete)
app.post('/login', Auth.login)
app.post('/register', Auth.register)
app.use(express.static('app'))
app.get('/', (req, res) => {
console.log(__dirname);
res.sendFile(`${__dirname}/index.html`);
})
app.listen('3000', () => {
console.log("Listening on port 3000...");
})