From dd405d11aced74d7198f556bf5f6501fd320adf5 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 23 May 2019 13:19:42 +0200 Subject: [PATCH] dev environment --- api/package.json | 6 ++---- api/src/server.ts | 10 +++------- package.json | 8 ++++++++ www/package.json | 10 ++++------ www/server.js | 4 +++- 5 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 package.json diff --git a/api/package.json b/api/package.json index 804da61..e5e1574 100644 --- a/api/package.json +++ b/api/package.json @@ -1,11 +1,9 @@ { "private": true, "scripts": { - "pkg": "tsc && pkg --targets latest-alpine-x64 --output ./server dist/server.js", - "pkg:mac": "tsc && pkg --targets latest-macos-x64 --output ./server-macos dist/server.js", - "prod": "NODE_ENV=production node dist/server.js", "build": "tsc", - "dev": "npm i && tsnd --no-notify src/server.ts" + "dev": "npm install --silent && tsnd --no-notify src/server.ts", + "prod": "NODE_ENV=production node dist/server.js" }, "devDependencies": { "@types/jsonwebtoken": "^8.3.2", diff --git a/api/src/server.ts b/api/src/server.ts index a49a3a3..2e4dcf6 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -15,12 +15,6 @@ import router from './routes' createConnection({ type: 'sqlite', database: join(process.cwd(), 'db.sqlite'), - // type: "mysql", - // host: "localhost", - // port: 3306, - // username: 'test', - // password: 'test', - // database: 'data', entities: [User, Purchase], synchronize: true, }).then(async () => { @@ -31,7 +25,9 @@ createConnection({ await User.createOrGet(user) } - const port = Config.get('server.port') + const port = process.env.NODE_ENV !== 'production' + ? 5000 + : 80 const server = new Koa() server.use(responseTime) diff --git a/package.json b/package.json new file mode 100644 index 0000000..fe3566c --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "private": true, + "scripts": { + "dev:local": "npm --prefix ./www run dev:local & npm --prefix ./api run dev", + "dev:docker": "docker-compose up", + "clean": "rm -r ./api/node_modules ./api/package-lock.json ./www/node_modules ./www/package-lock.json" + } +} \ No newline at end of file diff --git a/www/package.json b/www/package.json index 8d8d3f3..46316aa 100755 --- a/www/package.json +++ b/www/package.json @@ -1,12 +1,10 @@ { "private": true, - "assets": [ - ".next/**/*" - ], "scripts": { - "dev": "npm i && node server.js", - "prod": "NODE_ENV=production node server.js", - "build": "next build" + "build": "next build", + "dev": "npm install --silent && node server.js", + "dev:local": "npm install --silent && API_HOST=localhost node server.js", + "prod": "NODE_ENV=production node server.js" }, "dependencies": { "axios": "^0.18.0", diff --git a/www/server.js b/www/server.js index db295eb..a902b4c 100755 --- a/www/server.js +++ b/www/server.js @@ -12,7 +12,9 @@ const app = next({ dev }) const handle = app.getRequestHandler() const proxy = httpProxy.createProxyServer() -const target = 'http://api' +const target = dev + ? `http://${process.env.API_HOST || 'api'}:5000` + : 'http://api' app.prepare().then(() => {