Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

844 username routes 404 #851

Merged
merged 5 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/ResolveRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export const routeRegex = {
PostsIndex: /^\/(@[\w\.\d-]+)\/feed\/?$/,
UserProfile1: /^\/(@[\w\.\d-]+)\/?$/,
UserProfile2: /^\/(@[\w\.\d-]+)\/(blog|posts|comments|recommended|transfers|curation-rewards|author-rewards|permissions|created|recent-replies|feed|password|followed|followers|settings)\/?$/,
UserRoute: /^(@[\w\.\d//-]+)?/,
UserEndPoints: /^(blog|posts|comments|recommended|transfers|curation-rewards|author-rewards|permissions|created|recent-replies|feed|password|followed|followers|settings)$/,
CategoryFilters: /^\/(hot|created|trending|active|promoted)\/?$/ig,
PostNoCategory: /^\/(@[\w\.\d-]+)\/([\w\d-]+)/
}

Expand Down
23 changes: 15 additions & 8 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import flash from 'koa-flash';
import minimist from 'minimist';
import Grant from 'grant-koa';
import config from '../config';
import secureRandom from 'secure-random'
import {routeRegex} from 'app/ResolveRoute';
import secureRandom from 'secure-random';

const grant = new Grant(config.grant);
// import uploadImage from 'server/upload-image' //medium-editor
Expand All @@ -49,20 +50,26 @@ app.use(function *(next) {
return;
}
// normalize user name url from cased params
if (this.method === 'GET' && /^\/(@[\w\.\d-]+)\/?$/.test(this.url)) {
if (this.method === 'GET' && routeRegex.UserProfile1.test(this.url)) {
const p = this.originalUrl.toLowerCase();
if(p !== this.originalUrl) {
this.redirect(p);
return;
}
}
// // handle non-existing users endpoints with 404
if (this.method === 'GET' && routeRegex.UserRoute.test(this.url)) {
const segments = this.url.split('/');
if(segments[2] && !routeRegex.UserEndPoints.test(segments[2])) {
this.status = 404;
return;
}
}
// normalize top category filtering from cased params
if (this.method === 'GET' && /^\/(hot|created|trending|active)\//.test(this.url)) {
const segments = this.url.split('/')
const category = segments[2]
if(category !== category.toLowerCase()) {
segments[2] = category.toLowerCase()
this.redirect(segments.join('/'));
if (this.method === 'GET' && routeRegex.CategoryFilters.test(this.url)) {
const p = this.originalUrl.toLowerCase();
if(p !== this.originalUrl) {
this.redirect(p);
return;
}
}
Expand Down