Skip to content
Snippets Groups Projects
Commit 2e389f64 authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

- fix redirects (/~witnesses for example)

- fix user.json
- fix post.json
parent c399af78
No related branches found
No related tags found
2 merge requests!354Remove linkify:false from Remarkable call. The option has been removed from...,!353Fix custom KOA middlewares
...@@ -7,12 +7,12 @@ export default function usePostJson(app) { ...@@ -7,12 +7,12 @@ export default function usePostJson(app) {
const router = koa_router(); const router = koa_router();
app.use(router.routes()); app.use(router.routes());
router.get(routeRegex.PostJson, function* () { router.get(routeRegex.PostJson, async (ctx) => {
// validate and build post details in JSON // validate and build post details in JSON
const author = this.url.match(/(@[\w\d.-]+)/)[0].replace('@', ''); const author = ctx.url.match(/(@[\w\d.-]+)/)[0].replace('@', '');
const permalink = this.url.match(/(@[\w\d.-]+)\/?([\w\d-]+)/)[2]; const permalink = ctx.url.match(/(@[\w\d.-]+)\/?([\w\d-]+)/)[2];
let status = ''; let status = '';
let post = yield api.getContentAsync(author, permalink); let post = await api.getContentAsync(author, permalink);
if (GDPRUserList.includes(post.author)) { if (GDPRUserList.includes(post.author)) {
post = 'Content unavailable'; post = 'Content unavailable';
...@@ -30,6 +30,6 @@ export default function usePostJson(app) { ...@@ -30,6 +30,6 @@ export default function usePostJson(app) {
status = '404'; status = '404';
} }
// return response and status code // return response and status code
this.body = { post, status }; ctx.body = { post, status };
}); });
} }
...@@ -7,13 +7,13 @@ export default function useUserJson(app) { ...@@ -7,13 +7,13 @@ export default function useUserJson(app) {
const router = koa_router(); const router = koa_router();
app.use(router.routes()); app.use(router.routes());
router.get(routeRegex.UserJson, function* () { router.get(routeRegex.UserJson, async (ctx) => {
// validate and build user details in JSON // validate and build user details in JSON
const user_name = this.url.match(routeRegex.UserJson)[1].replace('@', ''); const user_name = ctx.url.match(routeRegex.UserJson)[1].replace('@', '');
let user = ''; let user = '';
let status = ''; let status = '';
const [chainAccount] = yield api.getAccountsAsync([user_name]); const [chainAccount] = await api.getAccountsAsync([user_name]);
if (GDPRUserList.includes(user_name)) { if (GDPRUserList.includes(user_name)) {
user = 'Content unavailable'; user = 'Content unavailable';
...@@ -31,6 +31,6 @@ export default function useUserJson(app) { ...@@ -31,6 +31,6 @@ export default function useUserJson(app) {
status = '404'; status = '404';
} }
// return response and status code // return response and status code
this.body = { user, status }; ctx.body = { user, status };
}); });
} }
...@@ -16,13 +16,13 @@ export default function useRedirects(app) { ...@@ -16,13 +16,13 @@ export default function useRedirects(app) {
redirects.forEach((redirectConfig) => { redirects.forEach((redirectConfig) => {
// eslint-disable-next-line require-yield // eslint-disable-next-line require-yield
router.get(redirectConfig[0], function* () { router.get(redirectConfig[0], async (ctx) => {
const dest = Object.keys(this.params).reduce((value, key) => { const dest = Object.keys(ctx.params).reduce((value, key) => {
return value.replace('$' + key, this.params[key]); return value.replace('$' + key, ctx.params[key]);
}, redirectConfig[1]); }, redirectConfig[1]);
console.log(`server redirect: [${redirectConfig[0]}] ${this.request.url} -> ${dest}`); console.log(`server redirect: [${redirectConfig[0]}] ${ctx.request.url} -> ${dest}`);
this.status = redirectConfig[2] || 301; ctx.status = redirectConfig[2] || 301;
this.redirect(dest); ctx.redirect(dest);
}); });
}); });
} }
...@@ -94,6 +94,9 @@ app.use(new csrf({ ...@@ -94,6 +94,9 @@ app.use(new csrf({
})); }));
useGeneralApi(app); useGeneralApi(app);
useRedirects(app);
useUserJson(app);
usePostJson(app);
koaLocale(app); koaLocale(app);
...@@ -269,10 +272,6 @@ if (env !== 'test') { ...@@ -269,10 +272,6 @@ if (env !== 'test') {
}); });
} }
useRedirects(app);
useUserJson(app);
usePostJson(app);
// Logging // Logging
if (env === 'production') { if (env === 'production') {
app.use(prod_logger()); app.use(prod_logger());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment