-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathserver.js
More file actions
97 lines (78 loc) · 2.87 KB
/
server.js
File metadata and controls
97 lines (78 loc) · 2.87 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
93
94
95
96
97
import Nullstack from 'nullstack'
import cors from 'cors'
import express from 'express'
import Application from './src/Application'
import CatchError from './src/CatchError'
import ContextProject from './src/ContextProject'
import ContextSecrets from './src/ContextSecrets'
import ContextSettings from './src/ContextSettings'
import ContextWorker from './src/ContextWorker'
import ExposedServerFunctions from './src/ExposedServerFunctions'
import setExternalRoute from './src/externalRoute'
import vueable from './src/plugins/vueable'
import ReqRes from './src/ReqRes'
Nullstack.use(vueable)
const context = Nullstack.start(Application)
const methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT']
context.server.use(
cors({
origin: 'http://localhost:6969',
optionsSuccessStatus: 200,
}),
)
context.server.use(express.json())
context.worker.staleWhileRevalidate = [/[0-9]/]
context.worker.cacheFirst = [/[0-9]/]
context.server
.get('/data/get/:param', ExposedServerFunctions.getData)
.get('/chainable-server-function', (request, response) => {
response.json({ chainable: true })
})
.get('/chainable-regular-function', (request, response) => {
response.json({ chainable: true })
})
context.server.get('/data/all/:param', ExposedServerFunctions.getData)
context.server.post('/data/post/:param', ExposedServerFunctions.getData)
context.server.put('/data/put/:param', ExposedServerFunctions.getData)
context.server.patch('/data/patch/:param', ExposedServerFunctions.getData)
context.server.delete('/data/delete/:param', ExposedServerFunctions.getData)
context.server.get('/exposed-server-function-url.json', ReqRes.exposedServerFunction)
context.server.get('/nested-exposed-server-function-url.json', ReqRes.nestedExposedServerFunction)
context.server.get('/custom-api-before-start', (request, response) => {
response.json({ startValue: context.startValue })
})
context.server.use('/api', (request, response, next) => {
request.status = 200
if (!response.headersSent) {
next()
}
})
for (const method of methods) {
context.server[method.toLowerCase()]('/api', (request, response) => {
response.status(request.status).json({ method: request.method })
})
}
context.server.get('/vaidamerdanaapi.json', (_request, response) => {
response.vaidamerdanaapi()
})
context.startIncrementalValue = 0
setExternalRoute(context.server)
context.server.use((request, response, next) => {
context.url = request.originalUrl
next()
})
context.start = async function () {
await ContextProject.start(context)
await ContextSecrets.start(context)
await ContextSettings.start(context)
await ContextWorker.start(context)
context.startValue = true
context.startIncrementalValue++
}
context.catch = async function (error) {
CatchError.logError({ message: error.message })
if (context.environment.development) {
console.error(error)
}
}
export default context