重命名env文件里面的参数名
This commit is contained in:
parent
84e0b406c0
commit
03f3bd679c
@ -2,8 +2,8 @@ import axios from 'axios';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const JINGROW_SERVER_URL = process.env.JINGROW_SERVER_URL;
|
||||
const JINGROW_SITE_NAME = process.env.JINGROW_SITE_NAME;
|
||||
const BACKEND_SERVER_URL = process.env.BACKEND_SERVER_URL;
|
||||
const BACKEND_SITE_NAME = process.env.BACKEND_SITE_NAME;
|
||||
const PUBLIC_FILES_DIR = path.join(process.cwd(), 'public/files');
|
||||
|
||||
// 确保目录存在
|
||||
@ -18,7 +18,7 @@ async function downloadToLocal(fileUrl) {
|
||||
let fullUrl = fileUrl;
|
||||
if (!/^https?:\/\//.test(fileUrl)) {
|
||||
// 相对路径,拼接服务器地址
|
||||
fullUrl = `${JINGROW_SERVER_URL}${fileUrl}`;
|
||||
fullUrl = `${BACKEND_SERVER_URL}${fileUrl}`;
|
||||
}
|
||||
// 取文件名
|
||||
const fileName = path.basename(fullUrl.split('?')[0]);
|
||||
@ -48,8 +48,8 @@ export async function GET(request) {
|
||||
return Response.json({ error: '缺少component_name参数' }, { status: 400 });
|
||||
}
|
||||
const response = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_component_data`,
|
||||
{ params: { component_name, site_name: JINGROW_SITE_NAME } }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_component_data`,
|
||||
{ params: { component_name, site_name: BACKEND_SITE_NAME } }
|
||||
);
|
||||
let data = response.data.message?.data || {};
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const JINGROW_SERVER_URL = process.env.JINGROW_SERVER_URL;
|
||||
const JINGROW_SITE_NAME = process.env.JINGROW_SITE_NAME;
|
||||
const BACKEND_SERVER_URL = process.env.BACKEND_SERVER_URL;
|
||||
const BACKEND_SITE_NAME = process.env.BACKEND_SITE_NAME;
|
||||
|
||||
// 递归处理菜单层级,拼接完整 slug 路径
|
||||
function buildMenuTree(items, parent = null, parentPath = "") {
|
||||
@ -26,8 +26,8 @@ function buildMenuTree(items, parent = null, parentPath = "") {
|
||||
export async function GET(request) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_menu`,
|
||||
{ params: { site_name: JINGROW_SITE_NAME } }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_menu`,
|
||||
{ params: { site_name: BACKEND_SITE_NAME } }
|
||||
);
|
||||
const items = response.data.message?.data || [];
|
||||
const menuTree = buildMenuTree(items);
|
||||
|
||||
@ -2,8 +2,8 @@ import axios from 'axios';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const JINGROW_SERVER_URL = process.env.JINGROW_SERVER_URL;
|
||||
const JINGROW_SITE_NAME = process.env.JINGROW_SITE_NAME;
|
||||
const BACKEND_SERVER_URL = process.env.BACKEND_SERVER_URL;
|
||||
const BACKEND_SITE_NAME = process.env.BACKEND_SITE_NAME;
|
||||
const PUBLIC_FILES_DIR = path.join(process.cwd(), 'public/files');
|
||||
|
||||
if (!fs.existsSync(PUBLIC_FILES_DIR)) {
|
||||
@ -14,7 +14,7 @@ async function downloadToLocal(fileUrl) {
|
||||
try {
|
||||
let fullUrl = fileUrl;
|
||||
if (!/^https?:\/\//.test(fileUrl)) {
|
||||
fullUrl = `${JINGROW_SERVER_URL}${fileUrl}`;
|
||||
fullUrl = `${BACKEND_SERVER_URL}${fileUrl}`;
|
||||
}
|
||||
const fileName = path.basename(fullUrl.split('?')[0]);
|
||||
const localPath = path.join(PUBLIC_FILES_DIR, fileName);
|
||||
@ -65,10 +65,10 @@ export async function POST(request) {
|
||||
if (!Array.isArray(slug_list)) {
|
||||
return Response.json({ error: 'slug_list参数必须为数组' }, { status: 400 });
|
||||
}
|
||||
const params = { slug_list: JSON.stringify(slug_list), page, site_name: JINGROW_SITE_NAME };
|
||||
const params = { slug_list: JSON.stringify(slug_list), page, site_name: BACKEND_SITE_NAME };
|
||||
if (page_size) params.page_size = page_size;
|
||||
const response = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_page_data`,
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_page_data`,
|
||||
{ params }
|
||||
);
|
||||
const message = response.data.message;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const JINGROW_SERVER_URL = process.env.JINGROW_SERVER_URL;
|
||||
const JINGROW_SITE_NAME = process.env.JINGROW_SITE_NAME;
|
||||
const BACKEND_SERVER_URL = process.env.BACKEND_SERVER_URL;
|
||||
const BACKEND_SITE_NAME = process.env.BACKEND_SITE_NAME;
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
@ -11,8 +11,8 @@ export async function POST(request) {
|
||||
return Response.json({ error: 'Missing parameters: subject and content are required.' }, { status: 400 });
|
||||
}
|
||||
const response = await axios.post(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.send_email`,
|
||||
{ subject, content, site_name: JINGROW_SITE_NAME }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.send_email`,
|
||||
{ subject, content, site_name: BACKEND_SITE_NAME }
|
||||
);
|
||||
const message = response.data.message;
|
||||
if (message?.success) {
|
||||
|
||||
@ -6,7 +6,7 @@ const nextConfig = {
|
||||
},
|
||||
allowedDevOrigins,
|
||||
env: {
|
||||
JINGROW_SERVER_URL: process.env.JINGROW_SERVER_URL,
|
||||
BACKEND_SERVER_URL: process.env.BACKEND_SERVER_URL,
|
||||
// 你还可以加其他需要暴露到前端的变量
|
||||
}
|
||||
};
|
||||
|
||||
@ -2,8 +2,8 @@ import axios from 'axios';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const JINGROW_SERVER_URL = process.env.JINGROW_SERVER_URL;
|
||||
const JINGROW_SITE_NAME = process.env.JINGROW_SITE_NAME;
|
||||
const BACKEND_SERVER_URL = process.env.BACKEND_SERVER_URL;
|
||||
const BACKEND_SITE_NAME = process.env.BACKEND_SITE_NAME;
|
||||
const PUBLIC_FILES_DIR = path.join(process.cwd(), 'public/files');
|
||||
|
||||
if (!fs.existsSync(PUBLIC_FILES_DIR)) {
|
||||
@ -13,8 +13,8 @@ if (!fs.existsSync(PUBLIC_FILES_DIR)) {
|
||||
// 直接内置鉴权头部生成函数,避免跨文件依赖
|
||||
function get_jingrow_api_headers() {
|
||||
// 这里应根据实际情况实现获取token等逻辑
|
||||
const apiKey = process.env.JINGROW_API_KEY;
|
||||
const apiSecret = process.env.JINGROW_API_SECRET;
|
||||
const apiKey = process.env.BACKEND_API_KEY;
|
||||
const apiSecret = process.env.BACKEND_API_SECRET;
|
||||
return {
|
||||
'Authorization': `token ${apiKey}:${apiSecret}`,
|
||||
'Content-Type': 'application/json'
|
||||
@ -26,7 +26,7 @@ export async function downloadToLocal(fileUrl) {
|
||||
try {
|
||||
let fullUrl = fileUrl;
|
||||
if (!/^https?:\/\//.test(fileUrl)) {
|
||||
fullUrl = `${JINGROW_SERVER_URL}${fileUrl}`;
|
||||
fullUrl = `${BACKEND_SERVER_URL}${fileUrl}`;
|
||||
}
|
||||
const fileName = path.basename(fullUrl.split('?')[0]);
|
||||
const localPath = path.join(PUBLIC_FILES_DIR, fileName);
|
||||
@ -121,11 +121,11 @@ export async function getPageData({
|
||||
throw new Error('slug_list must be an array');
|
||||
}
|
||||
|
||||
const params = { slug_list: JSON.stringify(slug_list), page, site_name: JINGROW_SITE_NAME };
|
||||
const params = { slug_list: JSON.stringify(slug_list), page, site_name: BACKEND_SITE_NAME };
|
||||
if (page_size) params.page_size = page_size;
|
||||
|
||||
const response = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_page_data`,
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_page_data`,
|
||||
{ params }
|
||||
);
|
||||
|
||||
@ -159,8 +159,8 @@ export async function getPageData({
|
||||
export async function getAllSlugs() {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_all_slugs`,
|
||||
{ params: { site_name: JINGROW_SITE_NAME } }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_all_slugs`,
|
||||
{ params: { site_name: BACKEND_SITE_NAME } }
|
||||
);
|
||||
const slugs = response.data.message?.data;
|
||||
if (!Array.isArray(slugs)) {
|
||||
@ -188,9 +188,9 @@ export async function getAllSlugs() {
|
||||
export async function fetchComponentData(componentName) {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_component_data`,
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_component_data`,
|
||||
{
|
||||
params: { component_name: componentName, site_name: JINGROW_SITE_NAME },
|
||||
params: { component_name: componentName, site_name: BACKEND_SITE_NAME },
|
||||
}
|
||||
);
|
||||
return { data: res.data.message?.data || null };
|
||||
@ -211,12 +211,12 @@ export async function fetchComponentData(componentName) {
|
||||
|
||||
export async function fetchListViewData({ pagetype, category, count }) {
|
||||
try {
|
||||
const params = { pagetype, site_name: JINGROW_SITE_NAME };
|
||||
const params = { pagetype, site_name: BACKEND_SITE_NAME };
|
||||
if (category) params.category = category;
|
||||
if (count !== undefined && count !== null) params.count = String(count);
|
||||
|
||||
const res = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_listview_data`,
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_listview_data`,
|
||||
{ params }
|
||||
);
|
||||
|
||||
@ -236,8 +236,8 @@ export async function fetchListViewData({ pagetype, category, count }) {
|
||||
export async function fetchCategoryData({ pagetype, name }) {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_category`,
|
||||
{ params: { pagetype, name, site_name: JINGROW_SITE_NAME } }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_category`,
|
||||
{ params: { pagetype, name, site_name: BACKEND_SITE_NAME } }
|
||||
);
|
||||
return { data: res.data.message?.data || null };
|
||||
} catch (error) {
|
||||
@ -256,8 +256,8 @@ export async function fetchCategoryData({ pagetype, name }) {
|
||||
export async function getMenuData() {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_menu`,
|
||||
{ params: { site_name: JINGROW_SITE_NAME } }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_menu`,
|
||||
{ params: { site_name: BACKEND_SITE_NAME } }
|
||||
);
|
||||
const items = response.data.message?.data || [];
|
||||
// 递归组装菜单树
|
||||
@ -288,8 +288,8 @@ export async function getMenuData() {
|
||||
export async function getSiteSettings() {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`${JINGROW_SERVER_URL}/api/action/jsite.api.v1.get_site_settings`,
|
||||
{ headers: get_jingrow_api_headers(), params: { site_name: JINGROW_SITE_NAME } }
|
||||
`${BACKEND_SERVER_URL}/api/action/jsite.api.v1.get_site_settings`,
|
||||
{ headers: get_jingrow_api_headers(), params: { site_name: BACKEND_SITE_NAME } }
|
||||
);
|
||||
return res.data?.message?.data || {
|
||||
site_name: "Jsite"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user