浏览代码

Merge pull request #1799 from Akuket/devel

enable/disable api with env var
Lauri Ojansivu 7 年之前
父节点
当前提交
aa080a7506
共有 5 个文件被更改,包括 23 次插入3 次删除
  1. 1 1
      Dockerfile
  2. 1 0
      docker-compose.yml
  3. 12 1
      models/users.js
  4. 5 1
      snap-src/bin/config
  5. 4 0
      snap-src/bin/wekan-help

+ 1 - 1
Dockerfile

@@ -1,5 +1,5 @@
 FROM debian:buster-slim
-MAINTAINER wekan
+LABEL maintainer="wekan"
 
 # Declare Arguments
 ARG NODE_VERSION

+ 1 - 0
docker-compose.yml

@@ -37,6 +37,7 @@ services:
     environment:
       - MONGO_URL=mongodb://wekandb:27017/wekan
       - ROOT_URL=http://localhost
+      - WITH_API=false
     depends_on:
       - wekandb
 

+ 12 - 1
models/users.js

@@ -622,9 +622,20 @@ if (Meteor.isServer) {
   });
 }
 
-
 // USERS REST API
 if (Meteor.isServer) {
+  // Middleware which checks that API is enabled.
+  JsonRoutes.Middleware.use(function (req, res, next) {
+    const api = req.url.search('api');
+    if (api === 1 && process.env.WITH_API === 'true' || api === -1){
+      return next();
+    }
+    else {
+      res.writeHead(301, {Location: '/'});
+      return res.end();
+    }
+  });
+
   JsonRoutes.add('GET', '/api/user', function(req, res) {
     try {
       Authentication.checkLoggedIn(req.userId);

+ 5 - 1
snap-src/bin/config

@@ -3,7 +3,7 @@
 # All supported keys are defined here together with descriptions and default values
 
 # list of supported keys
-keys="MONGODB_BIND_UNIX_SOCKET MONGODB_BIND_IP MONGODB_PORT MAIL_URL MAIL_FROM ROOT_URL PORT DISABLE_MONGODB CADDY_ENABLED CADDY_BIND_PORT"
+keys="MONGODB_BIND_UNIX_SOCKET MONGODB_BIND_IP MONGODB_PORT MAIL_URL MAIL_FROM ROOT_URL PORT DISABLE_MONGODB CADDY_ENABLED CADDY_BIND_PORT WITH_API"
 
 # default values
 DESCRIPTION_MONGODB_BIND_UNIX_SOCKET="mongodb binding unix socket:\n"\
@@ -47,3 +47,7 @@ KEY_CADDY_ENABLED="caddy-enabled"
 DESCRIPTION_CADDY_BIND_PORT="Port on which caddy will expect proxy, value set here will be set in $SNAP_COMMON/Caddyfile"
 DEFAULT_CADDY_BIND_PORT="3001"
 KEY_CADDY_BIND_PORT="caddy-bind-port"
+
+DESCRIPTION_WITH_API="Enable/disable the api of wekan"
+DEFAULT_WITH_API="false"
+KEY_WITH_API="with-api"

+ 4 - 0
snap-src/bin/wekan-help

@@ -28,6 +28,10 @@ echo -e "\t\t-connect mongodb-plug with slot from snap providing mongodb"
 echo -e "\t\t-disable mongodb in $SNAP_NAME by calling: $ snap set $SNAP_NAME set disable-mongodb='true'"
 echo -e "\t\t-set mongodb-bind-unix-socket to point to serving mongodb. Use relative path inside shared directory, e.g run/mongodb-27017.sock"
 echo -e "\n"
+echo -e "To enable the API of wekan:"
+echo -e "\t$ snap set $SNAP_NAME WITH_API='true'"
+echo -e "\t-Disable the API:"
+echo -e "\t$ snap set $SNAP_NAME WITH_API='false'"
 # parse config file for supported settings keys
 echo -e "wekan supports settings keys"
 echo -e "values can be changed by calling\n$ snap set $SNAP_NAME <key name>='<key value>'"