node.js - 如何在 AWS 中运行 json-server?
问题描述
我的团队在 AWS 中部署了一个 Angular 应用程序。我们使用 json-server 为应用程序制作模拟服务和数据库。但是,我们找不到在 aws 中运行 json-server 的方法。任何人都可以在这方面帮助我们吗?
这是管道代码-
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-server,则需要运行以下命令:
nohup json-server --watch data/store.json --port
然后您可以使用 curl 来验证 json-server 是否已启动并且可以正确响应请求。
如果要使用低于 1024 的端口,请使用sudo
.
我无法在公网调用api,可能是安全组问题或其他一些权限设置不正确。但我希望这能有所帮助。
推荐阅读
- java - 如何使用嵌入式 tomcat 减少 Spring Boot 应用程序的内存使用?
- javascript - 在 JS 中获取属性值 - 最快的方法
- php - 在 PHP 中同时进行运算符和赋值?
- python - re python - 提取字符串的两个不同部分
- javascript - 流星- npm 版本错误
- python - 使用 GET 与 Python、Flask 和 MongoDB 返回整个集合
- r - 将不同的 data.tables 子集导出到集群中的每个节点
- python - 删除特定的字符集?
- ms-access - 我如何使用 VBA 代码合并多个 pdf 文件
- entity-framework - .Net MVC Linq 查询