Skip to content

Commit a4265bb

Browse files
authored
fix: Default HTML pages for password reset, email verification not found (#10041)
1 parent c1f1800 commit a4265bb

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

spec/PagesRouter.spec.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ describe('Pages Router', () => {
225225
expect(Config.get(Parse.applicationId).pages.forceRedirect).toBe(
226226
Definitions.PagesOptions.forceRedirect.default
227227
);
228-
expect(Config.get(Parse.applicationId).pages.pagesPath).toBe(
229-
Definitions.PagesOptions.pagesPath.default
230-
);
228+
expect(Config.get(Parse.applicationId).pages.pagesPath).toBeUndefined();
231229
expect(Config.get(Parse.applicationId).pages.pagesEndpoint).toBe(
232230
Definitions.PagesOptions.pagesEndpoint.default
233231
);
@@ -1236,6 +1234,36 @@ describe('Pages Router', () => {
12361234
});
12371235
});
12381236

1237+
describe('pagesPath resolution', () => {
1238+
it('should serve pages when current working directory differs from module directory', async () => {
1239+
const originalCwd = process.cwd();
1240+
const os = require('os');
1241+
process.chdir(os.tmpdir());
1242+
1243+
try {
1244+
await reconfigureServer({
1245+
appId: 'test',
1246+
appName: 'exampleAppname',
1247+
publicServerURL: 'http://localhost:8378/1',
1248+
pages: { enableRouter: true },
1249+
});
1250+
1251+
// Request the password reset page with an invalid token;
1252+
// even with an invalid token, the server should serve the
1253+
// "invalid link" page (200), not a 404. A 404 indicates the
1254+
// HTML template files could not be found because pagesPath
1255+
// resolved to the wrong directory.
1256+
const response = await request({
1257+
url: 'http://localhost:8378/1/apps/test/request_password_reset?token=invalidToken',
1258+
}).catch(e => e);
1259+
expect(response.status).toBe(200);
1260+
expect(response.text).toContain('Invalid password reset link');
1261+
} finally {
1262+
process.chdir(originalCwd);
1263+
}
1264+
});
1265+
});
1266+
12391267
describe('XSS Protection', () => {
12401268
beforeEach(async () => {
12411269
await reconfigureServer({

src/Config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ export class Config {
326326
} else if (!isBoolean(pages.forceRedirect)) {
327327
throw 'Parse Server option pages.forceRedirect must be a boolean.';
328328
}
329-
if (pages.pagesPath === undefined) {
330-
pages.pagesPath = PagesOptions.pagesPath.default;
331-
} else if (!isString(pages.pagesPath)) {
329+
if (pages.pagesPath !== undefined && !isString(pages.pagesPath)) {
332330
throw 'Parse Server option pages.pagesPath must be a string.';
333331
}
334332
if (pages.pagesEndpoint === undefined) {

src/Options/Definitions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,7 @@ module.exports.PagesOptions = {
772772
pagesPath: {
773773
env: 'PARSE_SERVER_PAGES_PAGES_PATH',
774774
help:
775-
"The path to the pages directory; this also defines where the static endpoint '/apps' points to. Default is the './public/' directory.",
776-
default: './public',
775+
"The path to the pages directory; this also defines where the static endpoint '/apps' points to. Default is the './public/' directory of the parse-server module.",
777776
},
778777
placeholders: {
779778
env: 'PARSE_SERVER_PAGES_PLACEHOLDERS',

src/Options/docs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ export interface PagesOptions {
437437
/* Is true if responses should always be redirects and never content, false if the response type should depend on the request type (GET request -> content response; POST request -> redirect response).
438438
:DEFAULT: false */
439439
forceRedirect: ?boolean;
440-
/* The path to the pages directory; this also defines where the static endpoint '/apps' points to. Default is the './public/' directory.
441-
:DEFAULT: ./public */
440+
/* The path to the pages directory; this also defines where the static endpoint '/apps' points to. Default is the './public/' directory of the parse-server module. */
442441
pagesPath: ?string;
443442
/* The API endpoint for the pages. Default is 'apps'.
444443
:DEFAULT: apps */

0 commit comments

Comments
 (0)