I have a web application using vue, built with vue-cli for the front end and wanting to switch to use PM2s static page serve. Everything is working fine but noticed PM2 can also declare the environmental variables for the vue app via the ecosystem.config.js file. Trying to set those in that file, I am not able to get it to work. Specifically, its my vue app api url. It works fine if I keep my .env file in the directory with the same var defined but once I remove that, kill PM2 and restart the app, the app does not work leading me to believe the env variables set in the ecosystem.config.js file is not working.
This is what I currently have in my ecosystem.config.js file -
module.exports = {
"apps" : [{
"name": "AppName",
"script": "serve",
"exec_mode": "cluster",
"instances" : 2,
"env_develop": {
"PM2_SERVE_PATH": 'dist',
"PM2_SERVE_PORT": 8084,
"PM2_SERVE_SPA": 'true',
"PM2_SERVE_HOMEPAGE": '/index.html',
"NODE_ENV": 'develop',
"VUE_APP_API_URL": "http://myappurl.com/api/",
}
}],
"deploy" : {
"develop" : {
"user" : "username",
"key" : "/home/user/.ssh/key.priv",
"host" : "localhost",
"ref" : "origin/develop",
"repo" : "gitrepourl",
"path" : "/home/user/FE",
"pre-deploy-local": "",
"post-deploy" : "npm ci && npm run build && pm2 startOrReload ecosystem.config.js --env develop",
"pre-setup": ""
}
}
}
Any insight on what I may be doing wrong?
Thanks
Related
After eas build can't access to name of channel of build`
"staging": {
"node": "14.21.1",
"channel": "staging",
"distribution": "internal",
"env": {
"APP_ENV": "staging"
}
}
that settings from my eas.json to env which I'm trying to build.
const config = getConfig(process.env.APP_ENV)
`
And I'm trying to get env depend on build, but it doesn't work(process.env.APP_ENV=undefined instead of "staging")
I already tried to get access by Contants
I created a new Vue app using npm init vue#latest and selected Playwright for e2e tests. I removed firefox and webkit from projects in the playwright.config.ts file, so it will only use chromium.
Running npm run test:e2e works fine, the process exists with a success code.
When forcing the tests to fail by modifying the ./e2e/vue.spec.ts file the output is
but the process does not exit with an error code, it still opened browser windows and so CI environments would freeze.
I searched the docs for a specific flag e.g. "headless" and tried --max-failures -x but that didn't help.
How can I tell Playwright to run in headless mode and exit with an error code when something failed?
Since playwright.config.ts already makes use of process.env.CI I thought about replacing reporter: "html", with reporter: [["html", { open: !process.env.CI ? "on-failure" : "never" }]],
but which arguments should I add to the script "test:e2e:ci": "playwright test", to ensure process.env.CI is set?
Update
I tried to run the script inside my CI environment and it seems to work out of the box ( I don't know how it sets the CI environment flag but the pipeline did not freeze )
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Check if e2e tests are passing
run: npm run test:e2e
If any test fails it exists with an error code
It's serving the html report and asking to press 'Ctr+C' to quite.You can disable it using below configuration.
// playwright.config.ts
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
reporter: [ ['html', { open: 'never' }] ],
};
export default config;
Refer - Report Doc
Issue - https://github.com/microsoft/playwright/issues/9702
To add to the answer above, you can set headless: true in the 'use' block of the config which is above the projects block. Anything set at that level will apply to all projects unless you specifically override the setting inside a project specific area:
// playwright.config.ts
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
reporter: [ ['html', { open: 'never' }] ],
use: {
headless: true,
},
projects: [
{
name: 'chromium',
use: {
browserName: 'chromium',
},
},
},
};
export default config;
I want to deploy my create-react-app to Vercel.
I define my redirects in my now.json as follows:
{
"redirects": [
{ "source": "/api/(.*)", "destination": "BACKEND_URL/$1", "statusCode": 200 }
]
}
The destination URL depends on the environment variable BACKEND_URL, which is defined in the Vercel dashboard.
I am trying to replace the environment variable in the redirects in the following build command:
sed -i "s|BACKEND_URL|${BACKEND_URL}|g" now.json && yarn build
But unfortunately now.json doesn't seem to be available at build time:
09:54:44.243 sed: can't read now.json: No such file or directory
How to enable dynamic redirects in Vercel?
This is not possible since now.json is read to determine how to build so you can't dynamically generate it during a build.
Instead, consider using a framework like Next.js which provides a next.config.js that can read environment variables as defined in RFC 9081.
npm install next#canary react react-dom
// next.config.js
module.exports = {
experimental: {
async redirects() {
return [{
source: "/api/:path*",
destination: `${process.env.BACKEND_URL}/:path*`,
permanent: false,
}]
}
}
};
https://github.com/zeit/now/discussions/4351
I think this actually is possible.
If you are using create-react-app then you just need to preface your env var name with REACT_APP_. See here: https://create-react-app.dev/docs/adding-custom-environment-variables/
I am currently doing this with a websocket URL env var. I have named it REACT_APP_WS_URL and here is how I use it.
I have 2 different vercel files in the project:
vercel.staging.json which has this section:
"build": {
"env": {
"REACT_APP_WS_URL": "wss:staging.my-backend.com/socket"
}
}
vercel.live.json which has this section:
"build": {
"env": {
"REACT_APP_WS_URL": "wss:my-backend.com/socket"
}
}
I deploy to them with either of these commands:
vercel deploy --prod -A vercel.staging.json
vercel deploy --prod -A vercel.live.json
and in my code I can access process.env.REACT_APP_WS_URL anywhere.
I have not tried doing this with the Vercel dashboard env vars but it might be worth trying your original approach except rename your env var to REACT_APP_BACKEND_URL.
Note: my deployment commands only work when I don't assign domains to the project. If I assign domains to a project, they are automatically used for ALL --prod deploys, no matter what is in my alias field in the json config file.
I have setup botium project according to direction given in https://chatbotsmagazine.com/5-steps-automated-testing-of-chatbots-in-eclipse-ef4c3dcaf233 and its working fine for single botium.json file.
but when i try to setup multiple connector together ex-
1)botium_dialog.json
{
"botium": {
"Capabilities": {
"PROJECTNAME": "jokes",
"CONTAINERMODE": "dialogflow",
"DIALOGFLOW_PROJECT_ID": "###",
"DIALOGFLOW_CLIENT_EMAIL": "###",
"DIALOGFLOW_PRIVATE_KEY": "###",
"DIALOGFLOW_USE_INTENT": false
}
}
}
2) botium_watson.json
{
"botium": {
"Capabilities": {
"PROJECTNAME": "IBM Watson Conversation Sample",
"SCRIPTING_UTTEXPANSION_MODE": "all",
"SCRIPTING_FORMAT": "xlsx",
"SCRIPTING_XLSX_STARTROW": 2,
"SCRIPTING_XLSX_STARTCOL": 1,
"CONTAINERMODE": "watson",
"WATSON_USER": "#",
"WATSON_PASSWORD": "#",
"WATSON_WORKSPACE_ID": "#"
}
}
}
in the same project but running 1 at a time using
mocha --reporter mochawesome --reporter-options
\"reportDir=reportsDialog,reportFilename=index.html,code=false\"
--convos ./spec/convo/dialog --config botium_dialog.json --exit spec "
its giving error
Error: Capability 'CONTAINERMODE' missing
at BotDriver._getContainer (node_modules\botium-core\src\BotDriver.js:316:13)
at async.series (node_modules\botium-core\src\BotDriver.js:154:30)
The "--convos" and the "--config" command line parameters are actually for the Botium CLI, not for mocha. You either switch your test scripts to Botium CLI, or you configure Botium in a way to use several configuration files and several convo directories. My recommendation would be to pack each section in an own subdirectory - so you have a "botium_dialog" and a "botium_watson" directory, each with it's own package.json, botium.json, spec/convo folders etc.
With some configuration changes, it is also possible to use your current folder structure.
Add multiple botium.spec.js in spec folder:
botium_dialog.spec.js:
const BotiumBindings = require('botium-bindings')
const bb = new BotiumBindings({ convodirs: [ './spec/convo/dialog' ] })
BotiumBindings.helper.mocha().setupMochaTestSuite({ bb })
botium_watson.spec.js:
const BotiumBindings = require('botium-bindings')
const bb = new BotiumBindings({ convodirs: [ './spec/convo/watson' ] })
BotiumBindings.helper.mocha().setupMochaTestSuite({ bb })
Add multiple test scripts to your package.json:
package.json:
...
"scripts": {
"test_dialog": "BOTIUM_CONFIG=botium_dialog.json mocha --reporter spec --exit spec/botium_dialog.spec.js",
"test_watson": "BOTIUM_CONFIG=botium_watson.json mocha --reporter spec --exit spec/botium_watson.spec.js"
}
...
Run both of the test scripts
For example:
npm run test_dialog
npm run test_watson
My pm2 ecosystem.config.js configuration like below:
HGBackend is not running. Others are running in pm2
module.exports = {
apps : [
{
name : "HGBackend",
cwd : "hgbackend/server",
script : "config.json"
},
{
name : "HGBlockchain",
cwd : "hgblockchain/localgrammes",
script : "index.js"
// args : "start:staging"
// instances : 4,
// exec_mode : "cluster"
},
{
name : "HGWeb",
cwd : "hgweb/src/server",
script : "server.js",
description: ""
}
]}
All are working except HGBackend. HGBackend is loopback api. Others are react and express api.
What will be the cause for not running HGBackend? Can anyone help me?
For the HGWeb and HGBlockchain applications, you are executing the relevant server.js in the script configuration. For the HGBackend you are passing the config.json as the script. For Loopback you also need to execute the server.js.
Yes I have corrected is. Actually problem in fatasource.json file. Thanks