forked from processing/p5.js-web-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.routes.js
156 lines (130 loc) · 3.72 KB
/
server.routes.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { Router } from 'express';
import sendHtml, { renderIndex } from '../views/index';
import { userExists } from '../controllers/user.controller';
import {
projectExists,
projectForUserExists
} from '../controllers/project.controller';
import { collectionForUserExists } from '../controllers/collection.controller';
const router = new Router();
// const fallback404 = (res) => (exists) =>
// exists ? res.send(renderIndex()) : get404Sketch((html) => res.send(html));
// this is intended to be a temporary file
// until i figure out isomorphic rendering
router.get('/', (req, res) => {
res.send(renderIndex());
});
router.get('/signup', (req, res) => {
if (req.user) {
return res.redirect('/');
}
return res.send(renderIndex());
});
router.get('/projects/:project_id', async (req, res) => {
const exists = await projectExists(req.params.project_id);
sendHtml(req, res, exists);
});
router.get(
'/:username/sketches/:project_id/add-to-collection',
async (req, res) => {
const exists = await projectForUserExists(
req.params.username,
req.params.project_id
);
sendHtml(req, res, exists);
}
);
router.get('/:username/sketches/:project_id', async (req, res) => {
const exists = await projectForUserExists(
req.params.username,
req.params.project_id
);
sendHtml(req, res, exists);
});
router.get('/:username/sketches', async (req, res) => {
const exists = await userExists(req.params.username);
sendHtml(req, res, exists);
});
router.get('/:username/full/:project_id', async (req, res) => {
const exists = await projectForUserExists(
req.params.username,
req.params.project_id
);
sendHtml(req, res, exists);
});
router.get('/full/:project_id', async (req, res) => {
const exists = await projectExists(req.params.project_id);
sendHtml(req, res, exists);
});
router.get('/login', (req, res) => {
if (req.user) {
return res.redirect('/');
}
return res.send(renderIndex());
});
router.get('/reset-password', (req, res) => {
if (req.user) {
return res.redirect('/account');
}
return res.send(renderIndex());
});
router.get('/reset-password/:reset_password_token', (req, res) => {
if (req.user) {
return res.redirect('/account');
}
return res.send(renderIndex());
});
router.get('/verify', (req, res) => {
res.send(renderIndex());
});
router.get('/sketches', (req, res) => {
if (req.user) {
const { username } = req.user;
return res.redirect(`/${username}/sketches`);
}
return res.redirect('/login');
});
router.get('/assets', (req, res) => {
if (req.user) {
const { username } = req.user;
return res.redirect(`/${username}/assets`);
}
return res.redirect('/login');
});
router.get('/:username/assets', async (req, res) => {
const exists = await userExists(req.params.username);
const isLoggedInUser = req.user && req.user.username === req.params.username;
const canAccess = exists && isLoggedInUser;
sendHtml(req, res, canAccess);
});
router.get('/account', (req, res) => {
if (req.user) {
res.send(renderIndex());
} else {
res.redirect('/login');
}
});
router.get('/about', (req, res) => {
res.send(renderIndex());
});
router.get('/:username/collections/:id', async (req, res) => {
const exists = await collectionForUserExists(
req.params.username,
req.params.id
);
sendHtml(req, res, exists);
});
router.get('/:username/collections', async (req, res) => {
const exists = await userExists(req.params.username);
sendHtml(req, res, exists);
});
router.get('/privacy-policy', (req, res) => {
res.send(renderIndex());
});
router.get('/terms-of-use', (req, res) => {
res.send(renderIndex());
});
router.get('/code-of-conduct', (req, res) => {
res.send(renderIndex());
});
export default router;