我正在尝试构建一个使用 Typescript 的 Next.js/React 应用程序的 docker 镜像。
安装了 Typescript,我可以在没有 docker 的情况下在本地运行构建。
但是,随着 docker 镜像的构建,我得到了以下几点:
Step 8/10 : RUN npm run build
---> Running in ee577c719739
> project@0.0.5 build /app
> next build
Creating an optimized production build...
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL: …Run Code Online (Sandbox Code Playgroud) 我在 Kubernetes(谷歌云)上部署了一个应用程序。要使部署发挥作用,它需要向“/healthz”和“/”返回 200 状态响应。我在我的 Express 服务器上设置了这个作为返回响应的路由,如下所示:
app.use('/healthz', ((_req, res) => {
logGeneral.info("Health Status check called.");
res.sendStatus(200);
}));
Run Code Online (Sandbox Code Playgroud)
但我不知道如何为在 Next.js/React 上运行的前端做同样的事情。不支持 res.send 等命令。
有人知道吗?
谢谢。
我正在为 React 实现状态管理。我正在使用 Next.js 和 Typescript。
我使用了下一个 redux 包装器,并按照指南的指示在 /pages/_app.js 上有以下内容。
import React from "react";
import {createStore} from "redux";
import {Provider} from "react-redux";
import App, {Container} from "next/app";
import withRedux from "next-redux-wrapper";
import configureStore from '../state/store';
class MyApp extends App {
static async getInitialProps ({Component, ctx}) {
return {
pageProps: (Component.getInitialProps ? await Component.getInitialProps(ctx) : {})
}
}
render() {
const {Component, pageProps, store} = this.props;
return (
<Container>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</Container>
);
}
}
export …Run Code Online (Sandbox Code Playgroud) 在我的 next.config.js 中,我有一个看起来像这样的部分:
module.exports = {
serverRuntimeConfig: { // Will only be available on the server side
mySecret: 'secret'
},
publicRuntimeConfig: { // Will be available on both server and client
PORT: process.env.PORT,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
BACKEND_URL: process.env.BACKEND_URL
}
Run Code Online (Sandbox Code Playgroud)
我有一个 .env 文件,当在本地运行时,Next.js 应用程序成功地从 .env 文件中获取环境变量。
例如,我指的是这样的 env 变量:
axios.get(publicRuntimeConfig.BACKOFFICE_BACKEND_URL)
Run Code Online (Sandbox Code Playgroud)
但是,当我将此应用程序部署到我的 Kubernetes 集群时,不会收集部署文件中设置的环境变量。所以他们返回为未定义。
我读到 .env 文件由于前端(基于浏览器)和后端(基于节点)之间的差异而无法读取,但必须有某种方法才能使这项工作正常进行。
有谁知道如何在前端(基于浏览器)应用程序上使用保存在 pods/containers 部署文件中的环境变量?
谢谢。
编辑 1:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "38"
creationTimestamp: xx
generation: 40
labels:
app: appname
name: appname
namespace: development
resourceVersion: …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成一个 GraphQL 模式。
我有以下解析器。他们三个在不同的文件中。其中 2 个用于收集数据,而其中一个只是一个触发器 API,用于让它们从数据源收集更多数据。
@Resolver()
export class RefreshDataSchema{
constructor(
private readonly aggregatedDataService : AggregateDataService
){}
@Mutation(() => Boolean)
async refreshTransactions() : Promise<Boolean>{
Logger.info("Refresh transactions mutation received.");
return await this.aggregatedDataService.fetchAndAggregateTransactions();
}
@Mutation(() => Boolean)
async refreshAccounts() : Promise<Boolean>{
Logger.info("Refresh accounts mutation received.");
return await this.aggregatedDataService.fetchAndAggregateAccounts();
}
}
@Resolver(() => Account)
export class AccountSchema extends Account{
@Query(() => Account)
async getAccount(
@Arg('query', () => AccountQuery)
query: AccountQuery,
) {
const data = await Account.findOne({ where: query });
if (data …Run Code Online (Sandbox Code Playgroud) 代码:
\n\nlet currency = 400023;\r\nconsole.log(new Intl.NumberFormat(\'de-DE\', {\r\n style: \'currency\',\r\n currency: \'EUR\'\r\n}).format(currency));Run Code Online (Sandbox Code Playgroud)\r\n预期: \n\xe2\x82\xac400.023,00
\n\n实际: \n\xe2\x82\xac400,023.00
\n\n在我在 JS 文档中找到的示例中,它显示点被用作千位分隔符,逗号被用作分,但当我自己使用它时,它不起作用。
\n日历小部件首先可以工作,但是如果您刷新页面,它就会停止工作,但只有在网站上线时才会停止工作。在本地开发中,不会出现这样的问题。
还注意到,当我通过导航路由到该页面时,它可以工作。但如果我直接输入特定页面的链接,则不起作用。
这是代码:
<template>
<client-only>
<vue-calendly url="link" :height="650"></vue-calendly>
</client-only>
</template>
<script>
import Vue from 'vue';
export default {
created() {
if (process.isClient) {
const VueCalendly = require('vue-calendly').default;
Vue.use(VueCalendly);
}
}
};
</script>
Run Code Online (Sandbox Code Playgroud)
Vue 应用程序在 Gridsome 上运行,因此它是 SSR。我将小部件设置为仅在客户端显示。不确定是什么问题。
next.js ×4
reactjs ×4
kubernetes ×2
typescript ×2
calendly ×1
docker ×1
formatting ×1
graphql-js ×1
gridsome ×1
javascript ×1
node.js ×1
react-redux ×1
typegraphql ×1
vue.js ×1