I would like to do a Hot-Deployment of the Front-End-Code (HTML, CSS, JS) of some Portlet so development time can be saved and not the whole Portlet needs to be redeployed.
The Portlet is a .war File.
In the good old Liferay 6.2 this was simply possible by overwriting the static frontend Code in the tomcat/webapps/portlet-name directory.
In Liferay DXP this is no longer possible, since the Portlet is not extracted to tomcat/webapps/ anymore.
Is there any possibility for a frontend-Hot-Deploy, so i can change e.g. my .html file on the fly and I don't have to redeploy the whole .war Portlet?
Apart from the described method being really bad practice for maintenance, I'm wondering how much time you actually save (as you say that this is your motivation).
You can always implement your portlet to include various resources from places outside of Liferay's control, but naturally, the provided tools won't help you keeping everything in sync - that'll be your personal problem to solve.
By the way: Tomcat's mode, in which you are able to just replace random content in the webapps directory, is called development mode.
We found an alternative solution to improve our time for frontend development, but it works completly different as it did in the old Liferay 6.2.
Basically we use an express.js proxy Server, which runs in parallel to Liferay on some different Port. This Proxy Server forwards all the requests to the other running liferay, except the requests for HTML, CSS and JS Files. Those are directly served from the local file System instead. Also an automatic rebuild of the frontend is triggered when a HTML, CSS or JS File is changed and saved.
This small Proxy-Server consists basically out of those two Files:
The dev-server.js File:
const packageConfig = require('../../../package.json');
const projectName = packageConfig.name;
const config = Object.assign({}, {
port: 8088,
liferayUrl: 'http://localhost:8080',
liferayVersion: 7,
webpackConfigFile: './webpack.development.config.js',
}, packageConfig.devServer || {});
const path = require('path');
const webpack = require('webpack');
const middleware = require('webpack-dev-middleware');
const webpackCompiler = webpack(require(config.webpackConfigFile));
const express = require('express');
const app = express();
const httpProxy = require('http-proxy');
const liferayProxy = httpProxy.createProxyServer();
let publicPath = `/o/${projectName}/static/js/`;
if(config.liferayVersion === 6) {
publicPath = `/${projectName}/static/js/`
}
app.use(
middleware(webpackCompiler, {
publicPath: `/o/${projectName}/static/js/`
})
);
app.all('/*', function(req, res) {
liferayProxy.web(req, res, {target: config.liferayUrl});
});
app.listen(config.port, () => console.log('Development server listening on port ' + config.port + '!'));
And the package.json:
{
"name": "react-base",
"version": "1.0.0",
"license": "NOLICENSE",
"private": true,
"scripts": {
"preinstall": "node ./target/ui-build/build/preInstallHook.js",
"build-dev": "gulp --gulpfile ./target/ui-build/build/gulpfile.js && webpack --config ./target/ui-build/build/webpack.development.config.js --progress --profile",
"build": "gulp --gulpfile ./target/ui-build/build/gulpfile.js production && webpack --config ./target/ui-build/build/webpack.production.config.js --bail",
"lint": "eslint -c ./target/ui-build/build/.eslintrc.js --rulesdir \"node_modules/#myproject/react-component-lib/eslint-rules/\" \"src/main/react/**/*.js\" ",
"test": "jest --config=./target/ui-build/build/jest.config.js --rootDir=./ --passWithNoTests",
"coverage": "jest --config=./target/ui-build/build/jest.config.js --rootDir=./ --passWithNoTests --coverage",
"stats": "webpack-bundle-analyzer ./target/generated-sources/js/stats.json",
"start:dev": "node ./target/ui-build/build/dev-server.js"
},
"dependencies": {
"#babel/runtime": "^7.0.0",
"mobx": "3.1.16",
"mobx-react": "4.4.3",
"prop-types": "15.7.2",
"react": "16.8.4",
"react-dom": "16.8.4"
},
"devDependencies": {
"autoprefixer": "^9.1.5",
"babel-core": "^7.0.0-bridge.0",
"#babel/core": "7.1.0",
"babel-eslint": "10.0.1",
"babel-jest": "^23.0.0",
"babel-loader": "8.0.4",
"#babel/plugin-proposal-class-properties": "7.1.0",
"#babel/plugin-proposal-decorators": "7.1.0",
"#babel/plugin-proposal-object-rest-spread": "7.0.0",
"#babel/plugin-transform-runtime": "7.1.0",
"#babel/preset-env": "7.1.0",
"#babel/preset-react": "7.0.0",
"css-loader": "1.0.0",
"enzyme": "3.4.0",
"enzyme-adapter-react-16": "1.5.0",
"eslint": "4.19.1",
"eslint-plugin-jsx-a11y": "6.0.3",
"eslint-plugin-react": "7.11.1",
"express": "4.17.1",
"file-loader": "2.0.0",
"fs-extra": "7.0.0",
"gulp": "3.9.1",
"gulp-concat": "2.6.1",
"http-proxy": "1.17.0",
"identity-obj-proxy": "3.0.0",
"jest": "^23.0.0",
"jest-cli": "^23.0.0",
"node-sass": "4.9.3",
"postcss-loader": "3.0.0",
"raf": "3.4.1",
"react-test-renderer": "16.8.4",
"run-sequence": "1.2.2",
"sass-loader": "7.1.0",
"style-loader": "0.23.1",
"url-loader": "1.1.2",
"url-search-params-polyfill": "5.0.0",
"webpack": "4.20.2",
"webpack-bundle-analyzer": "^3.0.2",
"webpack-cli": "^3.1.1",
"webpack-dev-middleware": "3.7.0"
},
"sideEffects": [
"*.css",
"*.scss"
]
}
The Proxy-Server can be started by calling 'yarn run start:dev', then you can access Liferay over the Proxy-Server via http://localhost:8088
Related
I have successfully deployed my angular app onto Heroku. I have implemented the proxy.conf.json file to connect to the Backend API (which is also deployed in Heroku and its a Java JAX-RS REST API) and it is up and running.
The proxy.conf.json file contains:
{
"/webapi/*": {
"target": "https://backend-api.herokuapp.com",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
} }
Also updated the start command in the package.json file as
"start": "ng serve --proxy-config proxy.config.json"
This is working perfectly fine in local using localhost:4200
But when I am deploying the project onto heroku, the backend call is not being held.
for your reference i am attaching the complete package.jsonfile
{
"name": "myapp-client",
"version": "0.0.0",
"scripts": {
"heroku-postbuild": "ng build --aot --prod",
"ng": "ng",
"start": "npm run build & concurrently --kill-others \"npm run serve-api\" \"npm run serve\"",
"serve": "ng serve --proxy-config proxy.config.json",
"build": "ng build",
"serve-api": "node server.js",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"engines": {
"node": "14.8.0",
"npm": "6.14.7"
},
"private": true,
"dependencies": {
"#angular-devkit/build-angular": "^0.1000.6",
"#angular/animations": "~10.0.9",
"#angular/cli": "^10.0.6",
"#angular/common": "~10.0.9",
"#angular/compiler": "~10.0.9",
"#angular/compiler-cli": "^10.0.9",
"#angular/core": "~10.0.9",
"#angular/forms": "~10.0.9",
"#angular/platform-browser": "~10.0.9",
"#angular/platform-browser-dynamic": "~10.0.9",
"#angular/router": "~10.0.9",
"awesome-typescript-loader": "^5.2.1",
"bootstrap": "^4.5.2",
"concurrently": "^5.3.0",
"cors": "^2.8.5",
"d3": "^3.5.17",
"express": "^4.17.1",
"file-saver": "^2.0.2",
"font-awesome": "^4.7.0",
"jquery": "^3.5.1",
"ng2-nvd3": "^2.0.0",
"nvd3": "^1.8.6",
"popper.js": "^1.16.1",
"rxjs": "~6.6.2",
"source-map-loader": "^1.0.1",
"tslib": "^1.10.0",
"typescript": "~3.9.7",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.1000.6",
"#angular/router": "~10.0.9",
"#types/jasmine": "^3.5.12",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.12.54",
"codelyzer": "^5.1.2",
"concurrently": "^5.3.0",
"install": "^0.13.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "^6.1.3"
},
"description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.9.",
"main": "karma.conf.js",
"repository": {
"type": "git",
"url": "git+https://gitlab.com/myapp_tool/myapp-client.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gitlab.com/myapp_tool/myapp-client/issues"
},
"homepage": "https://gitlab.com/myapp_tool/myapp-client#readme"
}
And the server.js file contains:
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
var cors = require('cors');
const app = express();
var corsOptions = {
origin: 'https://backend-api.herokuapp.com',
optionsSuccessStatus: 200
}
//app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname + '/dist/myapp-client')));
//app.use('/webapi',api);
app.get('/webapi', cors(corsOptions), function (req, res, next) {
res.json({msg: 'This is CORS-enabled for Java API!'})
});
app.get('*', (req,res) => {
res.sendFile(path.join(__dirname+'/dist/myapp-client/index.html'));});
//app.get('*', function (req,res) {
//res.sendFile('index.html', {root: '/dist/myapp-client'}));});
//const port = process.env.PORT || '8080';
//app.set('port',port);
//const server = http.createServer(app);
app.listen(process.env.PORT || 8080, function (){
console.log('CORS-enabled API is running on Port:${process.env.PORT || 8080}')
});
The deployed angular app works fine till its having static pages. but when it needs to access the backend-api it is unable to do so.
Like when I want to login and send the userid and password; the request should go like following:
https://myapp-client.herokuapp.com/login ==>> https://backend-api.herokuapp.com/webapi/login
But in the browser console i found that it is actually sending request to:
https://myapp-client.herokuapp.com/webapi/login
The angular app is unable to read the backend-api address; instead adds the rest of the path with it self(can't figure out why????).
I am unable to find any other method apart from proxy.conf.json and cors for dynamic backend api call.
Sorry guys for the long post. But i am unable to find any helpful material from anymore, hence I have explained all the things in more detail. Can anyone please help, I have a deadline hanging on me. Thanks in advance for any help.
Try adding path rewrite property in your proxy configuration like this -
{
context: '/webapi',
pathRewrite: { '^/webapi': '' },
target: "https://backend-api.herokuapp.com",
secure: false,
logLevel: "debug",
changeOrigin: true
}
Hope this might help!
I can't figure out how to get my react app (created with create-react-app) to work when deploying to heroku.
Without heroku everything works fine. I use npm start which uses react-scripts start to start the react app and everything works locally as expected.
Now that I want the app to run on heroku I have to use express to serve it's content to the client. I tried this but sadly my browser stays blank. Just a white screen, nothing else. Not even error messages?! Neither in the console nor in the browser's console.
My server's structure looks like this:
public
favicon.ico
index.html
manifest.json
etc...
src
App.css
App.js
index.css
index.js
etc...
package-lock.json
package.json
Procfile
server.js
Here is my server.js file:
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'src')));
app.get('/', (req, res) => {
res.sendFile(path.join(publicPath, 'index.html'));
});
app.listen(port, () => {
console.log('Server is running on port ' + port);
});
Is there any mistake in the file? Or do I maybe use a wrong method to start the server?
I've seen people using node server.js, some run node server.js in one terminal and npm start in another terminal. And some others run just npm start but changed the start script in the package.json to node server.js. I think I am confused at this point. What's the difference between all those commands?
And what could I do to solve the problem? Can anyone help me? Or do you need any additional code insights to help me?
My server.js
const express = require('express');
const http = require('http');
const path = require('path');
let app = express();
app.use(express.static(path.join(__dirname, 'build')));
const port = process.env.PORT || '8080';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Running on :${port}`));
My Procfile as per heroku:
web: node server.js
Please note that you should have build folder where the production would be picked up by heroku. In addition package.json.
My package.json
{
"name": "my-app",
"version": "3.0.1",
"main": "index.js",
"license": "MIT",
"dependencies": {
"#amcharts/amcharts4": "^4.0.3",
"#amcharts/amcharts4-geodata": "^4.0.27",
"#babel/runtime": "7.0.0-beta.55",
"#date-io/moment": "^1.1.0",
"#material-ui/core": "^3.8.1",
"#material-ui/icons": "^3.0.1",
"array-move": "^1.0.0",
"autosuggest-highlight": "^3.1.1",
"axios": "^0.18.0",
"babel-preset-stage-2": "^6.24.1",
"bootstrap": "^4.1.3",
"bootstrap-v4-rtl": "^4.1.1-0",
"can-use-dom": "^0.1.0",
"chart.js": "^2.7.3",
"classnames": "^2.2.6",
"connected-react-router": "^6.2.1",
"cross-env": "^5.2.0",
"downshift": "^3.1.5",
"draft-js": "^0.10.5",
"draftjs-to-html": "^0.8.4",
"email-regex": "^3.0.0",
"express": "^4.17.1",
"history": "^4.7.2",
"install": "^0.10.1",
"isomorphic-fetch": "^2.2.1",
"jss-rtl": "^0.2.3",
"jwt-decode": "^2.2.0",
"luhn": "^2.3.0",
"material-ui-pickers": "^2.0.1",
"moment": "^2.22.2",
"node-sass": "^4.10.0",
"node_env": "^0.0.3",
"nprogress": "^0.2.0",
"package.json": "^2.0.1",
"path": "^0.12.7",
"prop-types": "^15.6.2",
"query-string": "^6.4.0",
"react": "^16.6.3",
"react-autosuggest": "^9.4.2",
"react-big-calendar": "^0.20.2",
"react-bootstrap-sweetalert": "^4.4.1",
"react-chartjs-2": "^2.7.4",
"react-circular-progressbar": "^1.0.0",
"react-ckeditor-component": "^1.1.0",
"react-color": "^2.17.0",
"react-custom-scrollbars": "^4.2.1",
"react-d3-speedometer": "^0.4.2",
"react-device-detect": "^1.6.1",
"react-dnd": "^6.0.0",
"react-dnd-html5-backend": "^6.0.0",
"react-dom": "^16.6.3",
"react-draft-wysiwyg": "^1.12.13",
"react-dropzone": "^4.2.9",
"react-google-maps": "^9.4.5",
"react-hot-loader": "^4.3.12",
"react-icons": "^3.2.2",
"react-intl": "^2.7.2",
"react-joyride": "^1.11.4",
"react-jss": "^8.6.1",
"react-jvectormap": "^0.0.4",
"react-loadable": "^5.5.0",
"react-notifications": "^1.4.3",
"react-number-format": "^4.0.4",
"react-paypal-express-checkout": "^1.0.5",
"react-placeholder": "^3.0.1",
"react-redux": "^6.0.0",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-select": "^2.1.1",
"react-simple-maps": "^0.12.1",
"react-slick": "^0.23.1",
"react-sortable-hoc": "^0.8.3",
"react-star-rating-component": "^1.4.1",
"react-swipeable-views": "^0.13.0",
"react-text-mask": "^5.4.3",
"reactstrap": "^6.5.0",
"recharts": "^1.3.6",
"recompose": "^0.30.0",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-persist": "^5.10.0",
"redux-saga": "^0.16.2",
"save": "^2.3.2",
"slick-carousel": "^1.8.1",
"typeface-roboto": "^0.0.54",
"underscore": "^1.9.1",
"url-search-params": "^1.1.0"
},
"scripts": {
"start": "cross-env NODE_PATH=src react-scripts start",
"build": "cross-env NODE_PATH=src react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"devDependencies": {
"bootstrap": "^4.1.3",
"node-sass": "^4.9.3",
"prettier": "^1.14.2",
"react-scripts": "2.1.1"
},
"browserslist": {
"development": [
"last 2 chrome versions",
"last 2 firefox versions",
"last 2 edge versions"
],
"production": [
">0.25%",
"not op_mini all",
"ie 11"
]
},
"engines": {
"node": ">=6.9.0",
"npm": ">= 3"
}
}
Heroku will run npm run build by default when deploying. In your case this is react-scripts build. This script will bundle your code into a build folder.
Express
This means that your Express middleware should serve static files from your build folder instead of your src folder.
app.use(express.static(path.join(__dirname, 'src')));
should be:
app.use(express.static(path.join(__dirname, 'build')));
(Note: I suggest using an environment variable for this process.env.STATIC_DIR or something similar. This way you can easily switch between src for local development and build for production code and deployment.)
Procfile
Your procfile states which command Heroku should run after deploying your code. Knowing that Heroku runs npm run build you should serve your bundle instead of your source code.
You can do this by changing your procfile like this:
web:npm start
Should be:
web:node server.js
This will run your server.js file which serves your static content from the build folder.
(Note: npm run start is just for local development. When deploying your web app you should only deploy production code.)
(Note: You can test your production build locally by running npm run build to bundle your code and node server.js to serve it.)
Yeah, create-react-app doesn't play nicely with Node.
This is what I did to fix my deployment.
tl;dr :
Since you created the react app with create-react-app you need to use a different buildpack such as: github.com/mars/create-react-app-buildpack.git
An example workflow taken from Heroku's docs:
# You probably did this already
# Create the App
npm install -g create-react-app
create-react-app my-app
cd my-app
git init
# Then you worked on your app
# Now, create the app in heroku with this buildpack...
heroku create -b https://github.com/mars/create-react-app-buildpack.git
# ...or add the buildpack in Heroku's dashboard
# Add the files the buildpack bundled for you and deploy
git add .
git commit -m "react-create-app on Heroku"
git push heroku master
# To see your app
heroku open
The Procfile (in the root directory) should contain the following:
web: bin/boot
Once that's in heroku's repo, you can use the CLI to start the web dyno
heroku ps:scale web=1:free
You can delete your server.js file at this point:
More info here: https://github.com/mars/create-react-app-buildpack#usage
Hope this helps. Cheers!
I need to run a script every time I use the ng serve command, I'm preparing I server to receive POST from an API. My question is if when I run firebase deploy from the /dist folder, it will start this server so I get POST from an API in my application.
Below is the file I need to run via localhost with command ng serve within Firebase Hosting when running firebase deploy command.
In my angular.json file I tried as follows:
"assets": [
"src/favicon.ico",
"src/assets",
"src/server-api/server.js"
],
At the moment I'm only able to execute by setting a script through package.json.
"scripts": {
"app-main": "ng build && node ./server-api/server.js",
}
server.js:
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
// Get our API routes
const api = require('./routes/api');
const app = express();
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
// Set our api routes
app.use('/api', api);
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));
api.js:
const express = require('express');
const router = express.Router();
const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");
firebase.initializeApp({
apiKey: "myapikey",
authDomain: "myapp-30d6b.firebaseapp.com",
projectId: "myapp-30d6b",
});
// Initialize Cloud Firestore through Firebase
var db = firebase.firestore();
router.post('/notifications', (req, res) => {
res.status(201).json({
notification: req.body
});
db.collection("notifications").add(req.body)
.then(function (docRef) {
console.log("Success: ", docRef.id);
})
.catch(function (error) {
console.error("Error", error);
});
});
module.exports = router;
package.json:
{
"name": "myapp",
"version": "1.0.0",
"scripts": {
"app-main": "ng build && node server.js",
"ng": "ng",
"start": "ng serve --open",
"start-hmr": "ng serve --configuration hmr -sm=false",
"start-hmr-sourcemaps": "ng serve --hmr -e=hmr",
"build": "node --max_old_space_size=6144 ./node_modules/#angular/cli/bin/ng build --dev",
"build-stats": "node --max_old_space_size=6144 ./node_modules/#angular/cli/bin/ng build --dev --stats-json",
"build-prod": "node --max_old_space_size=6144 ./node_modules/#angular/cli/bin/ng build --prod",
"build-prod-stats": "node --max_old_space_size=6144 ./node_modules/#angular/cli/bin/ng build --prod --stats-json",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"bundle-report": "webpack-bundle-analyzer dist/stats.json"
},
"private": true,
"dependencies": {
"#agm/core": "1.0.0-beta.2",
"#angular/animations": "6.0.0",
"#angular/cdk": "6.0.1",
"#angular/common": "6.0.0",
"#angular/compiler": "6.0.0",
"#angular/core": "6.0.0",
"#angular/flex-layout": "6.0.0-beta.15",
"#angular/forms": "6.0.0",
"#angular/http": "6.0.0",
"#angular/material": "6.0.1",
"#angular/material-moment-adapter": "6.0.1",
"#angular/platform-browser": "6.0.0",
"#angular/platform-browser-dynamic": "6.0.0",
"#angular/router": "6.0.0",
"#ngrx/effects": "6.0.0-beta.1",
"#ngrx/router-store": "6.0.0-beta.1",
"#ngrx/store": "6.0.0-beta.1",
"#ngrx/store-devtools": "6.0.0-beta.1",
"#ngx-translate/core": "10.0.1",
"#swimlane/ngx-charts": "8.0.0",
"#swimlane/ngx-datatable": "12.0.0",
"#swimlane/ngx-dnd": "4.0.0",
"#types/prismjs": "1.9.0",
"angular-calendar": "0.24.0",
"angular-in-memory-web-api": "0.6.0",
"angularfire2": "5.0.0-rc.9",
"body-parser": "1.18.3",
"chart.js": "2.7.2",
"classlist.js": "1.1.20150312",
"core-js": "2.5.6",
"creditcard.js": "2.1.3",
"d3": "5.2.0",
"express": "4.16.3",
"firebase": "5.0.3",
"firebase-admin": "5.12.1",
"font-awesome": "4.7.0",
"hammerjs": "2.0.8",
"lodash": "4.17.10",
"moment": "2.22.1",
"ng2-charts": "1.6.0",
"ng2-currency-mask": "5.3.1",
"ngrx-store-freeze": "0.2.2",
"ngx-color-picker": "6.0.0",
"ngx-cookie-service": "1.0.10",
"ngx-mask": "2.7.3",
"ngx-toastr": "8.6.0",
"perfect-scrollbar": "1.3.0",
"prismjs": "1.14.0",
"rxjs": "6.1.0",
"rxjs-compat": "6.1.0",
"typescript": "2.7.2",
"web-animations-js": "2.3.1",
"zone.js": "0.8.26"
},
"devDependencies": {
"#angular-devkit/build-angular": "0.6.0",
"#angular/cli": "6.0.3",
"#angular/compiler-cli": "6.0.0",
"#angular/language-service": "6.0.0",
"#angularclass/hmr": "2.1.3",
"#types/jasmine": "2.8.7",
"#types/jasminewd2": "2.0.3",
"#types/lodash": "4.14.108",
"#types/node": "8.9.5",
"codelyzer": "4.2.1",
"jasmine-core": "2.99.1",
"jasmine-spec-reporter": "4.2.1",
"karma": "1.7.1",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "1.4.2",
"karma-jasmine": "1.1.2",
"karma-jasmine-html-reporter": "0.2.2",
"protractor": "5.3.1",
"ts-node": "5.0.1",
"tslint": "5.9.1",
"webpack-bundle-analyzer": "2.11.1"
}
}
The solution I'm looking for:
I need it to work when I run ng serve or else when my application is hosted on Firebase Hosting through the firebase deploy command.
That way I can receive POST in my Angular application.
you can use the pre/post hooks for npm explained here:
http://www.marcusoft.net/2015/08/pre-and-post-hooks-for-npm-scripting.html#hooks-pre-and-post
try adding these 2 scripts to your package.json and then run npm run server:dev
"preserver:dev": "node ./server-api/server.js",
"server:dev": "ng serve --configuration=dev",
;) I created my portfolio with NodeJs and VueJS , it works perfectly in local and I would like to deploy my website in online with heroku. But i follow instructions and finally I have the message " application error ".
I don't understand !
So this is my code :
index.js in folder config
'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
},
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}
package.json :
{
"name": "app",
"version": "1.0.0",
"description": "Portfolio",
"author": "Alex Salicki <salicki.alex#gmail.com>",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js"
},
"dependencies": {
"ev-emitter": "^1.1.1",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"gsap": "^1.20.4",
"html-webpack-plugin": "^2.30.1",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"scrollmagic": "^2.0.5",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
I add too the file " procfile " with the code : " web : node index.js " for heroku application
You can see my complete code in GitHub : https://github.com/Alexsalicki91/website/tree/master/portfolio-1/spa
Can you help me ? Where is my errors ?
Have a nice days guys !
Alex Salicki
Hi is there anyone who has tried to deploy nuxt app to Google App Engine. I have tried from nuxt regular and express template, it shows 502 Bad Gateway. I don't modify anything from create-nuxt-app command. My app.yaml file contains
runtime: nodejs
env: flex
Is there anything wrong with my setup or maybe there are some additional setup I have to do?
Here is my package.json
{
"name": "nuxt-pwa-vuetify-starter",
"version": "1.0.0",
"description": "Nuxt.js + PWA + Vuetify.js starter project",
"author": "Jefry Dewangga <jefrydco#gmail.com>",
"private": true,
"homepage": "https://github.com/jefrydco/nuxt-pwa-vuetify-starter#readme",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/jefrydco/nuxt-pwa-vuetify-starter"
},
"keywords": [
"nuxt",
"nuxt.js",
"nuxtjs",
"nuxt pwa",
"vue",
"vue.js",
"vuejs",
"vue universal",
"vue ssr",
"vue pwa",
"vuetify",
"vuetify.js",
"vuetifyjs"
],
"engines": {
"node": ">=8.0.0",
"npm": ">=5.0.0"
},
"scripts": {
"dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
"build": "nuxt build",
"prestart": "npm run build",
"start": "cross-env NODE_ENV=production node server/index.js",
"generate": "nuxt generate"
},
"dependencies": {
"#nuxtjs/axios": "^5.0.1",
"#nuxtjs/browserconfig": "0.0.7",
"#nuxtjs/component-cache": "^1.1.1",
"#nuxtjs/dotenv": "^1.1.0",
"#nuxtjs/google-analytics": "^2.0.2",
"#nuxtjs/pwa": "^2.0.5",
"#nuxtjs/sentry": "^1.0.1",
"#nuxtjs/sitemap": "0.0.3",
"babel-plugin-transform-imports": "^1.4.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"babel-runtime": "^6.26.0",
"cross-env": "^5.1.3",
"express": "^4.16.2",
"morgan": "^1.9.0",
"node-sass": "^4.7.2",
"nodemon": "^1.17.1",
"nuxt": "^1.3.0",
"pug": "^2.0.0-rc.4",
"sass-loader": "^6.0.7",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"vuetify": "^1.0.3"
},
"devDependencies": {
"babel-eslint": "^8.2.2",
"eslint": "^4.18.1",
"eslint-config-standard": "^10.2.1",
"eslint-loader": "^1.9.0",
"eslint-plugin-html": "^4.0.2",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1"
}
}
and here is my app server index.js,
const express = require('express')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 8080
app.set('port', port)
// Import and Set Nuxt.js options
let config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
async function start () {
// Init Nuxt.js
const nuxt = new Nuxt(config)
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// Listen the server
app.listen(port, host)
console.log('Server listening on http://' + host + ':' + port) // eslint-disable-line no-console
}
start()
Below worked for me.
package.json
"start": "npm install --save cross-env && nuxt build && cross-env NODE_ENV=production node server/index.js",
This install cross-env before serving and nuxt build is a required command in production.
Plus I've changes in server.js
Add health route to express:
app.get('/_ah/health', (req, res) => {
res.status(200)
res.send({hello:'world'})
})
Listen to only port
// app.listen(host,port)
app.listen(port)