@tremho/mist-lift 1.0.2-pre-release.4 → 1.0.2-pre-release.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/actions/initQuestions.js +24 -22
- package/build/commands/actions/initQuestions.js.map +1 -1
- package/build/commands/actions/setupPackageJson.js +4 -4
- package/build/commands/actions/setupPackageJson.js.map +1 -1
- package/build/commands/build.js +31 -25
- package/build/commands/build.js.map +1 -1
- package/build/commands/builtin/ApiDocMaker.js +60 -23
- package/build/commands/builtin/ApiDocMaker.js.map +1 -1
- package/build/commands/builtin/BuiltInHandler.js +6 -6
- package/build/commands/builtin/BuiltInHandler.js.map +1 -1
- package/build/commands/builtin/DeployBuiltInZip.js +4 -4
- package/build/commands/builtin/DeployBuiltInZip.js.map +1 -1
- package/build/commands/builtin/StageWebrootZip.js +1 -0
- package/build/commands/builtin/StageWebrootZip.js.map +1 -1
- package/build/commands/create.js +10 -11
- package/build/commands/create.js.map +1 -1
- package/build/commands/deploy.js +38 -42
- package/build/commands/deploy.js.map +1 -1
- package/build/commands/doctor.js +38 -37
- package/build/commands/doctor.js.map +1 -1
- package/build/commands/help.js +93 -93
- package/build/commands/help.js.map +1 -1
- package/build/commands/init.js +7 -7
- package/build/commands/init.js.map +1 -1
- package/build/commands/package.js +50 -51
- package/build/commands/package.js.map +1 -1
- package/build/commands/publish.js +98 -102
- package/build/commands/publish.js.map +1 -1
- package/build/commands/settings.js +19 -18
- package/build/commands/settings.js.map +1 -1
- package/build/commands/start.js +4 -4
- package/build/commands/start.js.map +1 -1
- package/build/commands/test.js +3 -3
- package/build/commands/test.js.map +1 -1
- package/build/commands/user.js +1 -1
- package/build/commands/user.js.map +1 -1
- package/build/expressRoutes/all.js +27 -26
- package/build/expressRoutes/all.js.map +1 -1
- package/build/expressRoutes/api.js +9 -7
- package/build/expressRoutes/api.js.map +1 -1
- package/build/expressRoutes/functionBinder.js +38 -36
- package/build/expressRoutes/functionBinder.js.map +1 -1
- package/build/lib/CaseUtils.js +2 -2
- package/build/lib/CaseUtils.js.map +1 -1
- package/build/lib/DirectoryUtils.js +4 -3
- package/build/lib/DirectoryUtils.js.map +1 -1
- package/build/lib/LiftConfig.js +18 -20
- package/build/lib/LiftConfig.js.map +1 -1
- package/build/lib/LiftVersion.js +17 -12
- package/build/lib/LiftVersion.js.map +1 -1
- package/build/lib/Tests/fileCompare.test.js +11 -10
- package/build/lib/Tests/fileCompare.test.js.map +1 -1
- package/build/lib/askQuestion.js +3 -2
- package/build/lib/askQuestion.js.map +1 -1
- package/build/lib/executeCommand.js +46 -33
- package/build/lib/executeCommand.js.map +1 -1
- package/build/lib/fileCompare.js +9 -8
- package/build/lib/fileCompare.js.map +1 -1
- package/build/lib/openAPI/ApiBuildCollector.js +9 -8
- package/build/lib/openAPI/ApiBuildCollector.js.map +1 -1
- package/build/lib/openAPI/WebrootFileSupport.js +4 -3
- package/build/lib/openAPI/WebrootFileSupport.js.map +1 -1
- package/build/lib/openAPI/openApiConstruction.js +62 -61
- package/build/lib/openAPI/openApiConstruction.js.map +1 -1
- package/build/lib/pathResolve.js +4 -4
- package/build/lib/pathResolve.js.map +1 -1
- package/build/lib/utils.js +5 -4
- package/build/lib/utils.js.map +1 -1
- package/build/lift.js +14 -15
- package/build/lift.js.map +1 -1
- package/package.json +2 -1
- package/src/commands/actions/initQuestions.ts +112 -112
- package/src/commands/actions/setupPackageJson.ts +21 -25
- package/src/commands/build.ts +143 -146
- package/src/commands/builtin/ApiDocMaker.ts +86 -54
- package/src/commands/builtin/BuiltInHandler.ts +31 -35
- package/src/commands/builtin/DeployBuiltInZip.ts +15 -17
- package/src/commands/builtin/StageWebrootZip.ts +29 -32
- package/src/commands/create.ts +40 -47
- package/src/commands/deploy.ts +139 -152
- package/src/commands/doctor.ts +86 -82
- package/src/commands/help.ts +152 -153
- package/src/commands/init.ts +37 -39
- package/src/commands/package.ts +201 -204
- package/src/commands/publish.ts +277 -312
- package/src/commands/settings.ts +67 -70
- package/src/commands/start.ts +32 -37
- package/src/commands/test.ts +15 -16
- package/src/commands/user.ts +1 -1
- package/src/expressRoutes/all.ts +73 -78
- package/src/expressRoutes/api.ts +14 -16
- package/src/expressRoutes/functionBinder.ts +144 -151
- package/src/lib/CaseUtils.ts +49 -54
- package/src/lib/DirectoryUtils.ts +25 -27
- package/src/lib/LiftConfig.ts +46 -54
- package/src/lib/LiftVersion.ts +69 -77
- package/src/lib/Tests/fileCompare.test.ts +27 -26
- package/src/lib/askQuestion.ts +12 -13
- package/src/lib/executeCommand.ts +40 -33
- package/src/lib/fileCompare.ts +46 -37
- package/src/lib/openAPI/ApiBuildCollector.ts +36 -36
- package/src/lib/openAPI/WebrootFileSupport.ts +15 -17
- package/src/lib/openAPI/openApiConstruction.ts +169 -175
- package/src/lib/pathResolve.ts +22 -28
- package/src/lib/utils.ts +31 -33
- package/src/lift.ts +68 -67
package/src/commands/settings.ts
CHANGED
|
@@ -1,76 +1,73 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
3
|
-
import {LiftConfig, RuntimeType} from '../lib/LiftConfig'
|
|
4
|
-
import {homedir} from 'os'
|
|
5
|
-
import {ask} from
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import { LiftConfig, RuntimeType } from '../lib/LiftConfig'
|
|
4
|
+
import { homedir } from 'os'
|
|
5
|
+
import { ask } from '../lib/askQuestion'
|
|
6
6
|
import * as ac from 'ansi-colors'
|
|
7
7
|
|
|
8
|
+
export async function doSettings (): Promise<number> {
|
|
9
|
+
try {
|
|
10
|
+
const mistLiftPath = path.join(homedir(), '.mistlift')
|
|
11
|
+
let settings: LiftConfig = { cloudHost: 'AWS' }
|
|
12
|
+
if (fs.existsSync(mistLiftPath)) {
|
|
13
|
+
settings = JSON.parse(fs.readFileSync(mistLiftPath).toString())
|
|
14
|
+
}
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let ok = false;
|
|
20
|
-
while(!ok) {
|
|
21
|
-
settings.cloudHost = ask("Type of cloud host (AWS)",
|
|
22
|
-
"cloud host",
|
|
23
|
-
settings.cloudHost
|
|
24
|
-
)
|
|
25
|
-
ok = settings.cloudHost == "AWS" // all we support now
|
|
26
|
-
}
|
|
27
|
-
ok = false
|
|
28
|
-
|
|
29
|
-
if(settings.cloudHost === "AWS") {
|
|
30
|
-
console.log("Choose from a configured AWS profile, or leave empty to use a custom credentials config file")
|
|
31
|
-
while (!ok) {
|
|
32
|
-
settings.awsIniProfile = ask("Name of AWS profile to use",
|
|
33
|
-
"AWS Profile",
|
|
34
|
-
settings.awsIniProfile??"default"
|
|
35
|
-
)
|
|
36
|
-
ok = settings.awsIniProfile !== "";
|
|
37
|
-
}
|
|
38
|
-
ok = false;
|
|
39
|
-
let runtime:string = settings.awsNodeRuntime as string
|
|
40
|
-
while(!ok) {
|
|
41
|
-
runtime = ask("AWS Node Runtime Version",
|
|
42
|
-
"NodeJS Runtime",
|
|
43
|
-
"Nodejs20.x"
|
|
44
|
-
)
|
|
45
|
-
ok = !!runtime
|
|
46
|
-
}
|
|
47
|
-
settings.awsNodeRuntime = runtime.toLowerCase() as RuntimeType
|
|
16
|
+
let ok = false
|
|
17
|
+
while (!ok) {
|
|
18
|
+
settings.cloudHost = ask('Type of cloud host (AWS)',
|
|
19
|
+
'cloud host',
|
|
20
|
+
settings.cloudHost
|
|
21
|
+
)
|
|
22
|
+
ok = settings.cloudHost === 'AWS' // all we support now
|
|
23
|
+
}
|
|
24
|
+
ok = false
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
26
|
+
if (settings.cloudHost === 'AWS') {
|
|
27
|
+
ok = false
|
|
28
|
+
console.log('Choose from a configured AWS profile, or leave empty to use a custom credentials config file')
|
|
29
|
+
while (!ok) {
|
|
30
|
+
settings.awsIniProfile = ask('Name of AWS profile to use',
|
|
31
|
+
'AWS Profile',
|
|
32
|
+
settings.awsIniProfile ?? 'default'
|
|
33
|
+
)
|
|
34
|
+
ok = settings.awsIniProfile !== ''
|
|
35
|
+
}
|
|
36
|
+
ok = false
|
|
37
|
+
let runtime: string = settings.awsNodeRuntime as string
|
|
38
|
+
while (!ok) {
|
|
39
|
+
runtime = ask('AWS Node Runtime Version',
|
|
40
|
+
'NodeJS Runtime',
|
|
41
|
+
'Nodejs20.x'
|
|
42
|
+
)
|
|
43
|
+
ok = runtime !== ''
|
|
44
|
+
}
|
|
45
|
+
settings.awsNodeRuntime = runtime.toLowerCase() as RuntimeType
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
47
|
+
ok = false
|
|
48
|
+
while (!ok) {
|
|
49
|
+
settings.awsPreferredRegion = ask('Preferred AWS region',
|
|
50
|
+
'preferred AWS region',
|
|
51
|
+
settings.awsPreferredRegion ?? 'us-east-1'
|
|
52
|
+
)
|
|
53
|
+
ok = (settings.awsPreferredRegion ?? '') !== ''
|
|
54
|
+
}
|
|
55
|
+
ok = false
|
|
56
|
+
console.log('Supply the ARN for the service role you have created in your AWS IAM account for Lambda, S3, and Cloudwatch access')
|
|
57
|
+
while (!ok) {
|
|
58
|
+
settings.awsServiceRoleARN = ask('AWS service role ARN',
|
|
59
|
+
'serviceRole ARN',
|
|
60
|
+
settings.awsServiceRoleARN ?? 'arn:aws.iam::xxxxxxxxxxxx:role/service-role-name'
|
|
61
|
+
)
|
|
62
|
+
ok = settings.awsServiceRoleARN !== 'arn:aws.iam::xxxxxxxxxxxx:role/service-role-name' &&
|
|
63
|
+
settings.awsServiceRoleARN !== ''
|
|
64
|
+
}
|
|
75
65
|
}
|
|
76
|
-
|
|
66
|
+
fs.writeFileSync(mistLiftPath, JSON.stringify(settings))
|
|
67
|
+
|
|
68
|
+
return 0
|
|
69
|
+
} catch (e: any) {
|
|
70
|
+
console.error(ac.bold.red('Error with settings:'), e)
|
|
71
|
+
return -1
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/commands/start.ts
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
/** Run Express Server */
|
|
2
2
|
import express from 'express'
|
|
3
|
-
import fs from 'fs'
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import bodyParser from 'body-parser'
|
|
6
3
|
|
|
7
|
-
import functionRouter, {functionBinder} from
|
|
4
|
+
import functionRouter, { functionBinder } from '../expressRoutes/functionBinder'
|
|
8
5
|
|
|
9
|
-
import apiRouter from
|
|
10
|
-
import allRouter, {allBinder} from
|
|
11
|
-
import {
|
|
12
|
-
import {buildOpenApi} from "../lib/openAPI/openApiConstruction";
|
|
13
|
-
import {resolvePaths} from "../lib/pathResolve";
|
|
6
|
+
import apiRouter from '../expressRoutes/api'
|
|
7
|
+
import allRouter, { allBinder } from '../expressRoutes/all'
|
|
8
|
+
import { resolvePaths } from '../lib/pathResolve'
|
|
14
9
|
|
|
15
|
-
import * as ac from
|
|
10
|
+
import * as ac from 'ansi-colors'
|
|
16
11
|
|
|
17
|
-
export function startLocalServer() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
12
|
+
export function startLocalServer (): void {
|
|
13
|
+
const projectPaths = resolvePaths()
|
|
14
|
+
if (!projectPaths.verified) {
|
|
15
|
+
console.log(ac.bold.red('Cannot start local server'))
|
|
16
|
+
console.log(ac.blue.italic('Not in a valid MistLift project directory'))
|
|
17
|
+
console.log('')
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
const port = 8081
|
|
21
|
+
allBinder()
|
|
22
|
+
functionBinder()
|
|
23
|
+
const app = express()
|
|
24
|
+
// for JSON posts
|
|
25
|
+
// app.use(bodyParser.json({limit: '50mb'}))
|
|
26
|
+
app.use(express.json())
|
|
27
|
+
// for form posts
|
|
28
|
+
app.use(express.urlencoded({ extended: true }))
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
app.use('/', functionRouter)
|
|
31
|
+
app.use('/api', apiRouter)
|
|
32
|
+
app.use('*', allRouter)
|
|
38
33
|
|
|
39
|
-
// =========================================
|
|
40
|
-
// Start server
|
|
41
|
-
// http only
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
// =========================================
|
|
35
|
+
// Start server
|
|
36
|
+
// http only
|
|
37
|
+
app.listen(port, function () {
|
|
38
|
+
console.log(`http listening on port ${port}`)
|
|
39
|
+
})
|
|
45
40
|
// ================================================
|
|
46
|
-
}
|
|
41
|
+
}
|
package/src/commands/test.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {executeCommand} from
|
|
2
|
-
import {doBuildAsync} from
|
|
1
|
+
import { executeCommand } from '../lib/executeCommand'
|
|
2
|
+
import { doBuildAsync } from './build'
|
|
3
3
|
|
|
4
|
-
export async function doTestAsync(args:string[]
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const result = await executeCommand('tap', [
|
|
4
|
+
export async function doTestAsync (args: string[]): Promise<number> {
|
|
5
|
+
if (await doBuildAsync(args) !== 0) return 1 // don't test if build fails
|
|
6
|
+
if (args.length === 0) args = ['*']
|
|
7
|
+
let ret = 0
|
|
8
|
+
for (const funcName of args) {
|
|
9
|
+
const result = await executeCommand('tap', [
|
|
11
10
|
`build/functions/${funcName}/*-tests/*.js`,
|
|
12
11
|
/*
|
|
13
12
|
- base -- looks a lot like terse
|
|
@@ -27,12 +26,12 @@ export async function doTestAsync(args:string[] ): Promise<number>
|
|
|
27
26
|
'--allow-empty-coverage',
|
|
28
27
|
'--allow-incomplete-coverage'
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
], '', true)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
31
|
+
if (result.retcode !== 0) {
|
|
32
|
+
ret = result.retcode
|
|
33
|
+
break
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
}
|
|
36
|
+
return ret
|
|
37
|
+
}
|
package/src/commands/user.ts
CHANGED
package/src/expressRoutes/all.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import fs from
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
3
|
|
|
4
|
-
import * as ac from
|
|
5
|
-
import {resolvePaths} from
|
|
6
|
-
import {gatherFunctionDefinitions} from
|
|
4
|
+
import * as ac from 'ansi-colors'
|
|
5
|
+
import { resolvePaths } from '../lib/pathResolve'
|
|
6
|
+
import { gatherFunctionDefinitions } from '../lib/openAPI/ApiBuildCollector'
|
|
7
7
|
|
|
8
8
|
import express from 'express'
|
|
9
|
-
const router = express.Router()
|
|
9
|
+
const router = express.Router()
|
|
10
10
|
|
|
11
|
-
export function allBinder() {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export function allBinder (): void {
|
|
12
|
+
const projectPaths = resolvePaths()
|
|
13
|
+
const defs = gatherFunctionDefinitions()
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
16
|
* @name /all
|
|
17
17
|
* @description
|
|
18
18
|
* Catch-all handler for URLs
|
|
@@ -27,78 +27,73 @@ export function allBinder() {
|
|
|
27
27
|
* - File contents passed through using `sendFile` (will handle its own 404 if not found)
|
|
28
28
|
*
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
router.all('*', (req, res, next) => {
|
|
31
|
+
// any PHP requests should be ignored
|
|
32
|
+
// ClogTrace('incoming: '+req.originalUrl)
|
|
33
|
+
if (req.originalUrl.includes('.php')) {
|
|
34
|
+
return res.send('')
|
|
35
|
+
}
|
|
36
|
+
if (req.originalUrl.includes('.env')) {
|
|
37
|
+
return res.send('')
|
|
38
|
+
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
let filepath = req.originalUrl ?? '/'
|
|
41
|
+
// match cloud behavior for docs because /api doesn't change cwd there
|
|
42
|
+
if (filepath.substring(0, 10) === '/api/docs/') {
|
|
43
|
+
filepath = filepath.replace('/api', '')
|
|
44
|
+
}
|
|
45
|
+
let funcFound = filepath === '/api' // reserved "function"
|
|
46
|
+
if (!funcFound) {
|
|
47
|
+
if (filepath.charAt(0) === '/') {
|
|
48
|
+
let n = filepath.indexOf('/', 1)
|
|
49
|
+
if (n === -1) n = filepath.length
|
|
50
|
+
let rootEntity = filepath.substring(0, n)
|
|
51
|
+
n = rootEntity.indexOf('?')
|
|
52
|
+
if (n === -1) n = rootEntity.length
|
|
53
|
+
rootEntity = rootEntity.substring(0, n)
|
|
54
|
+
for (const entry of defs) {
|
|
55
|
+
let entryRoot = entry.pathMap
|
|
56
|
+
const n = entryRoot.indexOf('/{')
|
|
57
|
+
if (n !== -1) entryRoot = entryRoot.substring(0, n)
|
|
58
|
+
if (rootEntity === entryRoot) {
|
|
59
|
+
funcFound = true
|
|
60
|
+
break
|
|
61
|
+
}
|
|
36
62
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
63
|
+
}
|
|
64
|
+
}
|
|
41
65
|
|
|
66
|
+
if (!funcFound) {
|
|
67
|
+
// check for '/' in path beyond the first one
|
|
68
|
+
if (filepath.includes('/', 1)) {
|
|
69
|
+
// console.log(ac.magenta.italic("Warning: / path delimiters will not be honored in a cloud deployment, use + instead ")+filepath)
|
|
70
|
+
}
|
|
71
|
+
// convert any incoming + to / to match cloud behavior
|
|
72
|
+
while (filepath.includes('+')) filepath = filepath.replace('+', '/')
|
|
42
73
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
// Put any other filtering here
|
|
75
|
+
if (filepath.includes('?')) {
|
|
76
|
+
filepath = filepath.substring(0, filepath.indexOf('?'))
|
|
77
|
+
}
|
|
78
|
+
if (filepath.substring(filepath.length - 1) === '/') filepath += 'index.html'
|
|
79
|
+
if (filepath.substring(0, 10) === '/api/docs/') {
|
|
80
|
+
filepath = filepath.replace('/api', '')
|
|
81
|
+
}
|
|
82
|
+
if (filepath.includes('/docs')) {
|
|
83
|
+
if (filepath.includes('.map')) {
|
|
84
|
+
return res.sendStatus(200)
|
|
47
85
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (n !== -1) entryRoot = entryRoot.substring(0, n);
|
|
61
|
-
if (rootEntity === entryRoot) {
|
|
62
|
-
funcFound = true;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!funcFound) {
|
|
70
|
-
// check for '/' in path beyond the first one
|
|
71
|
-
if(filepath.indexOf('/',1) !== -1)
|
|
72
|
-
{
|
|
73
|
-
// console.log(ac.magenta.italic("Warning: / path delimiters will not be honored in a cloud deployment, use + instead ")+filepath)
|
|
74
|
-
}
|
|
75
|
-
// convert any incoming + to / to match cloud behavior
|
|
76
|
-
while(filepath.indexOf("+")!== -1) filepath = filepath.replace("+", "/")
|
|
77
|
-
|
|
78
|
-
// Put any other filtering here
|
|
79
|
-
if (filepath.indexOf('?') !== -1) {
|
|
80
|
-
filepath = filepath.substring(0, filepath.indexOf('?'))
|
|
81
|
-
}
|
|
82
|
-
if (filepath.substring(filepath.length - 1) === '/') filepath += 'index.html'
|
|
83
|
-
if(filepath.substring(0, 10) == '/api/docs/') {
|
|
84
|
-
filepath = filepath.replace('/api', '');
|
|
85
|
-
}
|
|
86
|
-
if(filepath.indexOf("/docs") !== -1) {
|
|
87
|
-
if(filepath.indexOf('.map') !== -1) {
|
|
88
|
-
return res.sendStatus(200)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
filepath = path.resolve(path.join(projectPaths.basePath, 'webroot', filepath)) // .. out of build
|
|
92
|
-
if (fs.existsSync(filepath)) {
|
|
93
|
-
return res.sendFile(filepath)
|
|
94
|
-
} else {
|
|
95
|
-
console.log(ac.red.bold("can't find " + filepath));
|
|
96
|
-
return res.sendStatus(404);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// if none of the above, tickle enumerator so we can process other paths
|
|
100
|
-
next()
|
|
101
|
-
})
|
|
86
|
+
}
|
|
87
|
+
filepath = path.resolve(path.join(projectPaths.basePath, 'webroot', filepath)) // .. out of build
|
|
88
|
+
if (fs.existsSync(filepath)) {
|
|
89
|
+
return res.sendFile(filepath)
|
|
90
|
+
} else {
|
|
91
|
+
console.log(ac.red.bold("can't find " + filepath))
|
|
92
|
+
return res.sendStatus(404)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// if none of the above, tickle enumerator so we can process other paths
|
|
96
|
+
next()
|
|
97
|
+
})
|
|
102
98
|
}
|
|
103
99
|
export default router
|
|
104
|
-
|
package/src/expressRoutes/api.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-var-requires: "off" */
|
|
1
2
|
import express from 'express'
|
|
2
|
-
const router = express.Router();
|
|
3
3
|
|
|
4
|
-
import {getProjectName, getProjectVersion} from
|
|
4
|
+
import { getProjectName, getProjectVersion } from '../lib/LiftVersion'
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const openApiUi = require('openapi-ui')
|
|
7
|
+
const router = express.Router()
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
router.get('/', function(req, res, next) {
|
|
9
|
+
router.get('/', function (req, res, next) {
|
|
10
10
|
res.send(generateApiDoc())
|
|
11
|
-
})
|
|
11
|
+
})
|
|
12
12
|
|
|
13
13
|
export default router
|
|
14
14
|
|
|
15
|
-
function generateApiDoc()
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
15
|
+
function generateApiDoc (): void {
|
|
16
|
+
console.log('---- Serving up api')
|
|
17
|
+
return openApiUi.generateIndex({
|
|
18
|
+
baseUrl: 'docs',
|
|
19
|
+
title: `${getProjectName() ?? ''} ${getProjectVersion()?.toString() ?? ''}`,
|
|
20
|
+
url: 'docs/apidoc.yaml'
|
|
21
|
+
})
|
|
22
|
+
}
|