# Server Configuration

# Basic Configuration

Most backend config can be cofigured in environment variable, which can be set in Settings - Environment Variables for Vercel. Note: all changes works after redeploy.

Environment VariableRequiredDescription
LEAN_IDLeanCloud Application ID
LEAN_KEYLeanCloud Application Key
LEAN_MASTER_KEYLeanCloud Application Master Key
LEAN_SERVERLeanCloud server address if you're leancloud china user
SITE_NAMEsite name
SITE_URLsite url
SECURE_DOMAINSSecure Domains config. Supports multiple domain with Comma separated
DISABLE_USERAGENTwether hide the user agent of commentor. Default value is false
AKISMET_KEYAkismet antispam service key, default is open, set false if you wanna close it.
COMMENT_AUDITComment audit switcher. We recommend to tip on the placeholder text if it's true.

Besides the above environment variables, different features will also its environment variable config, which can be viewed in the corresponding sidebar items.

# Code Config

Except environment variables setting, we also support some config in project file.

# secureDomains

Secure domain settings. Requests from other domain will receive 403 status code. It supports String, Regexp, and Array type. Leaving this config means that all domain referrer are allowed.

// index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  secureDomains: 'waline.js.org',
});
1
2
3
4
5
6

Tip

  • To make local development easy, localhost and 127.0.0.1 will be added to the list of secure domain names by default.
  • Env variable SECURE_DOMAINS won't work when this option is set.

# forbiddenWords

If a comment match forbidden word, it will be marked as spam.

// index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  forbiddenWords: ['Trump'],
});
1
2
3
4
5
6

# disallowIPList

If a comment ip match this list, 403 status code is returned.

// index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  disallowIPList: ['8.8.8.8', '4.4.4.4'],
});
1
2
3
4
5
6

# mailSubject

Customize the title of the comment reply email, which is equivalent to environment variable MAIL_SUBJECT.

# mailTemplate

Customize the content of the comment reply email, which is equivalent to environment variable MAIL_TEMPLATE.

# mailSubjectAdmin

Customize the title of the new comment notification email, which is equivalent to the environment variable MAIL_SUBJECT_ADMIN.

# mailTemplateAdmin

Customize the content of the new comment notification email, which is equivalent to the environment variable MAIL_TEMPLATE_ADMIN.

# QQTemplate

The QQ comment notification template, which is equivalent to the environment variable QQ_TEMPLATE.

# TGTempalte

Telegram comment notification template, which is equivalent to the environment variable TG_TEMPLATE.

# Comment Hooks

Besides environment variable configuration, Waline also provides some custom hooks to facilitate the processing of custom requirements. It only needs to be configured in the server entry file index.js.

# preSave(comment)

The hook will be triggered before comments are posted, and comment data will be passed to params. If the method returns content, the interface will return directly without storing the comment data.

//index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  async preSave(comment) {
    const isSapm = await Akismet.check(comment);
    if (isSpam) {
      return { errmsg: "It's a spam!" };
    }
  },
});
1
2
3
4
5
6
7
8
9
10
11

# postSave(comment, pComment)

The action performed after the comment is posted.

When the method is executed, the comment data will be passed as the first param, and if it's a reply to the comment, the parent comment will be passed as the second param.

// index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  async postSave(comment, pComment) {
    await mailto({
      mail: pComment.mail,
      text: `${comment.nick} replied your comment!`,
    });
  },
});
1
2
3
4
5
6
7
8
9
10
11

# preUpdate(comment)

Action before a comment content is updated in the dashboard. If the method returns content, the interface will return directly without updating the comment data.

//index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  async preUpdate(comment) {
    return "Then you can't update comment data";
  },
});
1
2
3
4
5
6
7
8

# afterUpdate(comment)

Action after a comment content is updated in the dashboard. Comment data will be passed in when the method is executed.

//index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  async postUpdate(comment) {
    console.log(`comment ${comment.objectId} has been updated!`);
  },
});
1
2
3
4
5
6
7
8

# preDelete(commentId)

Action before a comment is deleted. When the method is executed, the comment Id to be operated will be passed in. If the method returns content, the interface will return directly without updating the comment data.

// index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  async preDelete(commentId) {
    return "Then you can't delete comment";
  },
});
1
2
3
4
5
6
7
8

# afterDelete(commentId)

Action after a comment is deleted, the comment Id will be passed as the only param.

// index.js
const Waline = require('@waline/vercel');

module.exports = Waline({
  async postDelete(commentId) {
    console.log(`comment ${commentId} has been deleted!`);
  },
});
1
2
3
4
5
6
7
8