javascript - 为什么我的 sapper 后端代码在我的浏览器中执行?
问题描述
因此,我正在尝试使用 awios 从我的 sapper 服务器对 dockerized api 进行一些调用,并将结果传递给浏览器。我的电话由“call.js”文件提供。
我的“index.svelte”看起来像这样:
<script context="module">
import * as calls from "./../../utils/calls.js";
export async function preload({ params, query }) {
try{
let response = await calls.getStripePub();
return { api_key: response.data.key };
}catch(e){
console.log(e, "error")
this.error(500, "Oops, unexpected error there");
}
}
</script>
<script>
import Payplace from "./../../components/payplace/Payplace.svelte";
export let api_key;
</script>
<Payplace {api_key} />
我的 call.js 是:
import axios from "axios";
let backend = process.env.IP_BACK
let api_key = `${process.env.API_KEY_NAME}=${process.env.API_KEY}`
export async function getStripePub(){
console.log(`http://${backend}/stripe/getkeypub/?${api_key}`);
return await axios.get(`http://${backend}/stripe/getkeypub/?${api_key}`);
}
该代码在服务器端工作,但它也在我的浏览器中执行,显示
process is not defined
此外,我的浏览器下载的 index.js 文件包含
let backend = process.env.IP_BACK;
let api_key = `${process.env.API_KEY_NAME}=${process.env.API_KEY}`;
async function getStripePub(){
console.log(`http://${backend}/stripe/getkeypub/?${api_key}`);
return await axios$1.get(`http://${backend}/stripe/getkeypub/?${api_key}`);
}
为什么我的代码在“context='module'”脚本标签中被浏览器执行?
解决方案
推荐阅读
- regex - 正则表达式只允许数字、带点的数字、& 和空格
- python - 在 Django 中连续运行后台任务
- google-ads-api - 如何从 Google Adwords API 中提取基于不同归因模型的转化结果
- javascript - 为什么 JavaScript/jQuery 过滤列表在 iPhone 中不起作用?
- android - Android Swipe手势和项目点击都不能在RecyclerView中一起工作
- autohotkey - AutoHotkey:无法关闭此脚本的前一个实例。继续等待?
- javascript - 有没有办法减少复杂封闭 SVG 路径中的坐标数?
- angular8 - 如何通过单击具有 RouterLink 仅适用于移动设备的元素来关闭 Material SideNav
- orm - TypeORM getRepository.find() 不包括外键字段
- android - 修复嵌套recyclerview android中滚动条的高度