mirror of
https://github.com/teableio/teable
synced 2024-11-21 23:04:16 +00:00
fix: should not use host from request (#220)
* ci: build and push images * fix: should not use host from request
This commit is contained in:
parent
17cabcfc37
commit
7640591312
25
.github/workflows/docker-push.yml
vendored
Normal file
25
.github/workflows/docker-push.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: Build and Push to Alibaba Cloud Registry
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Login to Alibaba Cloud Docker Registry
|
||||||
|
run: docker login --username=${{ secrets.ALI_DOCKER_USERNAME }} registry.cn-beijing.aliyuncs.com --password=${{ secrets.ALI_DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
docker build -t registry.cn-beijing.aliyuncs.com/bieber/teable:${GITHUB_SHA} -f dockers/teable/Dockerfile .
|
||||||
|
docker push registry.cn-beijing.aliyuncs.com/bieber/teable:${GITHUB_SHA}
|
@ -1,6 +1,7 @@
|
|||||||
import type { ITableFullVo, ITableListVo, IRecord } from '@teable-group/core';
|
import type { ITableFullVo, ITableListVo, IRecord } from '@teable-group/core';
|
||||||
import { FieldKeyType, HttpError } from '@teable-group/core';
|
import { FieldKeyType, HttpError } from '@teable-group/core';
|
||||||
import type { IGetBaseVo } from '@teable-group/openapi';
|
import type { IGetBaseVo } from '@teable-group/openapi';
|
||||||
|
import type { IUser } from '@teable-group/sdk';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export class SsrApi {
|
export class SsrApi {
|
||||||
@ -54,6 +55,14 @@ export class SsrApi {
|
|||||||
async getBaseById(baseId: string) {
|
async getBaseById(baseId: string) {
|
||||||
return await this.axios.get<IGetBaseVo>(`/base/${baseId}`).then(({ data }) => data);
|
return await this.axios.get<IGetBaseVo>(`/base/${baseId}`).then(({ data }) => data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUserMe(cookie?: string) {
|
||||||
|
return await this.axios
|
||||||
|
.get<IUser>(`/auth/user/me`, {
|
||||||
|
headers: { cookie },
|
||||||
|
})
|
||||||
|
.then(({ data }) => data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ssrApi = new SsrApi();
|
export const ssrApi = new SsrApi();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
||||||
import { HttpError, parseDsn } from '@teable-group/core';
|
import { HttpError, parseDsn } from '@teable-group/core';
|
||||||
import { axios } from '@teable-group/openapi';
|
|
||||||
import type { IUser } from '@teable-group/sdk';
|
import type { IUser } from '@teable-group/sdk';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import timezone from 'dayjs/plugin/timezone';
|
import timezone from 'dayjs/plugin/timezone';
|
||||||
@ -12,6 +11,7 @@ import Head from 'next/head';
|
|||||||
import { appWithTranslation } from 'next-i18next';
|
import { appWithTranslation } from 'next-i18next';
|
||||||
import type { ReactElement, ReactNode } from 'react';
|
import type { ReactElement, ReactNode } from 'react';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { ssrApi } from '@/backend/api/rest/table.ssr';
|
||||||
import { colors } from '@/themes/colors';
|
import { colors } from '@/themes/colors';
|
||||||
import { INITIAL_THEME } from '@/themes/initial';
|
import { INITIAL_THEME } from '@/themes/initial';
|
||||||
import { getColorsCssVariablesText } from '@/themes/utils';
|
import { getColorsCssVariablesText } from '@/themes/utils';
|
||||||
@ -97,24 +97,20 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
|
|||||||
// calls page's `getInitialProps` and fills `appProps.pageProps`
|
// calls page's `getInitialProps` and fills `appProps.pageProps`
|
||||||
const appProps = await App.getInitialProps(appContext);
|
const appProps = await App.getInitialProps(appContext);
|
||||||
const res = appContext.ctx.res;
|
const res = appContext.ctx.res;
|
||||||
const host = appContext.ctx.req?.headers.host || '';
|
|
||||||
const isLoginPage = appContext.ctx.pathname.startsWith('/auth/login');
|
const isLoginPage = appContext.ctx.pathname.startsWith('/auth/login');
|
||||||
|
|
||||||
if (!res || !res?.writeHead) {
|
if (!res || !res?.writeHead) {
|
||||||
return appProps;
|
return appProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const { driver } = parseDsn(process.env.PRISMA_DATABASE_URL as string);
|
||||||
const { driver } = parseDsn(process.env.PRISMA_DATABASE_URL!);
|
|
||||||
const initialProps = {
|
const initialProps = {
|
||||||
...appProps,
|
...appProps,
|
||||||
driver,
|
driver,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await axios.get<IUser>(`http://${host}/api/auth/user/me`, {
|
const user = await ssrApi.getUserMe(appContext.ctx.req?.headers.cookie);
|
||||||
headers: { cookie: appContext.ctx.req?.headers.cookie },
|
|
||||||
});
|
|
||||||
// Already logged in
|
// Already logged in
|
||||||
if (user && isLoginPage) {
|
if (user && isLoginPage) {
|
||||||
res.writeHead(302, {
|
res.writeHead(302, {
|
||||||
@ -122,7 +118,7 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
|
|||||||
});
|
});
|
||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
return { ...initialProps, user: user.data };
|
return { ...initialProps, user };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof HttpError && !isLoginPage) {
|
if (error instanceof HttpError && !isLoginPage) {
|
||||||
const redirect = encodeURIComponent(appContext.ctx.req?.url || '');
|
const redirect = encodeURIComponent(appContext.ctx.req?.url || '');
|
||||||
@ -132,6 +128,7 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
|
|||||||
});
|
});
|
||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return initialProps;
|
return initialProps;
|
||||||
|
@ -5,6 +5,7 @@ services:
|
|||||||
container_name: integration-test
|
container_name: integration-test
|
||||||
build:
|
build:
|
||||||
context: ../
|
context: ../
|
||||||
|
dockerfile: ./dockers/teable/Dockerfile
|
||||||
target: builder
|
target: builder
|
||||||
args:
|
args:
|
||||||
INTEGRATION_TEST: 1
|
INTEGRATION_TEST: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user