@reactful/create 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/README.md +7 -7
  2. package/commons/package.json +21 -21
  3. package/commons/tsconfig.json +24 -24
  4. package/index.js +148 -148
  5. package/package.json +31 -31
  6. package/templates/minimal/components/hello.tsx +8 -8
  7. package/templates/minimal/components/icon.tsx +11 -0
  8. package/templates/minimal/components/index.ts +2 -1
  9. package/templates/minimal/routes/index.tsx +7 -6
  10. package/templates/sampling/apis/auth/db.ts +14 -14
  11. package/templates/sampling/apis/auth/index.ts +27 -27
  12. package/templates/sampling/apis/hello.ts +2 -2
  13. package/templates/sampling/apis/quotes.ts +15 -15
  14. package/templates/sampling/apis/sub/index.ts +2 -2
  15. package/templates/sampling/apis/sub/sub.ts +2 -2
  16. package/templates/sampling/assets/bootstrap-icons.css +5 -0
  17. package/templates/sampling/assets/default.css +94 -91
  18. package/templates/sampling/assets/fonts/bootstrap-icons.woff +0 -0
  19. package/templates/sampling/assets/fonts/bootstrap-icons.woff2 +0 -0
  20. package/templates/sampling/assets/icon.svg +6 -6
  21. package/templates/sampling/assets/manifest.json +56 -56
  22. package/templates/sampling/assets/markdown.css +273 -273
  23. package/templates/sampling/assets/robots.txt +1 -1
  24. package/templates/sampling/assets/system.css +6 -6
  25. package/templates/sampling/builds/about.html +29 -26
  26. package/templates/sampling/builds/bundle.js +34763 -13116
  27. package/templates/sampling/builds/bundle.ts +20 -25
  28. package/templates/sampling/builds/clock.html +29 -28
  29. package/templates/sampling/builds/counter.html +30 -29
  30. package/templates/sampling/builds/forms/form.html +48 -47
  31. package/templates/sampling/builds/forms/index.html +48 -47
  32. package/templates/sampling/builds/hello.html +61 -59
  33. package/templates/sampling/builds/htmlx.html +26 -23
  34. package/templates/sampling/builds/htmlx.tsx +12 -12
  35. package/templates/sampling/builds/index.html +98 -97
  36. package/templates/sampling/builds/login.html +47 -44
  37. package/templates/sampling/builds/profile/index.html +54 -53
  38. package/templates/sampling/builds/quotes.html +26 -25
  39. package/templates/sampling/builds/shared.js +77 -76
  40. package/templates/sampling/builds/system.html +27 -26
  41. package/templates/sampling/components/header.tsx +6 -6
  42. package/templates/sampling/components/hello.tsx +9 -0
  43. package/templates/sampling/components/icon.tsx +11 -0
  44. package/templates/sampling/components/index.ts +3 -0
  45. package/templates/sampling/index.html +20 -19
  46. package/templates/sampling/index.ts +18 -18
  47. package/templates/sampling/routes/about.html +12 -12
  48. package/templates/sampling/routes/clock.tsx +36 -35
  49. package/templates/sampling/routes/forms/form.tsx +50 -50
  50. package/templates/sampling/routes/hello.tsx +58 -61
  51. package/templates/sampling/routes/htmlx.html +14 -14
  52. package/templates/sampling/routes/index.md +15 -15
  53. package/templates/sampling/routes/login.tsx +35 -35
  54. package/templates/sampling/routes/profile/detail.css +12 -12
  55. package/templates/sampling/routes/profile/detail.tsx +47 -47
  56. package/templates/sampling/routes/profile/index.tsx +13 -13
  57. package/templates/sampling/routes/profile/profile.css +8 -8
  58. package/templates/sampling/routes/profile/tester.tsx +10 -10
  59. package/templates/sampling/routes/system.tsx +1 -0
  60. package/templates/sampling/tests/access.spec.ts +29 -29
  61. package/templates/sampling/tests/counter.spec.ts +18 -18
  62. package/templates/sampling/tests/form.spec.ts +50 -50
  63. package/templates/sampling/tests/hello.spec.ts +24 -24
  64. package/templates/sampling/tests/path.test.ts +19 -19
  65. package/vscode/launch.json +8 -8
  66. package/templates/sampling/builds/client.ts +0 -1
  67. /package/templates/sampling/assets/{logo-144.png → logos/logo-144.png} +0 -0
  68. /package/templates/sampling/assets/{logo-168.png → logos/logo-168.png} +0 -0
  69. /package/templates/sampling/assets/{logo-192.png → logos/logo-192.png} +0 -0
  70. /package/templates/sampling/assets/{logo-48.png → logos/logo-48.png} +0 -0
  71. /package/templates/sampling/assets/{logo-512.png → logos/logo-512.png} +0 -0
  72. /package/templates/sampling/assets/{logo-72.png → logos/logo-72.png} +0 -0
  73. /package/templates/sampling/assets/{logo-96.png → logos/logo-96.png} +0 -0
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # reactful scaffold
2
-
3
- Createing a reactful framework project scaffold.
4
-
5
- ```bash
6
- bunx @reactful/create@latest
7
- ```
1
+ # reactful scaffold
2
+
3
+ Createing a reactful framework project scaffold.
4
+
5
+ ```bash
6
+ bunx @reactful/create@latest
7
+ ```
@@ -1,22 +1,22 @@
1
- {
2
- "type": "module",
3
- "name": "template",
4
- "module": "index.ts",
5
- "scripts": {
6
- "start": "bun --hot run index.ts",
7
- "build": "rm -rf tsconfig.tsbuildinfo; bunx tsc -p tsconfig.json",
8
- "clear": "rm -rf node_modules package-lock.json bun.lockb; bun i; bun run build"
9
- },
10
- "dependencies": {
11
- "react": "^18.2.0",
12
- "react-dom": "^18.2.0",
13
- "@reactful/extensions": "latest",
14
- "@reactful/server": "latest",
15
- "@reactful/web": "latest"
16
- },
17
- "devDependencies": {
18
- "bun-types": "^1.0.20",
19
- "typescript": "^5.3.3",
20
- "@types/react": "^18.2.57"
21
- }
1
+ {
2
+ "type": "module",
3
+ "name": "template",
4
+ "module": "index.ts",
5
+ "scripts": {
6
+ "start": "bun --hot run index.ts",
7
+ "build": "rm -rf tsconfig.tsbuildinfo; bunx tsc -p tsconfig.json",
8
+ "clear": "rm -rf node_modules package-lock.json bun.lockb; bun i; bun run build"
9
+ },
10
+ "dependencies": {
11
+ "react": "^18.2.0",
12
+ "react-dom": "^18.2.0",
13
+ "@reactful/extensions": "latest",
14
+ "@reactful/server": "latest",
15
+ "@reactful/web": "latest"
16
+ },
17
+ "devDependencies": {
18
+ "bun-types": "^1.0.20",
19
+ "typescript": "^5.3.3",
20
+ "@types/react": "^18.2.57"
21
+ }
22
22
  }
@@ -1,24 +1,24 @@
1
- {
2
- "exclude": ["node_modules"],
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- "jsx": "react",
6
- "target": "esnext",
7
- "module": "esnext",
8
- "types": ["bun-types"],
9
- "moduleDetection": "auto",
10
- "moduleResolution": "bundler",
11
- "noEmit": true,
12
- "strict": false,
13
- "allowJs": true,
14
- "sourceMap": true,
15
- "composite": true,
16
- "declaration": true,
17
- "skipLibCheck": true,
18
- "noImplicitAny": false,
19
- "esModuleInterop": true,
20
- "downlevelIteration": true,
21
- "allowSyntheticDefaultImports": true,
22
- "forceConsistentCasingInFileNames": true
23
- }
24
- }
1
+ {
2
+ "exclude": ["node_modules"],
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "jsx": "react",
6
+ "target": "esnext",
7
+ "module": "esnext",
8
+ "types": ["bun-types"],
9
+ "moduleDetection": "auto",
10
+ "moduleResolution": "bundler",
11
+ "noEmit": true,
12
+ "strict": false,
13
+ "allowJs": true,
14
+ "sourceMap": true,
15
+ "composite": true,
16
+ "declaration": true,
17
+ "skipLibCheck": true,
18
+ "noImplicitAny": false,
19
+ "esModuleInterop": true,
20
+ "downlevelIteration": true,
21
+ "allowSyntheticDefaultImports": true,
22
+ "forceConsistentCasingInFileNames": true
23
+ }
24
+ }
package/index.js CHANGED
@@ -1,149 +1,149 @@
1
- #!/usr/bin/env node
2
-
3
- import npmRegistryFetch from 'npm-registry-fetch'
4
- import { spawn , execSync } from 'child_process'
5
- import inquirer from 'inquirer'
6
- import path from 'path'
7
- import * as tar from 'tar'
8
- import fs from 'fs'
9
-
10
- const CIANO = '\x1b[36m'
11
- const GREEN = '\x1b[32m'
12
- const RESET = '\x1b[0m'
13
- const prefix = `${GREEN}+${RESET}`
14
- const char = '─'
15
- const line = char.repeat(51)
16
- const decor = '-'.repeat(18)
17
-
18
- const packageJson = fs.readFileSync('package.json', 'utf-8');
19
- const { version } = JSON.parse(packageJson);
20
-
21
-
22
- console.log('___________________________________________________')
23
- console.log('')
24
- console.log(` ${GREEN}REACTful${RESET} create `)
25
- console.log(` ${CIANO}current version ${version}${RESET} `)
26
- //console.log(`${decor}( ${GREEN}reactful${RESET}.js )${decor}`)
27
- console.log('___________________________________________________')
28
- // console.log(line)
29
- console.log('')
30
-
31
- const templates = ['empty', 'minimal', 'sampling']
32
- const questions = [{
33
- type: 'list',
34
- name: 'template',
35
- message: 'Which template?',
36
- choices: templates,
37
- prefix
38
- },
39
- { type: 'input', name: 'project', message: 'Project name?', prefix, default: 'Sample' },
40
- { type: 'confirm', name: 'vscode', message: 'VS Code IDE?', prefix },
41
- { type: 'confirm', name: 'install', message: 'Install?', prefix },
42
- ]
43
-
44
- inquirer.prompt(questions).then(prompting)
45
-
46
- async function prompting(answers) {
47
- console.log('- preparing...')
48
-
49
- if (!answers.project) throw 'Required project name!'
50
-
51
- const destination = path.join(process.cwd(), answers.project)
52
- const downloadPath = path.join(destination, 'temp')
53
-
54
- await createDirectory(destination)
55
-
56
- console.log('- loading NPM...')
57
- await download('@reactful/create', downloadPath)
58
-
59
- console.log('- creating env...')
60
- const env = `PORT=333\nMINIFY=FALSE`
61
- fs.writeFileSync(`${destination}/.env`, env)
62
-
63
- console.log('- copying template...')
64
- await copyPath(`${downloadPath}/commons`, destination)
65
- await copyPath(`${downloadPath}/templates/${answers.template}`, destination)
66
-
67
- console.log('- renaming project...')
68
- renamingJSON(destination, answers.project)
69
-
70
- console.log('- installing dependencies...\n')
71
- process.chdir(answers.project)
72
- execSync(`bun install`)
73
-
74
- if (answers.vscode) {
75
- spawn("code", ['.'])
76
-
77
- const pathVSCode = `${destination}/.vscode`
78
- await createDirectory(pathVSCode)
79
- await copyPath(`${downloadPath}/vscode`, pathVSCode)
80
- }
81
-
82
- await removeDirectory(downloadPath)
83
- }
84
-
85
- function renamingJSON(directory, projectName) {
86
- const url = `${directory}/package.json`
87
- const txt = fs.readFileSync(url, { encoding: 'utf-8' })
88
- const obj = JSON.parse(txt)
89
-
90
- obj.name = projectName
91
-
92
- fs.writeFileSync(url, JSON.stringify(obj, null, 3))
93
- }
94
-
95
- async function download(packageName, directory) {
96
- try {
97
- await createDirectory(directory)
98
-
99
- const metadata = await npmRegistryFetch.json(packageName)
100
- const latestVersion = metadata['dist-tags'].latest
101
- const tarballURL = metadata.versions[latestVersion].dist.tarball
102
- const filename = tarballURL.substring(tarballURL.lastIndexOf('/') + 1)
103
- const tempFilePath = path.join(directory, filename)
104
-
105
- if (!fs.existsSync(directory))
106
- fs.mkdirSync(directory, { recursive: true })
107
-
108
- const response = await npmRegistryFetch(tarballURL)
109
-
110
- await new Promise((resolve, reject) => {
111
- const fileStream = fs.createWriteStream(tempFilePath)
112
- response.body.pipe(fileStream)
113
- response.body.on('error', reject)
114
- fileStream.on('finish', resolve)
115
- })
116
-
117
- await tar.x({ file: tempFilePath, cwd: directory, strip: 1 })
118
-
119
- fs.unlinkSync(tempFilePath)
120
- } catch (error) {
121
- console.error('downloadPackage')
122
- throw error
123
- }
124
- }
125
-
126
-
127
- function createDirectory(directory) {
128
- removeDirectory(directory)
129
- fs.mkdirSync(directory)
130
- }
131
-
132
- function removeDirectory(directory) {
133
- if (!fs.existsSync(directory)) return
134
- else fs.rmSync(directory, { recursive: true })
135
- }
136
-
137
- function copyPath(source, target) {
138
- if (!fs.existsSync(target)) fs.mkdirSync(target)
139
-
140
- fs.readdirSync(source).forEach(function(file) {
141
- const sourcePath = path.join(source, file)
142
- const targetPath = path.join(target, file)
143
- const statusPath = fs.lstatSync(sourcePath)
144
- const folderPath = statusPath.isDirectory()
145
-
146
- if (folderPath) copyPath(sourcePath, targetPath)
147
- else fs.copyFileSync(sourcePath, targetPath)
148
- })
1
+ #!/usr/bin/env node
2
+
3
+ import npmRegistryFetch from 'npm-registry-fetch'
4
+ import { spawn , execSync } from 'child_process'
5
+ import inquirer from 'inquirer'
6
+ import path from 'path'
7
+ import * as tar from 'tar'
8
+ import fs from 'fs'
9
+
10
+ const CIANO = '\x1b[36m'
11
+ const GREEN = '\x1b[32m'
12
+ const RESET = '\x1b[0m'
13
+ const prefix = `${GREEN}+${RESET}`
14
+ const char = '─'
15
+ const line = char.repeat(51)
16
+ const decor = '-'.repeat(18)
17
+
18
+ const packageJson = fs.readFileSync('package.json', 'utf-8');
19
+ const { version } = JSON.parse(packageJson);
20
+
21
+
22
+ console.log('___________________________________________________')
23
+ console.log('')
24
+ console.log(` ${GREEN}REACTful${RESET} create `)
25
+ console.log(` ${CIANO}current version ${version}${RESET} `)
26
+ //console.log(`${decor}( ${GREEN}reactful${RESET}.js )${decor}`)
27
+ console.log('___________________________________________________')
28
+ // console.log(line)
29
+ console.log('')
30
+
31
+ const templates = ['empty', 'minimal', 'sampling']
32
+ const questions = [{
33
+ type: 'list',
34
+ name: 'template',
35
+ message: 'Which template?',
36
+ choices: templates,
37
+ prefix
38
+ },
39
+ { type: 'input', name: 'project', message: 'Project name?', prefix, default: 'Sample' },
40
+ { type: 'confirm', name: 'vscode', message: 'VS Code IDE?', prefix },
41
+ { type: 'confirm', name: 'install', message: 'Install?', prefix },
42
+ ]
43
+
44
+ inquirer.prompt(questions).then(prompting)
45
+
46
+ async function prompting(answers) {
47
+ console.log('- preparing...')
48
+
49
+ if (!answers.project) throw 'Required project name!'
50
+
51
+ const destination = path.join(process.cwd(), answers.project)
52
+ const downloadPath = path.join(destination, 'temp')
53
+
54
+ await createDirectory(destination)
55
+
56
+ console.log('- loading NPM...')
57
+ await download('@reactful/create', downloadPath)
58
+
59
+ console.log('- creating env...')
60
+ const env = `PORT=333\nMINIFY=FALSE`
61
+ fs.writeFileSync(`${destination}/.env`, env)
62
+
63
+ console.log('- copying template...')
64
+ await copyPath(`${downloadPath}/commons`, destination)
65
+ await copyPath(`${downloadPath}/templates/${answers.template}`, destination)
66
+
67
+ console.log('- renaming project...')
68
+ renamingJSON(destination, answers.project)
69
+
70
+ console.log('- installing dependencies...\n')
71
+ process.chdir(answers.project)
72
+ execSync(`bun install`)
73
+
74
+ if (answers.vscode) {
75
+ spawn("code", ['.'])
76
+
77
+ const pathVSCode = `${destination}/.vscode`
78
+ await createDirectory(pathVSCode)
79
+ await copyPath(`${downloadPath}/vscode`, pathVSCode)
80
+ }
81
+
82
+ await removeDirectory(downloadPath)
83
+ }
84
+
85
+ function renamingJSON(directory, projectName) {
86
+ const url = `${directory}/package.json`
87
+ const txt = fs.readFileSync(url, { encoding: 'utf-8' })
88
+ const obj = JSON.parse(txt)
89
+
90
+ obj.name = projectName
91
+
92
+ fs.writeFileSync(url, JSON.stringify(obj, null, 3))
93
+ }
94
+
95
+ async function download(packageName, directory) {
96
+ try {
97
+ await createDirectory(directory)
98
+
99
+ const metadata = await npmRegistryFetch.json(packageName)
100
+ const latestVersion = metadata['dist-tags'].latest
101
+ const tarballURL = metadata.versions[latestVersion].dist.tarball
102
+ const filename = tarballURL.substring(tarballURL.lastIndexOf('/') + 1)
103
+ const tempFilePath = path.join(directory, filename)
104
+
105
+ if (!fs.existsSync(directory))
106
+ fs.mkdirSync(directory, { recursive: true })
107
+
108
+ const response = await npmRegistryFetch(tarballURL)
109
+
110
+ await new Promise((resolve, reject) => {
111
+ const fileStream = fs.createWriteStream(tempFilePath)
112
+ response.body.pipe(fileStream)
113
+ response.body.on('error', reject)
114
+ fileStream.on('finish', resolve)
115
+ })
116
+
117
+ await tar.x({ file: tempFilePath, cwd: directory, strip: 1 })
118
+
119
+ fs.unlinkSync(tempFilePath)
120
+ } catch (error) {
121
+ console.error('downloadPackage')
122
+ throw error
123
+ }
124
+ }
125
+
126
+
127
+ function createDirectory(directory) {
128
+ removeDirectory(directory)
129
+ fs.mkdirSync(directory)
130
+ }
131
+
132
+ function removeDirectory(directory) {
133
+ if (!fs.existsSync(directory)) return
134
+ else fs.rmSync(directory, { recursive: true })
135
+ }
136
+
137
+ function copyPath(source, target) {
138
+ if (!fs.existsSync(target)) fs.mkdirSync(target)
139
+
140
+ fs.readdirSync(source).forEach(function(file) {
141
+ const sourcePath = path.join(source, file)
142
+ const targetPath = path.join(target, file)
143
+ const statusPath = fs.lstatSync(sourcePath)
144
+ const folderPath = statusPath.isDirectory()
145
+
146
+ if (folderPath) copyPath(sourcePath, targetPath)
147
+ else fs.copyFileSync(sourcePath, targetPath)
148
+ })
149
149
  }
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "@reactful/create",
3
- "version": "1.2.1",
4
- "main": "index.js",
5
- "type": "module",
6
- "description": "reactful scafold tool",
7
- "author": "jonathan de sena ribeiro <jsenaribeiro@gmail.com>",
8
- "bin": {
9
- "@reactful/create": "index.js"
10
- },
11
- "files": [
12
- "index.js",
13
- "package.json",
14
- "templates",
15
- "commons",
16
- "vscode"
17
- ],
18
- "scripts": {
19
- "start": "bun run index.js",
20
- "patch": "npm version patch; npm publish --access public",
21
- "minor": "npm version minor; npm publish --access public",
22
- "major": "npm version major; npm publish --access public"
23
- },
24
- "license": "MIT",
25
- "dependencies": {
26
- "bun-types": "latest",
27
- "inquirer": "^9.2.13",
28
- "npm-registry-fetch": "^16.1.0",
29
- "tar": "^6.2.0"
30
- }
31
- }
1
+ {
2
+ "name": "@reactful/create",
3
+ "version": "1.2.3",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "description": "reactful scaffold",
7
+ "author": "jonathan de sena ribeiro <jsenaribeiro@gmail.com>",
8
+ "bin": {
9
+ "@reactful/create": "index.js"
10
+ },
11
+ "files": [
12
+ "index.js",
13
+ "package.json",
14
+ "templates",
15
+ "commons",
16
+ "vscode"
17
+ ],
18
+ "scripts": {
19
+ "start": "bun run index.js",
20
+ "patch": "npm version patch; npm publish --access public",
21
+ "minor": "npm version minor; npm publish --access public",
22
+ "major": "npm version major; npm publish --access public"
23
+ },
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "bun-types": "latest",
27
+ "inquirer": "^9.2.13",
28
+ "npm-registry-fetch": "^16.1.0",
29
+ "tar": "^6.2.0"
30
+ }
31
+ }
@@ -1,9 +1,9 @@
1
- import React from "react"
2
-
3
- interface Props {
4
- name?: string
5
- }
6
-
7
- export const Hello = (props: Props) => <>
8
- <h1>Hello { props.name || "World"} !</h1>
1
+ import React from "react"
2
+
3
+ interface Props {
4
+ name?: string
5
+ }
6
+
7
+ export const Hello = (props: Props) => <>
8
+ <h1>Hello { props.name || "World"} !</h1>
9
9
  </>
@@ -0,0 +1,11 @@
1
+ import React from 'react'
2
+
3
+ interface Props {
4
+ id: string
5
+ size?: string
6
+ children?: string
7
+ }
8
+
9
+ export const Icon = ({ id, size, children }: Props) => <>
10
+ <i className={`bi bi-${size} bi-${id}`} title={children || ""}></i>
11
+ </>
@@ -1 +1,2 @@
1
- export * from './hello'
1
+ export * from './hello'
2
+ export * from './icon'
@@ -1,7 +1,8 @@
1
- import React from "react"
2
- import { Hello } from './components'
3
-
4
- export default () => <>
5
- <h2>Minimal Template</h2>
6
- <Hello name="World" />
1
+ import React from "react"
2
+ import { Hello, Icon } from './components'
3
+
4
+ export default () => <>
5
+ <h2>Minimal Template</h2>
6
+ <Hello name="World" />
7
+ <Icon id='plus-circle' />
7
8
  </>
@@ -1,15 +1,15 @@
1
- const database = [
2
- { username: 'usr', password: 'pwd' },
3
- { username: 'test', password: '123' },
4
- ]
5
-
6
- export const db = {
7
-
8
- has(username, password) {
9
- const contains = database
10
- .filter(x => x.username == username)
11
- .some(x => x.password == password)
12
-
13
- return Promise.resolve(contains)
14
- }
1
+ const database = [
2
+ { username: 'usr', password: 'pwd' },
3
+ { username: 'test', password: '123' },
4
+ ]
5
+
6
+ export const db = {
7
+
8
+ has(username, password) {
9
+ const contains = database
10
+ .filter(x => x.username == username)
11
+ .some(x => x.password == password)
12
+
13
+ return Promise.resolve(contains)
14
+ }
15
15
  }
@@ -1,28 +1,28 @@
1
- "user server"
2
-
3
- import { delay } from '../../../commons/src'
4
- import { db } from "./db"
5
-
6
- const SECRET_KEY = '0123456789'
7
-
8
- export async function post(request: Request) {
9
- await delay(3000)
10
-
11
- const AUTHORIZATION = request.headers.get('authorization')
12
- const UNAUTHORIZED = { status: 401, headers: { 'Content-Type': 'text/plain' }}
13
- const NO_HEADERS = 'Authorization header missing!'
14
- const NOT_LOGIN = 'Authentication failed!'
15
-
16
- if (!AUTHORIZATION?.startsWith('Basic '))
17
- return new Response(NO_HEADERS, UNAUTHORIZED)
18
-
19
- const auth = AUTHORIZATION.split(' ')[1]
20
- const credential = Buffer.from(auth, 'base64').toString('utf-8')
21
- const [ username, password ] = credential.split(':')
22
- const exists = await db.has(username, password)
23
- const settings = exists ? { } : UNAUTHORIZED
24
- const access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
25
- const text = exists ? JSON.stringify({ access_token }) : NOT_LOGIN
26
-
27
- return new Response(text, settings)
1
+ "user server"
2
+
3
+ import { delay } from '../../../commons/src'
4
+ import { db } from "./db"
5
+
6
+ const SECRET_KEY = '0123456789'
7
+
8
+ export async function post(request: Request) {
9
+ await delay(3000)
10
+
11
+ const AUTHORIZATION = request.headers.get('authorization')
12
+ const UNAUTHORIZED = { status: 401, headers: { 'Content-Type': 'text/plain' }}
13
+ const NO_HEADERS = 'Authorization header missing!'
14
+ const NOT_LOGIN = 'Authentication failed!'
15
+
16
+ if (!AUTHORIZATION?.startsWith('Basic '))
17
+ return new Response(NO_HEADERS, UNAUTHORIZED)
18
+
19
+ const auth = AUTHORIZATION.split(' ')[1]
20
+ const credential = Buffer.from(auth, 'base64').toString('utf-8')
21
+ const [ username, password ] = credential.split(':')
22
+ const exists = await db.has(username, password)
23
+ const settings = exists ? { } : UNAUTHORIZED
24
+ const access_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
25
+ const text = exists ? JSON.stringify({ access_token }) : NOT_LOGIN
26
+
27
+ return new Response(text, settings)
28
28
  }
@@ -1,3 +1,3 @@
1
- export function get(request: Request) {
2
- return new Response("hello world")
1
+ export function get(request: Request) {
2
+ return new Response("hello world")
3
3
  }
@@ -1,16 +1,16 @@
1
- export function get(request: Request) {
2
- function getRandomInt(max) { return Math.floor(Math.random() * max); }
3
-
4
- const messages = [
5
- "Man is the measure of all things (Protagoras)",
6
- "The unexamined life is not worth living (Socrates)",
7
- "One cannot step twice in the same river (Heraclitus)",
8
- "Life must be understood backward. But it must be lived forward (Kierkegaard)",
9
- "Science is what you know. Philosophy is what you don't know (Russell)",
10
- "I can control my passions and emotions if I can understand their nature (Spinoza)"
11
- ]
12
-
13
- const message = messages[getRandomInt(messages.length)]
14
-
15
- return new Response(message)
1
+ export function get(request: Request) {
2
+ function getRandomInt(max) { return Math.floor(Math.random() * max); }
3
+
4
+ const messages = [
5
+ "Man is the measure of all things (Protagoras)",
6
+ "The unexamined life is not worth living (Socrates)",
7
+ "One cannot step twice in the same river (Heraclitus)",
8
+ "Life must be understood backward. But it must be lived forward (Kierkegaard)",
9
+ "Science is what you know. Philosophy is what you don't know (Russell)",
10
+ "I can control my passions and emotions if I can understand their nature (Spinoza)"
11
+ ]
12
+
13
+ const message = messages[getRandomInt(messages.length)]
14
+
15
+ return new Response(message)
16
16
  }
@@ -1,3 +1,3 @@
1
- export function get(request: Request) {
2
- return new Response("hi sub index")
1
+ export function get(request: Request) {
2
+ return new Response("hi sub index")
3
3
  }