-
Notifications
You must be signed in to change notification settings - Fork 3
/
express-param.html
53 lines (43 loc) · 1.42 KB
/
express-param.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
43
44
45
46
47
48
49
50
51
52
53
<script>
class ExpressParam extends HTMLElement {
constructor() {
super();
this.name = null;
this.callback = null;
}
static get observedAttributes() {
return [
'name'
];
}
attributeChangedCallback(name, oldValue, newValue) {
switch (name) {
case 'name': {
this.name = newValue;
break;
}
}
}
expressReadyCallback(app, express, router, route) {
if (router) {
prepareWithRouter(this, router);
}
else {
prepareWithApp(this, app);
}
function prepareWithRouter(context, router) {
if (!context.name) {
console.log('using router.param() without specifying a name is deprecated as of Express v4.11.0');
}
if (Array.isArray(context.name)) {
throw 'ExpressParamError: router.param() does not accept an array of route parameters';
}
router.param(context.name, context.callback);
}
function prepareWithApp(context, app) {
app.param(context.name, context.callback);
}
}
}
window.customElements.define('express-param', ExpressParam);
</script>