Skip to content

Commit

Permalink
fixed #813
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jul 26, 2020
1 parent 4cca9cf commit 8a434e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
20 changes: 3 additions & 17 deletions backend/scripts/install-nodejs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,9 @@ touch /tmp/install.lock
# lock
touch /tmp/install-nodejs.lock

# install nvm
BASE_DIR=`dirname $0`
/bin/bash ${BASE_DIR}/install-nvm.sh
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# install Node.js v10.19
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
nvm install 10.19

# create soft links
ln -s $HOME/.nvm/versions/node/v10.19.0/bin/npm /usr/local/bin/npm
ln -s $HOME/.nvm/versions/node/v10.19.0/bin/node /usr/local/bin/node

# environments manipulation
export NODE_PATH=$HOME.nvm/versions/node/v10.19.0/lib/node_modules
export PATH=$NODE_PATH:$PATH
# install node.js
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt install -y nodejs

# install chromium
# See https://crbug.com/795759
Expand Down
5 changes: 1 addition & 4 deletions backend/services/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"runtime/debug"
Expand Down Expand Up @@ -116,9 +115,7 @@ func AssignTask(task model.Task) error {
func SetEnv(cmd *exec.Cmd, envs []model.Env, task model.Task, spider model.Spider) *exec.Cmd {
// 默认把Node.js的全局node_modules加入环境变量
envPath := os.Getenv("PATH")
homePath := os.Getenv("HOME")
nodeVersion := "v10.19.0"
nodePath := path.Join(homePath, ".nvm/versions/node", nodeVersion, "lib/node_modules")
nodePath := "/usr/lib/node_modules"
if !strings.Contains(envPath, nodePath) {
_ = os.Setenv("PATH", nodePath+":"+envPath)
}
Expand Down

0 comments on commit 8a434e0

Please sign in to comment.