小编ann*_*123的帖子

Firebase 函数环境变量

所以我正在将我的应用程序从 node express 迁移到 firebase-functions!

在我的 node-express 应用程序中,我有 .env 文件,其中包含所有数据,对于初学者,让我们将其视为我的 .env 文件

GOOGLE_CLIENT_ID = 4046108-bssbfjohpj94l0dhpu69vpgs1ne0.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET = lTQHpj3yY57oQpO
Run Code Online (Sandbox Code Playgroud)

然后在我的护照策略中,我有这样的事情

passport.use(new GoogleStrategy({
    clientID: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    callbackURL:  "/auth/google/callback",
    userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo',
    accessType: 'offline',
    passReqToCallback: true
  },
Run Code Online (Sandbox Code Playgroud)

现在,

问题:1 - Firebase 函数可能不支持 .env 文件,所以我们可以设置 env 变量而不使用 set 标志手动添加它吗?假设我的环境中有很多变量

问题 - 2:我可以通过执行这样的操作来访问我设置的变量吗

firebase functions:config:set slack.url=https://hooks.slack.com/services/XXX
Run Code Online (Sandbox Code Playgroud)

使用

 process.env.slack.url
Run Code Online (Sandbox Code Playgroud)

或者我们必须做(必要的)

functions.config().slack.url
Run Code Online (Sandbox Code Playgroud)

问题:3Firebase Docs 中,它是这样写的

在函数运行时和本地模拟函数中会自动填充环境变量,包括:

process.env.GCLOUD_PROJECT:提供 Firebase 项目 ID

process.env.FIREBASE_CONFIG:提供以下 Firebase 项目配置信息:

他们的意思是什么?如果第二个问题的答案是错误的,那么他们如何使用 process.env.FIREBASE_CONFIG:

node.js firebase google-cloud-functions

7
推荐指数
1
解决办法
3553
查看次数

自定义日期组件的重构代码

我创建了一个日期组件(底部是工作GIF)。

代码的工作没有问题,但是我编写的代码看起来很杂乱,任何其他人都很难理解。

注意:请查看下面的GIF。另外,忽略样式

这就是我在做什么。对于屏幕中的日期组件,我正在创建引用和状态,如下所示

class OnBoarding extends PureComponent {
    constructor(props) {
        super(props)
        this.d1 = React.createRef()
        this.d2 = React.createRef()
        this.d3 = React.createRef()
        this.d4 = React.createRef()
        this.d5 = React.createRef()
        this.d6 = React.createRef()
        this.d7 = React.createRef()
        this.d8 = React.createRef()
    }
    state = {
        name: '',
        emailAddress: '',
        dob: '',
        male: null,
        female: null,
        keyboard: false,
        d1: null,
        d2: null,
        d3: null,
        d4: null,
        d5: null,
        d6: null,
        d7: null,
        d8: null
    }

dobHandler(number, flag) {
        const completeFlag = `d${flag}`
        this.setState({[completeFlag]: number})
        flag = …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

7
推荐指数
2
解决办法
325
查看次数

Redux reducer中的传播算子

我试图了解在Redux状态下散布运算符会做什么?

我经历了这个问题,在React-Redux Reducers中使用Spread语法的目的,但是由于某些原因,我不相信Answer。

有人可以用简单的方式向我解释为什么我们要这样做吗

  case WHATEVER:
      return {
        ...state,
        DateSucess: action.payload,
Run Code Online (Sandbox Code Playgroud)

不只是

 case WHATEVER
  return {
   DataSucess: action.payload
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux

6
推荐指数
1
解决办法
2045
查看次数

了解 Axios 创建的功能

我被要求进行 API 调用以发送数据。

在 vue 中点击,我触发了这个事件

async facebookDataToSend () {
  let campaignID = await this.$store.getters['CurrentInstance/id']
  this.$axios.post(process.env.API_BASE_URL + 'faceeBookCampaign', { campaignID: campaignID }, { withCredentials: true })
},
Run Code Online (Sandbox Code Playgroud)

但是后来,我被告知使用一些 xyz.js 文件中已经存在的 API 函数。

我的 xyz.js 文件看起来像这样..

const rest = {
  something: axios.create({
    baseURL: process.env.API_BASE_URL,
    withCredentials: true
  }),
  setClient: function (client) {
    this.something = axios.create({
      baseURL: process.env.API_BASE_URL,
      withCredentials: true,
      params: {
        __somethingClient: client
      }
    })
    this.client = client
  }
}
Run Code Online (Sandbox Code Playgroud)

在这里,我无法理解如何使用此实例进行 api 调用所以我查看了他们已经进行了 api 调用的代码并看到了这样的内容

const API = {
  url: '/whateverHtml/',
        method: …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js quasar axios

6
推荐指数
1
解决办法
9292
查看次数

从右侧定位

我正在基于本机的React上构建一个应用程序,我想在其中定位正确的位置

   <View style={searchDrop}> 
             <TextInput
              style={textInput}
              placeholder="Search Coin"
              onChangeText={(text) => this.onSearch(text)} />
              <TouchableOpacity onPress={() => this.props.navigation.navigate("CurrencySelection")}>
                      <Text style={money}> <Icons name="money" size={35} color="#fbc02d" /> </Text>
              </TouchableOpacity>
            </View>
Run Code Online (Sandbox Code Playgroud)

具有以下样式

textInput: { 
    width: "70%",
    height: 35,
    marginLeft: 5,
    marginRight: 5,
    borderWidth: 0,
    backgroundColor: "white",
    borderRadius: 15,
    textAlign: 'center'
  }, 

searchDrop: {
    paddingTop: 32,
    paddingBottom: 5,
    display: "flex",
    flexDirection: "row",
    height: 80,
    backgroundColor: "#3b5998",
    width: 100%
  }, 
  money: {
    position: "absolute",
    right: 0
  }
Run Code Online (Sandbox Code Playgroud)

有了那个,我期待着

<Text style={money}> <Icons name="money" size={35} color="#fbc02d" /> </Text>
Run Code Online (Sandbox Code Playgroud)

位于屏幕的绝对右侧

这是现在的样子

在此处输入图片说明

javascript css react-native

5
推荐指数
1
解决办法
60
查看次数

类似于Array函数的JavaScript语法:[variable]({key},arg){}

我被要求研究雇主的守则,在守则中,雇主做了这样的事情:

export const actions = {
  [ACTIONS.ITEM_LIST.LOAD.name] ({commit}, payload) {
    const type = payload
Run Code Online (Sandbox Code Playgroud)

现在,在此,我无法纠正这一行代码

 [ACTIONS.ITEM_LIST.LOAD.name] ({commit}, payload) {
Run Code Online (Sandbox Code Playgroud)

像是功能还是什么?有人可以向我解释以上语法吗?

javascript ecmascript-6

5
推荐指数
1
解决办法
89
查看次数

向Twitter API发出Oauth2请求

更新的问题:我想使用oauth2请求在NodeJs中对用户进行身份验证,但是我找不到任何文章可以在网上进行。

通常是Twitter,大多数网络上的人都使用oauth 1进行身份验证,因为我不想拥有快速的会话中间件,而且我很好奇要了解当用户没有护照策略时如何使用oauth对用户进行身份验证等。

Can someone please help me in figuring out how we can authenticate user in twitter using their docs (with code and possibly axios)?

link for their docs

javascript twitter node.js oauth-2.0 axios

5
推荐指数
0
解决办法
143
查看次数

.measure 不是函数

我想从屏幕顶部确定元素的位置。从其他问题来看,一种方法是使用 react native 的 .measure 属性?

参考问题:React Native:获取元素的位置

所以我做了这样的事情

const AutoComplete = (props) => {
  let parentViewRef =  useRef(null);
  return (
       <View 
        style={styles.modelOpenViewMain}>
        <View  ref={parentViewRef} 
        onLayout={({nativeEvent}) => {
          console.log(nativeEvent)
          if (parentViewRef) {
            parentViewRef.measure((x, y, width, height, pageX, pageY) => {
                      console.log(x, y, width, height, pageX, pageY);
             })
            }}}/>
        <View style={styles.modelOpenInputView}>
          <TextInput
              value={value.label}
              onChangeText={(text) => onchangeHandler(text)}
              style={[{color: defaultColor, borderColor: defaultColor}, styles.defaultTextInputStyle, textInputStyle]}
            />
          </View>
      </View>
)
}
Run Code Online (Sandbox Code Playgroud)

我的 parentViewRef 的控制台给了我这个 console.log(parentViewRef)

_nativeTag: 73
_children: []
viewConfig:
uiViewClassName: "RCTView"
Commands: {} …
Run Code Online (Sandbox Code Playgroud)

react-native

5
推荐指数
1
解决办法
1390
查看次数

如何从终端运行esnext文件

我有点新打字稿,我写了一个 SDK,我的 .tsconfig 看起来有点像这样

{
  "compilerOptions": {
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "module": "esnext",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2015",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "noImplicitAny": false,
    "outDir": "./lib",
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
  "exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)

我使用tsc命令构建它。现在我创建了 localtest.js 文件,我在其中导入了这个文件

import getWorkspace from './lib/index'

const randomFunc = async () => {
   // some code 
}
randomFunc()
Run Code Online (Sandbox Code Playgroud)

然后在我的终端中使用以下命令运行它node localtest.js会引发以下错误

function (exports, require, module, __filename, __dirname) { import getWorkspace from './lib/index'
                                                                     ^^^^^^^^^^^^

SyntaxError: Unexpected …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript

5
推荐指数
1
解决办法
202
查看次数

如何在javascript客户端将图像解析为ICO格式

我想在前端使用 javascript 将图像(png/jpeg)转换为 ICO。

在网上搜索时,我在 github 上发现了这段代码:https : //gist.github.com/twolfson/7656254但不幸的是它使用fs //gist.github.com/twolfson/7656254了 nodejs 模块(+ 代码很难理解)。

有人可以告诉我应该搜索什么/或使用前端javascript将png/jpeg转换为ico的方法吗?

我尝试过的替代方法?

使用了这个 repo:https : //github.com/fiahfy/ico-convert但他们使用了sharp,并且客户端不支持sharp

javascript

5
推荐指数
1
解决办法
761
查看次数