Skip to content

Commit

Permalink
fix(platform-server): artifact link use public path
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyi.levi committed Feb 2, 2023
1 parent 660c526 commit d4add46
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 46 deletions.
7 changes: 4 additions & 3 deletions packages/platform-server/src/app.entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ export async function createApp() {
const config = app.get(Config)
const metrics = app.get(Metric)

if (config.publicPath !== config.origin) {
if (config.dev) {
app.enableCors({
origin: config.publicPath,
origin: /localhost/,
credentials: true,
})
}

Expand All @@ -57,7 +58,7 @@ export async function createApp() {
name: 'perfsee_sid',
cookie: {
maxAge: 14 * 24 * 60 * 60 * 1000, // 14 days
secure: process.env.NODE_ENV !== 'development',
secure: config.prod,
httpOnly: true,
sameSite: 'lax',
},
Expand Down
27 changes: 0 additions & 27 deletions packages/platform-server/src/config/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@ export interface PerfseeConfig {
*/
path: string

/**
*
* where the frontend get deployed.
* if not set, it will be the same as `https?://[host]/[path]`
*
* @env PERFSEE_PUBLIC_PATH
*/
_publicPath?: string

/**
*
* where the frontend get deployed.
* if not set, it will be the same as `https?://[host]/[path]`
*
* @env PERFSEE_PUBLIC_PATH
*/
get publicPath(): string

/**
*
* where the frontend get deployed.
* if not set, it will be the same as `https?://[host]/[path]`
*
* @env PERFSEE_PUBLIC_PATH
*/
set publicPath(value: string)

/**
* Readonly property `baseUrl` is the full url of the server consists of `https://HOST:PORT/PATH`.
*
Expand Down
10 changes: 3 additions & 7 deletions packages/platform-server/src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ export const getDefaultPerfseeConfig: () => PerfseeConfig = () => ({
host: 'localhost',
port: 3000,
path: '',
get publicPath() {
return this._publicPath ?? this.origin
},
set publicPath(value: string) {
this._publicPath = value
},
get origin() {
return `${this.https ? 'https' : 'http'}://${this.host}${this.host === 'localhost' ? `:${this.port}` : ''}`
return this.dev
? 'http://localhost:8080'
: `${this.https ? 'https' : 'http'}://${this.host}${this.host === 'localhost' ? `:${this.port}` : ''}`
},
get baseUrl() {
return `${this.origin}${this.path}`
Expand Down
3 changes: 2 additions & 1 deletion packages/platform-server/src/modules/artifact/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { InternalIdService, UrlService } from '@perfsee/platform-server/helpers'
import { Logger } from '@perfsee/platform-server/logger'
import { Metric } from '@perfsee/platform-server/metrics'
import { ObjectStorage } from '@perfsee/platform-server/storage'
import { artifactKey } from '@perfsee/platform-server/utils'
import { BundleJobUpdate, JobType } from '@perfsee/server-common'
import { BuildUploadParams, GitHost, gitHostFromDomain, isBaseline } from '@perfsee/shared'
import { pathFactory } from '@perfsee/shared/routes'
Expand Down Expand Up @@ -95,7 +96,7 @@ export class ArtifactController {
try {
await this.projectUsage.verifyUsageLimit(project.id)

const buildKey = `builds/${project.id}/${uuid()}.tar`
const buildKey = artifactKey(project.id, `builds/${uuid()}.tar`)
await this.storage.upload(buildKey, file)

await this.projectUsage.recordStorageUsage(project.id, file.byteLength)
Expand Down
5 changes: 5 additions & 0 deletions packages/platform-server/src/modules/artifact/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ export class ArtifactResolver {

@ResolveField(() => String, { description: 'the link to uploaded build tar file' })
buildLink(@Parent() artifact: Artifact) {
// we drop the support for old build artifact keys
if (!artifact.buildKey.startsWith('artifacts')) {
return ''
}

return artifactLink(artifact.buildKey)
}

Expand Down
6 changes: 1 addition & 5 deletions packages/platform-server/src/perfsee.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ const env = process.env
// # where the server get deployed.
// perfsee.host = 'perfsee.com'

// # where the frontend get deployed.
// # if not set, it will be the same as `https?://[host]/[path]`
// perfsee.publicPath = 'https://perfsee.com'

// # which port the server will listen on
// perfsee.port = 3000

Expand Down Expand Up @@ -97,7 +93,7 @@ perfsee.email.enable = true
// }
// # object storage that used to put all job logs
// # will fallback to `perfsee.objectStorage.artifact` if not set
// perfsee.objectStorage.logLog = {
// perfsee.objectStorage.jobLog = {
// provider: 'aws',
// region: 'eu-west-1',
// aws_access_key_id: '',
Expand Down
1 change: 0 additions & 1 deletion packages/platform-server/src/perfsee.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ perfsee.ENV_MAP = {
PERFSEE_SERVER_HOST: 'host',
PERFSEE_SERVER_PORT: ['port', 'int'],
PERFSEE_SERVER_SUB_PATH: 'path',
PERFSEE_PUBLIC_PATH: 'publicPath',
MYSQL_URL: 'mysql.url',
MYSQL_PORT: ['mysql.port', 'int'],
MYSQL_HOST: 'mysql.host',
Expand Down
1 change: 0 additions & 1 deletion packages/schema/src/graphql/bundle/fragments/artifact.gql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ fragment artifact on Artifact {
status
duration
failedReason
buildLink
reportLink
contentLink
score
Expand Down
2 changes: 1 addition & 1 deletion tools/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const config: () => webpack.Configuration = () => {
export async function startDevServer(entry: string, externalConfig: webpack.Configuration) {
return Promise.all([watchRoutes(), watchGraphqlSchema()]).then(async () => {
const compiler = webpack(merge(config(), { entry }, externalConfig))
const serverProxyRoutes = ['/graphql', '/auth', '/oauth2', '/api', '/health', '/github', '/docs']
const serverProxyRoutes = ['/graphql', '/auth', '/oauth2', '/health', '/github', '/docs', '/artifacts']
const devServer = new WebpackDevServer(
{
historyApiFallback: true,
Expand Down

0 comments on commit d4add46

Please sign in to comment.