forked from nullstack/nullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (68 loc) · 2 KB
/
index.js
File metadata and controls
80 lines (68 loc) · 2 KB
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
import 'dotenv/config';
import { normalize } from 'path';
import element from '../shared/element';
import fragment from '../shared/fragment';
import getProxyableMethods from '../shared/getProxyableMethods';
import { usePlugins } from '../shared/plugins';
import context from './context';
import environment from './environment';
import generator from './generator';
import instanceProxyHandler from './instanceProxyHandler';
import invoke from './invoke';
import project from './project';
import registry from './registry';
import secrets from './secrets';
import server from './server';
import settings from './settings';
import worker from './worker';
globalThis.window = {}
context.server = server;
context.project = project;
context.environment = environment;
context.settings = settings;
context.secrets = secrets;
context.worker = worker;
server.less = normalize(__filename) !== normalize(process.argv[1])
class Nullstack {
static registry = registry;
static element = element;
static invoke = invoke;
static fragment = fragment;
static use = usePlugins('server');
static start(Starter) {
if (this.name.indexOf('Nullstack') > -1) {
generator.starter = () => element(Starter);
setTimeout(server.start, 0)
return context;
}
}
_self = {
prerendered: true,
initiated: false,
hydrated: false,
terminated: false,
}
constructor(scope) {
this._request = () => scope.request;
this._response = () => scope.response;
const methods = getProxyableMethods(this);
const proxy = new Proxy(this, instanceProxyHandler);
for (const method of methods) {
this[method] = this[method].bind(proxy);
}
return proxy;
}
toJSON() {
const serialized = {};
for (const name of Object.getOwnPropertyNames(this)) {
if (typeof (this[name]) !== 'function' && !name.startsWith('_') && name !== 'attributes') {
serialized[name] = this[name];
}
}
return serialized;
}
render() {
return false;
}
}
export default Nullstack;