Skip to content

Commit 2877eb1

Browse files
committed
fix(proxy): ignore _loading path when proxying to laravel
1 parent e9b57e9 commit 2877eb1

12 files changed

+4299
-3357
lines changed

lib/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.nuxtOutputEnv = exports.laravelAppEnv = exports.moduleKey = exports.scope = void 0;
34
exports.scope = 'nuxt:laravel';
45
exports.moduleKey = `__${exports.scope.replace(':', '_')}`;
56
exports.laravelAppEnv = 'APP_URL';

lib/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.swCacheDefaults = void 0;
34
const constants_1 = require("./constants");
45
const defaults = {
56
root: process.cwd(),

lib/module.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.meta = exports.nuxtOutputEnv = exports.laravelAppEnv = exports.moduleKey = void 0;
67
const fs_extra_1 = __importDefault(require("fs-extra"));
78
const path_1 = __importDefault(require("path"));
89
const execa_1 = __importDefault(require("execa"));
910
const url_1 = require("url");
1011
const os_1 = require("os");
1112
const constants_1 = require("./constants");
12-
exports.moduleKey = constants_1.moduleKey;
13-
exports.laravelAppEnv = constants_1.laravelAppEnv;
14-
exports.nuxtOutputEnv = constants_1.nuxtOutputEnv;
13+
Object.defineProperty(exports, "moduleKey", { enumerable: true, get: function () { return constants_1.moduleKey; } });
14+
Object.defineProperty(exports, "laravelAppEnv", { enumerable: true, get: function () { return constants_1.laravelAppEnv; } });
15+
Object.defineProperty(exports, "nuxtOutputEnv", { enumerable: true, get: function () { return constants_1.nuxtOutputEnv; } });
1516
const utils_1 = require("./utils");
1617
const options_1 = require("./options");
1718
const laravelModule = function (overwrites) {

lib/options.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5+
}) : (function(o, m, k, k2) {
6+
if (k2 === undefined) k2 = k;
7+
o[k2] = m[k];
8+
}));
9+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10+
Object.defineProperty(o, "default", { enumerable: true, value: v });
11+
}) : function(o, v) {
12+
o["default"] = v;
13+
});
514
var __importStar = (this && this.__importStar) || function (mod) {
615
if (mod && mod.__esModule) return mod;
716
var result = {};
8-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
9-
result["default"] = mod;
17+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18+
__setModuleDefault(result, mod);
1019
return result;
1120
};
21+
var __importDefault = (this && this.__importDefault) || function (mod) {
22+
return (mod && mod.__esModule) ? mod : { "default": mod };
23+
};
1224
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.getConfiguration = exports.validateOptions = void 0;
1326
const path_1 = __importDefault(require("path"));
1427
const dotenv_1 = __importDefault(require("dotenv"));
1528
const lodash_1 = require("lodash");

lib/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.getModuleOptions = exports.addBadgeMessage = exports.logger = void 0;
67
const chalk_1 = __importDefault(require("chalk"));
78
const consola_1 = __importDefault(require("consola"));
89
const constants_1 = require("./constants");

package.json

+36-36
Original file line numberDiff line numberDiff line change
@@ -37,53 +37,53 @@
3737
},
3838
"homepage": "https://github.com/m2sd/nuxt-laravel#readme",
3939
"devDependencies": {
40-
"@commitlint/cli": "^8.3.5",
41-
"@commitlint/config-conventional": "^8.3.4",
42-
"@nuxt/types": "^0.7.0",
43-
"@nuxtjs/axios": "^5.9.5",
44-
"@nuxtjs/module-test-utils": "^1.5.0",
45-
"@nuxtjs/proxy": "^1.3.3",
46-
"@nuxtjs/pwa": "^3.0.0-beta.20",
47-
"@olavoparno/jest-badges-readme": "^1.4.1",
48-
"@types/dotenv": "^6.1.1",
49-
"@types/fs-extra": "^8.1.0",
50-
"@types/jest": "^24.9.1",
51-
"@types/lodash": "^4.14.149",
52-
"@types/request-promise": "^4.1.45",
53-
"@types/tmp": "^0.1.0",
54-
"@typescript-eslint/eslint-plugin": "^2.21.0",
55-
"@typescript-eslint/parser": "^2.21.0",
40+
"@commitlint/cli": "^11.0.0",
41+
"@commitlint/config-conventional": "^11.0.0",
42+
"@nuxt/types": "^2.14.5",
43+
"@nuxtjs/axios": "^5.12.2",
44+
"@nuxtjs/module-test-utils": "^1.6.3",
45+
"@nuxtjs/proxy": "^2.0.1",
46+
"@nuxtjs/pwa": "^3.0.2",
47+
"@olavoparno/jest-badges-readme": "^1.5.1",
48+
"@types/dotenv": "^8.2.0",
49+
"@types/fs-extra": "^9.0.1",
50+
"@types/jest": "^26.0.13",
51+
"@types/lodash": "^4.14.161",
52+
"@types/request-promise": "^4.1.46",
53+
"@types/tmp": "^0.2.0",
54+
"@typescript-eslint/eslint-plugin": "^4.1.0",
55+
"@typescript-eslint/parser": "^4.1.0",
5656
"cpr": "^3.0.1",
57-
"cz-conventional-changelog": "^3.1.0",
58-
"eslint": "^6.8.0",
59-
"eslint-config-prettier": "^6.10.0",
60-
"eslint-plugin-import": "^2.20.1",
61-
"eslint-plugin-node": "^10.0.0",
62-
"eslint-plugin-prettier": "^3.1.2",
57+
"cz-conventional-changelog": "^3.3.0",
58+
"eslint": "^7.9.0",
59+
"eslint-config-prettier": "^6.11.0",
60+
"eslint-plugin-import": "^2.22.0",
61+
"eslint-plugin-node": "^11.1.0",
62+
"eslint-plugin-prettier": "^3.1.4",
6363
"eslint-plugin-promise": "^4.2.1",
64-
"husky": "^3.1.0",
65-
"jest": "^24.9.0",
66-
"loglevel": "^1.6.7",
67-
"nuxt": "^2.11.0",
68-
"prettier": "^1.19.1",
64+
"husky": "^4.3.0",
65+
"jest": "^26.4.2",
66+
"loglevel": "^1.7.0",
67+
"nuxt": "^2.14.5",
68+
"prettier": "^2.1.1",
6969
"rimraf": "^3.0.2",
70-
"standard-version": "^7.1.0",
71-
"ts-jest": "^24.3.0",
72-
"ts-node": "^8.6.2",
73-
"typescript": "^3.8.2"
70+
"standard-version": "^9.0.0",
71+
"ts-jest": "^26.3.0",
72+
"ts-node": "^9.0.0",
73+
"typescript": "^4.0.2"
7474
},
7575
"dependencies": {
7676
"dotenv": "^8.2.0",
77-
"execa": "^2.1.0",
78-
"fs-extra": "^8.1.0",
79-
"lodash": "^4.17.15"
77+
"execa": "^4.0.3",
78+
"fs-extra": "^9.0.1",
79+
"lodash": "^4.17.20"
8080
},
8181
"peerDependencies": {
8282
"@nuxtjs/axios": "^5.4.1",
8383
"@nuxtjs/proxy": "^1.3.3"
8484
},
8585
"optionalDependencies": {
86-
"@nuxtjs/pwa": "^3.0.0-beta.20"
86+
"@nuxtjs/pwa": "^3.0.2"
8787
},
8888
"config": {
8989
"commitizen": {
@@ -101,4 +101,4 @@
101101
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
102102
}
103103
}
104-
}
104+
}

src/defaults.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const defaults: Options = {
66
publicDir: 'public',
77
server: true,
88
swCache: false,
9-
dotEnvExport: false
9+
dotEnvExport: false,
1010
}
1111

1212
export const swCacheDefaults = {
1313
name: moduleKey,
1414
fileName: 'workbox.cache.js',
15-
endpoint: `/${moduleKey}_cache`
15+
endpoint: `/${moduleKey}_cache`,
1616
}
1717

1818
export default defaults

src/module.ts

+21-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { moduleKey, laravelAppEnv, nuxtOutputEnv } from './constants'
1111
import { logger, addBadgeMessage, getModuleOptions } from './utils'
1212
import { getConfiguration, Options } from './options'
1313

14-
const laravelModule: Module<Options> = function(overwrites) {
14+
const laravelModule: Module<Options> = function (overwrites) {
1515
const config = getConfiguration(this.options, overwrites)
1616

1717
/** GLOBAL CONTEXT **/
@@ -58,7 +58,7 @@ const laravelModule: Module<Options> = function(overwrites) {
5858
const { dst } = this.addTemplate({
5959
src: path.join(__dirname, 'templates', 'workbox.cache.ejs'),
6060
options: config.cache,
61-
fileName: config.cache.fileName
61+
fileName: config.cache.fileName,
6262
})
6363

6464
this.options.pwa = {
@@ -69,9 +69,9 @@ const laravelModule: Module<Options> = function(overwrites) {
6969
...(typeof routingExtensions === 'string'
7070
? [routingExtensions]
7171
: routingExtensions),
72-
path.join(this.options.buildDir!, dst)
73-
]
74-
}
72+
path.join(this.options.buildDir!, dst),
73+
],
74+
},
7575
}
7676

7777
this.requireModule('@nuxtjs/pwa')
@@ -110,18 +110,22 @@ const laravelModule: Module<Options> = function(overwrites) {
110110

111111
this.options.axios = {
112112
...(this.options.axios || {}),
113-
proxy: true
113+
proxy: true,
114114
}
115115
this.options.proxy = [
116116
...(this.options.proxy || []),
117117
[
118-
['**/*', `!${config.nuxt.urlPath}`],
118+
[
119+
'**/*',
120+
`!${config.nuxt.urlPath}`,
121+
`!${path.posix.join(config.routerBase, '_loading')}`,
122+
],
119123
{
120124
target: laravelUrl.origin,
121125
ws: false,
122-
logLevel: 'debug'
123-
}
124-
]
126+
logLevel: 'debug',
127+
},
128+
],
125129
]
126130

127131
// configure proxy
@@ -133,7 +137,7 @@ const laravelModule: Module<Options> = function(overwrites) {
133137
// First, check if there is an unnamed route
134138
// Then, check if there's a route at /
135139
// Finally, check for a name with first segment index
136-
route =>
140+
(route) =>
137141
route.name === '' ||
138142
route.path === '/' ||
139143
!!(route.name && route.name.match(/^index(-\w+)?$/))
@@ -148,7 +152,7 @@ const laravelModule: Module<Options> = function(overwrites) {
148152
if (i18nOptions && i18nOptions.defaultLocale) {
149153
const separator = i18nOptions.routesNameSeparator || '___'
150154
index = routes.find(
151-
route =>
155+
(route) =>
152156
!!(
153157
route.name &&
154158
route.name.match(
@@ -173,7 +177,7 @@ const laravelModule: Module<Options> = function(overwrites) {
173177
routes.push({
174178
...index,
175179
name: moduleKey,
176-
path: config.nuxt.routerPath
180+
path: config.nuxt.routerPath,
177181
})
178182
})
179183

@@ -228,18 +232,18 @@ const laravelModule: Module<Options> = function(overwrites) {
228232
? '127.0.0.1'
229233
: laravelUrl.hostname
230234
}`,
231-
`--port=${laravelUrl.port}`
235+
`--port=${laravelUrl.port}`,
232236
],
233237
{
234238
cwd: config.laravel.root,
235239
// forward render path and baseUrl as env variables
236240
env: {
237241
...process.env,
238242
[laravelAppEnv]: nuxtUrl.origin,
239-
[nuxtOutputEnv]: nuxtUrl.href
243+
[nuxtOutputEnv]: nuxtUrl.href,
240244
},
241245
stderr: process.stderr,
242-
stdout: process.stdout
246+
stdout: process.stdout,
243247
}
244248
)
245249

@@ -272,7 +276,7 @@ const laravelModule: Module<Options> = function(overwrites) {
272276
...this.options.generate,
273277
dir: config.output.src,
274278
exclude: [/.*/],
275-
fallback: config.output.fallback
279+
fallback: config.output.fallback,
276280
}
277281

278282
this.nuxt.hook('generate:done', async ({ nuxt }: { nuxt: any }) => {

src/options.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path'
22
import dotenv from 'dotenv'
33
import { merge } from 'lodash'
44

5-
import { Configuration } from '@nuxt/types'
5+
import { NuxtConfig } from '@nuxt/types'
66

77
import defaults, { swCacheDefaults } from './defaults'
88
import { moduleKey, nuxtOutputEnv } from './constants'
@@ -45,7 +45,7 @@ export const validateOptions = (
4545
}
4646

4747
export const getConfiguration = (
48-
nuxtOptions: Configuration,
48+
nuxtOptions: NuxtConfig,
4949
overwrites?: Options
5050
) => {
5151
const routerBase = (nuxtOptions.router && nuxtOptions.router.base) || '/'
@@ -58,7 +58,7 @@ export const getConfiguration = (
5858

5959
const nuxt = {
6060
urlPath: path.posix.join(routerBase, moduleKey),
61-
routerPath: `/${moduleKey}`
61+
routerPath: `/${moduleKey}`,
6262
}
6363

6464
const laravel = (() => {
@@ -69,7 +69,7 @@ export const getConfiguration = (
6969
: options.server && nuxtOptions.server
7070
? {
7171
host: nuxtOptions.server.host,
72-
port: +(nuxtOptions.server.port || 3000) + 1
72+
port: +(nuxtOptions.server.port || 3000) + 1,
7373
}
7474
: (false as false)
7575

@@ -85,7 +85,7 @@ export const getConfiguration = (
8585
return {
8686
root: laravelRoot,
8787
public: path.resolve(laravelRoot, options.publicDir),
88-
server
88+
server,
8989
}
9090
})()
9191

@@ -99,7 +99,7 @@ export const getConfiguration = (
9999
fallback: `${routerBase.length > 1 ? 'index' : 'spa'}.html`,
100100
additional: outputPath
101101
? path.resolve(laravel.root, outputPath)
102-
: (false as false)
102+
: (false as false),
103103
}
104104
})()
105105

@@ -123,6 +123,6 @@ export const getConfiguration = (
123123
laravel,
124124
output,
125125
cache,
126-
routerBase
126+
routerBase,
127127
}
128128
}

0 commit comments

Comments
 (0)