我很困惑--相当简单的应用(我是Node新手)。
App.js
import * as RNFS from 'react-native-fs';
var config_full;
// readFile(filepath: string, encoding?: string)
RNFS.readFile('./config.toml', 'utf-8').then(res => {
config_full = toml.parse(res);
})
.catch(err => {
console.log(err.message, err.code);
});
Package.json
{
"name": "samples-dashboard",
"version": "0.1.0",
"private": false,
"type": "module",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"fs": "0.0.1-security",
"gremlin": "^3.4.6",
"match-sorter": "^4.1.0",
"namor": "^2.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-native-fs": "^2.16.6",
"react-scripts": "3.4.1",
"react-table": "^7.1.0",
"styled-components": "^5.1.1",
"toml": "^3.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"gh-pages": "^2.2.0"
}
}
而且我得到一个错误。
Failed to compile
./node_modules/react-native-fs/FS.common.js
SyntaxError: /node_modules/react-native-fs/FS.common.js: Unexpected token, expected ";" (32:5)
30 | var normalizeFilePath = (path) => (path.startsWith('file://') ? path.slice(7) : path);
31 |
> 32 | type MkdirOptions = {
| ^
33 | NSURLIsExcludedFromBackupKey?: boolean; // iOS only
34 | NSFileProtectionKey?: string; // IOS only
35 | };
我完全不在乎我用什么从.toml文件中加载--只需要从磁盘上加载一些东西。我应该用什么?
要说明的是,我不需要把这个文件传递给浏览器,我想让服务器加载这个文件,并把.toml的值提供给变量。
我检查了下面的方法,但似乎都没有用。
我最大的希望是核心医生-- https:/github.comalexbeletskytoml-js。 - 但所有的文件系统包似乎都不能在那里工作。
我现在意识到我想错了。整个应用程序--包括config--被下载到客户端并运行,这将包括.toml中的敏感材料。
我需要想出另一种方法来与数据库进行认证。这个问题没有意义。