错误页面和 pm2 部署
错误页面
在根目录新建 error.vue 文件
html
<template>
<div class="error-container">你的页面发生错误了~</div>
</template>
<script setup>
definePageMeta({
layout: "error",
});
</script>
<style scoped lang="scss">
.error-container {
}
</style>
pm2 部署
在根目录 新建 ecosystem.config.cjs
ts
module.exports = {
apps: [
{
name: "xxx",
script: "./.output/server/index.mjs",
log_date_format: "YYYY-MM-DD HH:mm:ss",
instances: "max", // 进程实例的数量,"max" 表示根据 CPU 核心数自动设置
exec_mode: "cluster", // 运行模式,"cluster" 表示使用集群模式
max_memory_restart: "3G", // 在内存达到指定大小时自动重启应用程序
port: "10200", // 端口号
},
],
};
- 把.output 和配置文件上传到服务器,然后使用 pm2 启动,目录结构可以自己调整
ts
pm2 start ecosystem.config.js // 启动服务
pm2 list // 查看是否启动成功
- 设置遇到错误自动重启
ts
pm2 startup