-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
25 lines (23 loc) · 799 Bytes
/
init.js
File metadata and controls
25 lines (23 loc) · 799 Bytes
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
'use strict'
const urllib = require('urllib')
const path = require('path')
const fs = require('fs/promises')
const config = require('./config').graphi
;(async () => {
const url = `${config.host}/api/route/${config.appId}/version/${config.version}`
console.log('Fetch routes from ' + url)
try {
const res = await urllib.request(url, { headers: { Authorization: config.token }, dataType: 'json' })
if (res.status === 200) {
const { data } = res
if (data.code === 200) {
await fs.writeFile(path.join(__dirname, 'graphi.json'), JSON.stringify(data.data, null, 2))
console.log('Successed save file graphi.json')
}
} else {
console.error('Fetch failed:', res.message)
}
} catch (e) {
console.error('Fetch failed:', e.message)
}
})()