-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexpress-route.html
42 lines (35 loc) · 1004 Bytes
/
express-route.html
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
<script>
class ExpressRouteComponent extends HTMLElement {
constructor() {
super();
this.path = null;
}
static get observedAttributes() {
return [
'path'
];
}
attributeChangedCallback(name, oldValue, newValue) {
switch (name) {
case 'path': {
this.path = newValue;
break;
}
}
}
expressReadyCallback(app, express, router, route) {
const parent = getParent(app, router);
const newRoute = parent.route(this.path);
this.route = newRoute;
function getParent(app, router) {
if (router) {
return router;
}
else {
return app;
}
}
}
}
window.customElements.define('express-route', ExpressRoute);
</script>