I'm trying to deploy my Nuxt project using apache and pm2.
The nuxt project will be the front-end, and it has a backend api that is on a different domain.
I got the virtual host setup fine, I can access the login page but for some reasons, it always returns a 404 on one .js file that's supposed to be generated after I ran yarn build
inside .nuxt/dist/client folder.
Some odd thing that's worth noting though is that when I use an invalid API_URL, like if I use a non-existent url https://xxx.xxx/api/1
instead of the correct url https://xxx.xxx/api/v1
. The error will disappear after retrying yarn build
and pm2 restart
My setup:
- OS: Debian 11
- Server: Apache2 & pm2
My nuxt.config.js
import colors from "vuetify/es5/util/colors";
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
titleTemplate: "%s - " + process.env.APP_NAME,
title: process.env.APP_NAME,
htmlAttrs: {
lang: "en",
},
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "" },
{ name: "format-detection", content: "telephone=no" },
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
},
watchers: {
webpack: {
aggregateTimeout: 300,
poll: 1000,
},
},
auth: {
strategies: {
laravelPassport: {
provider: "laravel/passport",
endpoints: {
userInfo: process.env.API_URL + "/me",
},
url: process.env.API_SERVER,
clientId: process.env.PASSPORT_CLIENT_ID,
clientSecret: process.env.PASSPORT_CLIENT_SECRET,
},
local: {
endpoints: {
login: {
url: "/user/login",
method: "post",
propertyName: "data.access_token",
},
logout: { url: "/user/logout", method: "post" },
user: { url: "/me", method: "get", propertyName: "data" },
},
token: {
property: "data.access_token",
},
user: {
property: "data",
},
tokenRequired: true,
tokenType: "Bearer",
autoFetchUser: true,
},
customStrategy: {
scheme: "~/schemes/customScheme",
endpoints: {
login: {
url: "/user/login",
method: "post",
propertyName: "data.access_token",
},
logout: { url: "/user/logout", method: "post" },
user: { url: "/me", method: "get", propertyName: "data" },
},
tokenRequired: true,
tokenType: "Bearer",
autoFetchUser: true,
},
},
redirect: {
login: "/",
logout: "/",
home: "/admin",
},
},
router: {
middleware: ["auth"],
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: ["~plugins/vue-api-query"],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/vuetify
"@nuxtjs/vuetify",
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: ["@nuxtjs/axios", "@nuxtjs/auth-next"],
// Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
vuetify: {
customVariables: ["~/assets/variables.scss"],
theme: {
dark: false,
themes: {
dark: {
primary: colors.blue.darken2,
accent: colors.grey.darken3,
secondary: colors.amber.darken3,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: colors.deepOrange.accent4,
success: colors.green.accent3,
},
},
},
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
maxChunkSize: 300000,
extend(config, ctx) {
config.performance.maxAssetSize = 700 * 1024;
},
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: process.env.API_SERVER || "https://xxx.xxx",
apiUrl: process.env.API_URL || "https://xxx.xxx/api/v1",
headers: {
common: {
Platform: "web",
},
},
},
};