Server Config

About 4 min...

Environment Variables

You can configure the Waline server through the following environment variables.

Note

You MUST redeploy after updating Environment variables to take effect.

Vercel needs to be set in Settings - Environment Variables.

Basic

Environment VariablesRequiredDescription
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
DISABLE_REGIONwether hide commentor's region. Default value is false
DISABLE_AUTHOR_NOTIFYwether disable author notification
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.
LOGINUser need login before comment when LOGIN=force
AVATAR_PROXYAvatar proxy service url, default is https://avatar.75cdn.workers.dev. You can set false to close it
GRAVATAR_STRGravatar render string,default is https://seccdn.libravatar.org/avatar/{{mail|md5}},base on nunjucks template
OAUTH_URLOAuth Social Login Service URL,default is https://oauth.lithub.cc. Also you can custom build with authopen in new window.
WEBHOOKYou can set a Webhook URL that will be triggered when you have new comment.
LEVELSGive each user a rating label based on the number of comments

Markdown

Environment VariablesDescription
MARKDOWN_CONFIGMarkdownIt Config
MARKDOWN_HIGHLIGHTWhether enable highlight, enable by default
MARKDOWN_EMOJIWhether enable emoji, enable by default
MARKDOWN_SUBWhether enable subscript, enable by default
MARKDOWN_SUPWhether enable superscript, enable by default
MARKDOWN_TEXService to parse math, 'mathjax' by default (also can be false | 'katex')
MARKDOWN_MATHJAXMathJax Options
MARKDOWN_KATEXKatex Options

Level Label

According to the set rating conditions and the number of user comments, a level label will be added to the commenter. This feature is disabled by default and can be enabled by configuring the environment variable LEVELS. The configuration is in the form of a comma concatenation of a given number, for example 0,10,20,50,100,200 means:

GradesConditionsDefault Grade Labels
00 <= count < 10Dwarves
110 <= count < 20Hobbits
220 <= count < 50Ents
350 <= count < 100Wizards
4100 <= count < 200Elves
5200 <= countMaiar

In addition to customizing the level judgment rules, we can also customize the level label. Configure the text in the client as follows:

new Waline({
  locale: {
    level0: 'Dwarves',
    level1: 'Hobbits',
    level2: 'Ents',
    level3: 'Wizards',
    level4: 'Elves',
    level5: 'Maiar',
  },
});

By default, only 6 levels of copywriting are provided, but it does not mean that there can only be 6 levels. The specific level cap is based on the level judgment rules you set. To add a new level, it is recommended to configure the label text corresponding to the level by yourself. If no label text is provided, the default label text such as Level 10 will be displayed by default.

Database

  • MongoDB:

    Environment VariableRequiredDefaultDescription
    MONGO_HOST127.0.0.1MongoDB server address, support array format
    MONGO_PORT27017MongoDB server port, support array format
    MONGO_DBMongoDB database name
    MONGO_USERMongoDB server username
    MONGO_PASSWORDMongoDB server password
    MONGO_REPLICASETMongoDB replica set
    MONGO_AUTHSOURCEMongoDB auth source
    MONGO_OPT_SSLuse SSL connection
  • MySQL:

    Environment VariableRequiredDefaultDescription
    MYSQL_HOST127.0.0.1MySQL server address
    MYSQL_PORT3306MySQL server port
    MYSQL_DBMySQL database name
    MYSQL_USERMySQL server username
    MYSQL_PASSWORDMySQL server password
    MYSQL_PREFIXwl_MySQL table prefix
    MYSQL_CHARSETutf8mb4MySQL table charset
  • SQLite:

    Environment VariableRequiredDefaultDescription
    SQLITE_PATHSQLite storage file path, not include file name
    SQLITE_DBwalineSQLite storage file name, change it if your filenamed is not waline
    SQLITE_PREFIXwl_SQLite table prefix
    JWT_TOKENRandom String for login token generator
  • PostgreSQL:

    Environment VariableRequiredDefaultDescription
    PG_HOST127.0.0.1PostgreSQL server address
    PG_PORT3211PostgreSQL server port
    PG_DBPostgreSQL database name
    PG_USERPostgreSQL server username
    PG_PASSWORDPostgreSQL server password
    PG_PREFIXwl_PostgreSQL table prefix
  • GitHub:

    Environment VariableRequiredDefaultDescription
    GITHUB_TOKENPersonal access tokensopen in new window
    GITHUB_REPOrepository name, such as walinejs/waline
    GITHUB_PATHThe data storage directory, such as data means it is stored in the data directory, root directory by default

Main entrance

The following options need to be configured in the server entry file index.js.

Note

If you are using template, please note that you need to save these configurations yourself, because they will be overwritten when you pull the latest official template.

secureDomains

  • Type: string | RegExp | string[] | RegExp[]

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.

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

module.exports = Waline({
  secureDomains: 'waline.js.org',
});

Tips

  • To make local development easier, 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

  • Type: string[]

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

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

module.exports = Waline({
  forbiddenWords: ['Trump'],
});

disallowIPList

  • Type: string[]

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

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

module.exports = Waline({
  disallowIPList: ['8.8.8.8', '4.4.4.4'],
});

mailSubject

  • Type: string

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

mailTemplate

  • Type: string

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

mailSubjectAdmin

  • Type: string

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

mailTemplateAdmin

  • Type: string

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

QQTemplate

  • Type: string

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

TGTempalte

  • Type: string

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)

Waline provides some custom hooks to let users customize Waline server behavior according to their own needs.

Example
// 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!" };
    }
  },
});

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.

Example
// 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!`,
    });
  },
});

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.

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

module.exports = Waline({
  async preUpdate(comment) {
    return "Then you can't update comment data";
  },
});

afterUpdate(comment)

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

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

module.exports = Waline({
  async postUpdate(comment) {
    console.log(`comment ${comment.objectId} has been updated!`);
  },
});

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.

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

module.exports = Waline({
  async preDelete(commentId) {
    return "Then you can't delete comment";
  },
});

afterDelete(commentId)

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

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

module.exports = Waline({
  async postDelete(commentId) {
    console.log(`comment ${commentId} has been deleted!`);
  },
});
TIPS: The comment area is only for demo. If you have any questions, please go to Github Discussion to ask.
Comments
Powered by Waline v2.6.1