Node.js 如何在AWS中运行json服务器?
我的团队已经在AWS中部署了Angular应用程序。我们使用json服务器为应用程序创建模拟服务和数据库。但是,我们找不到在aws中运行json服务器的方法。在这方面有人能帮助我们吗 这是管道代码-Node.js 如何在AWS中运行json服务器?,node.js,angular,amazon-web-services,json-server,Node.js,Angular,Amazon Web Services,Json Server,我的团队已经在AWS中部署了Angular应用程序。我们使用json服务器为应用程序创建模拟服务和数据库。但是,我们找不到在aws中运行json服务器的方法。在这方面有人能帮助我们吗 这是管道代码- version: 0.0 os: linux version: 0.2 env: variables: S3_BUCKET: "initial-codedeploy-bucket-us-east-1-jready" APP_NAME: "shopping-c
version: 0.0
os: linux
version: 0.2
env:
variables:
S3_BUCKET: "initial-codedeploy-bucket-us-east-1-jready"
APP_NAME: "shopping-city"
BUILD_ENV : "prod"
phases:
install:
commands:
# Download and Install NodeJS 10.0
- curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
- sudo apt-get install -y nodejs
- echo Installing source NPM dependencies...
# Install http drivers for node
- sudo apt-get update -y
- sudo apt-get install -y apt-transport-https
# Install Yarn Package Manager (Replace the commands below if you using NPM).
# - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
# - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -y
- sudo apt-get install -y npm
# Install Angular CLI, If you are not using Angular 6, install angular/cli@1.7.0 or lower, confirm by running ng -v inside your project folder
- npm global add @angular/cli@6.0.8
# Install node dependancies.
- npm install
build:
commands:
# Builds Angular application. You can also build using custom environment here like mock or staging
- echo Build started on `date`
- ng build --${BUILD_ENV}
post_build:
commands:
# Clear S3 bucket.
- aws s3 rm s3://${S3_BUCKET} --recursive
- echo S3 bucket is cleared.
# Copy dist folder to S3 bucket, As of Angular 6, builds are stored inside an app folder in distribution and not at the root of the dist folder
- aws s3 cp dist s3://${S3_BUCKET}/${APP_NAME} --recursive
- echo Build completed on `date`
artifacts:
files:
- '/'
discard-paths: yes
base-directory: 'dist*'
如果要在AWS EÇ2上运行json服务器,需要运行以下命令:
nohup json-server --watch data/store.json --port
然后,您可以使用curl来验证json服务器是否已启动并能够正确响应请求
如果要使用低于1024的端口,请使用sudo
运行命令
我无法在公网中调用api,可能是安全组问题或其他权限设置不正确。但是我希望这能有所帮助。如果您想在AWS EÇ2上运行json服务器,您需要运行以下命令:
nohup json-server --watch data/store.json --port
然后,您可以使用curl来验证json服务器是否已启动并能够正确响应请求
如果要使用低于1024的端口,请使用sudo
运行命令
我无法在公网中调用api,可能是安全组问题或其他权限设置不正确。但我希望这能有所帮助。您可以将EC2实例与PM2+Nginx一起使用,以获得更好的性能。您可以将EC2实例与PM2+Nginx一起使用,以获得更好的性能。