-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathindex.js
More file actions
92 lines (76 loc) · 2.07 KB
/
index.js
File metadata and controls
92 lines (76 loc) · 2.07 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
81
82
83
84
85
86
87
88
89
90
91
92
import './dotenv'
import { normalize } from 'path'
import element from '../shared/element'
import getProxyableMethods from '../shared/getProxyableMethods'
import { useServerPlugins } from '../shared/plugins'
import context from './context'
import environment from './environment'
import generator from './generator'
import instanceProxyHandler from './instanceProxyHandler'
import project from './project'
import secrets from './secrets'
import server from './server'
import settings from './settings'
import worker from './worker'
import fetch from 'node-fetch'
globalThis.window = {}
if (!global.fetch) {
global.fetch = fetch
}
if (!global.location) {
global.location = {
href: '/',
}
}
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])
if (environment.development) {
globalThis.$nullstack = context
}
class Nullstack {
static use = useServerPlugins
static start(Starter) {
if (this === Nullstack) {
generator.starter = () => element(Starter)
setTimeout(server.start, 0)
return context
}
}
prerendered = true
initiated = false
hydrated = false
terminated = false
key = null
constructor() {
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 (name === 'prerendered') continue
if (name === 'initiated') continue
if (name === 'hydrated') continue
if (name === 'terminated') continue
if (name === 'key') continue
if (name === '_attributes') continue
if (name === '_scope') continue
if (typeof this[name] === 'function') continue
serialized[name] = this[name]
}
return serialized
}
render() {
return false
}
}
export default Nullstack