fix: change API_PORT to SERVER_PORT

This commit is contained in:
chenos 2022-04-21 14:51:00 +08:00
parent dda2ed1f77
commit f1d7d14145
2 changed files with 13 additions and 14 deletions

View File

@ -1,13 +1,12 @@
import { promisify } from 'util';
import { promises as fs } from 'fs';
import path from 'path';
import { getApp } from '.';
import { FILE_FIELD_NAME, STORAGE_TYPE_LOCAL } from '../constants';
import { getApp, requestFile } from '.';
const { LOCAL_STORAGE_BASE_URL, API_PORT = '13002' } = process.env;
const DEFAULT_LOCAL_BASE_URL = LOCAL_STORAGE_BASE_URL || `http://localhost:${API_PORT}/uploads`;
const { LOCAL_STORAGE_BASE_URL, SERVER_PORT = '13002' } = process.env;
const DEFAULT_LOCAL_BASE_URL = LOCAL_STORAGE_BASE_URL || `http://localhost:${SERVER_PORT}/uploads`;
describe('action', () => {
let app;
@ -83,7 +82,7 @@ describe('action', () => {
expect(file.toString()).toBe('Hello world!\n');
// 通过 url 是否能正确访问
const url = attachment.url.replace(`http://localhost:${API_PORT}`, '');
const url = attachment.url.replace(`http://localhost:${SERVER_PORT}`, '');
const content = await agent.get(url);
expect(content.text).toBe('Hello world!\n');
});
@ -135,7 +134,7 @@ describe('action', () => {
});
it('upload to assoiciated field and storage with full base url should be ok', async () => {
const BASE_URL = `http://localhost:${API_PORT}/another-uploads`;
const BASE_URL = `http://localhost:${SERVER_PORT}/another-uploads`;
const storageName = 'local_private';
const urlPath = 'test/path';
const Storage = db.getCollection('storages').model;
@ -161,7 +160,7 @@ describe('action', () => {
// 文件的 url 是否正常生成
expect(body.data.url).toBe(`${BASE_URL}/${urlPath}/${body.data.filename}`);
console.log(body.data.url);
const url = body.data.url.replace(`http://localhost:${API_PORT}`, '');
const url = body.data.url.replace(`http://localhost:${SERVER_PORT}`, '');
const content = await agent.get(url);
expect(content.text).toBe('Hello world!\n');
});

View File

@ -1,11 +1,11 @@
import path from 'path';
import { URL } from 'url';
import Application from '@nocobase/server';
import serve from 'koa-static';
import mkdirp from 'mkdirp';
import multer from 'multer';
import serve from 'koa-static';
import path from 'path';
import { URL } from 'url';
import { STORAGE_TYPE_LOCAL } from '../constants';
import { getFilename } from '../utils';
import Application from '@nocobase/server';
// use koa-mount match logic
function match(basePath: string, pathname: string): boolean {
@ -53,7 +53,7 @@ function getDocumentRoot(storage): string {
}
async function middleware(app: Application, options?) {
const LOCALHOST = `http://localhost:${process.env.API_PORT || '13002'}`;
const LOCALHOST = `http://localhost:${process.env.SERVER_PORT || '13002'}`;
const Storage = app.db.getCollection('storages');
const storages = new Map<string, any>();
@ -122,7 +122,7 @@ export default {
title: '本地存储',
type: STORAGE_TYPE_LOCAL,
name: `local`,
baseUrl: process.env.LOCAL_STORAGE_BASE_URL || `http://localhost:${process.env.API_PORT || '13002'}/uploads`,
baseUrl: process.env.LOCAL_STORAGE_BASE_URL || `http://localhost:${process.env.SERVER_PORT || '13002'}/uploads`,
};
},
};