-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
82 lines (68 loc) · 2.57 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import express from 'express';
import morgan from 'morgan';
// TODO: What is cors?????
import cors from 'cors';
import cookieParser from 'cookie-parser';
import authRouter from './routes/auth.js';
import db from './database.js';
import userRouter from './routes/user.js';
import fileUpload from 'express-fileupload';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
db.schema.hasTable('users').then(function(exists) {
if (!exists) {
db.schema.createTable('users', function(user) {
user.string('uid');
user.string('email');
user.string('first_name');
user.string('last_name');
user.string('video_uri');
user.string('photo_uri');
user.string('bio');
user.boolean('is_online');
user.string('created_at');
user.string('updated_at');
}).then(function(table) {
console.log('Created Table', table);
});
}
});
const port = 5000;
const app = express();
app.use(fileUpload());
app.use(cors());
app.use(cookieParser()); // populates req.cookies.
app.use(morgan('dev')); // give back development data,
app.use(express.json()) // for parsing application/json
// TODO(Noah): WHEN WE ARE DONE BUILDING THE PROJECT
app.use(express.static(`${__dirname}/frontend/build`));
app.get(/.*/, (req, res) => res.sendFile(`frontend/build/index.html`, { root: __dirname }));
app.use('/api/auth', authRouter);
app.use('/api/user', userRouter);
app.listen(port, () => {
console.log(`Server running on port ${port}`)
})
/*
app.post('/login', function(req, res) {
let email = req.body.email;
let password = req.body.password;
/* So, what is going on with the cookies here?
They are sent on each request, apparently.
We can set expiration times for cookies.
- So the auth flow is kind of like this, then. The browser client
logs in. The server gives it back a cookie. And the browser client
continues each request with that cookie.
- And this cookie expires after some time, maybe a few months, lets say.
Seems that we can use the Set-Cookie header to store a cookie in the client.
We should always be seing session cookies.
We want to update this to make it secure and to prevent
session fixation attacks: https://developer.mozilla.org/en-US/docs/Web/Security/Types_of_attacks#session_fixation
SignInWithEmailAndPassword(email, password)
.then((cookie) => {
}).catch(() => {
// what do we even do here lol.
});
// res.send({email, password});
});
*/