I want the existing spring boot gateway as the backend server, instead of the angular 2 .
that is i want the angular2 combines to the spring gateway .
Assume :
the angular 2 webpack-dev-server on port 8090 , and there is a
page index.html
spring boot gateway on port 8080: and all the api .
I want to open
localhost:8080
to see the angular2 index.html ,
how to implement ?
You need to set up proxy for your backend. I know that webpack-dev-server based on Express. So, I can give you a clue how to run it with Express:
var express = require('express');
var request = require('request');
var path = require('path');
var app = express();
app.use('/api', function(req, res) {
var url = 'http://localhost:8080/api' + req.url;
req.pipe(request(url)).pipe(res);
});
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
/* serves all the static files */
app.get(/^(.+)$/, function(req, res){
res.sendFile( __dirname + req.params[0]);
});
app.listen(8090);
Then you refer to backend API by /api/entry-point .
#Injectable()
export class HttpProductDiscountService {
constructor(private _http: Http) {}
getProductDiscounts() {
return this._http.get('api/1.0/product-discount')
.map(res => res.json())
}
}
I have found an example of an implementation ,
front is : https://github.com/springboot-angular2-tutorial/angular2-app
and spring-server is : https://github.com/springboot-angular2-tutorial/boot-app ,
Reference to this example , I have successfully build a simplify
demo .
Related
I'm trying to run a Deno app with a deno_webview and an http server but for some reason I cannot run both at the same time, calling webview.run() seems to block something and I can no longer reach my http server.
In order to prevent the blocking, I'm trying running either the server or the webview in a webworker, but in both scenarios I get the same error "Cannot find name 'window'"
What is the issue here?
api.webworker.ts
import { Application } from 'https://deno.land/x/oak/mod.ts';
const app = new Application();
await app.listen({ port: 8080 });
webview.webworker.ts
import { WebView } from 'https://deno.land/x/webview/mod.ts';
const webview = new WebView({ url: 'http://localhost:4200' });
await webview.run();
server.ts
const webviewWorker = new Worker(
'./workers/webview.worker.ts', {
type: 'module',
deno: true
});
Error:
const apiWorker = new Worker(
'./workers/api.worker.ts', {
type: 'module',
deno: true
});
Error:
Web Workers don't have window object, you have to use self or globalThis
So https://deno.land/x/webview/mod.ts doesn't support being called from a Web Worker.
The library will need to change window usage to globalThis so it will work int the main process and inside workers.
Created a next.js full stack application. After production build when I run next start it returns 500 : internal server. I'm using environment varibles for hitting api.
env.development file
BASE_URL=http://localhost:3000
It was working fine in development
service.ts
import axios from 'axios';
const axiosDefaultConfig = {
baseURL: process.env.BASE_URL, // is this line reason for error?
headers: {
'Access-Control-Allow-Origin': '*'
}
};
const axio = axios.create(axiosDefaultConfig);
export class Steam {
static getGames = async () => {
return await axio.get('/api/getAppList');
};
}
Do you have a next.config.js file?
To add runtime configuration to your app open next.config.js and add the publicRuntimeConfig and serverRuntimeConfig configs:
module.exports = {
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: 'secret',
secondSecret: process.env.SECOND_SECRET, // Pass through env variables
},
publicRuntimeConfig: {
// Will be available on both server and client
staticFolder: '/static',
},
}
To get access to the runtime configs in your app use next/config, like so:
import getConfig from 'next/config'
// Only holds serverRuntimeConfig and publicRuntimeConfig
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
// Will only be available on the server-side
console.log(serverRuntimeConfig.mySecret)
// Will be available on both server-side and client-side
console.log(publicRuntimeConfig.staticFolder)
function MyImage() {
return (
<div>
<img src={`${publicRuntimeConfig.staticFolder}/logo.png`} alt="logo" />
</div>
)
}
export default MyImage
I hope this helps.
I dont think you have setup env.
You need to configure it for it to work. Try it without it and it should work fine!
The Problem
I have a simple Nodejs Express Hello_World application up and running both locally and on a live server using Plesk-Onyx17.8.11. The app runs correctly on localhost:3000 in my browser:
But after I push the files to the server (using a Filezilla ftp client), my browser can't load the files in the public folder, so it won't load the CSS file:
As you can see the file http://shamimkeshani.ir/stylesheets/style.css cannot be downloaded. This is the correct URL, because we use app.use(express.static(path.join(__dirname, '/public'))); in the Express app. But hypothetically if we insert a wrong URL file of http://shamimkeshani.ir/public/stylesheets/style.css it would find the file and download it correctly from shamimkeshani.ir, which is not the correct behavior! Also, this will not work locally which is the right behavior!!
The codes
I used express-generator to create the default Hello_World Express application. The app.js file:
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
console.log(__dirname);
app.use(express.static(path.join(__dirname, '/public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
I use a server.js file to run the Nodejs application. This file is actually a copy of ./bin/www file that Express uses. I use npm start which runs this file locally. Also, the server.js file is set in the Plesk for starting the application on the server:
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('./app');
var debug = require('debug')('app:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
package.json file:
{
"name": "app",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./server.js"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11"
}
}
I also checked the Nodejs versions running locally and at the server and they both match (10.1.0).
I searched a lot and couldn't figure out how to solve this problem. I want for my Nodejs application to work the same locally and on the server. Any additional thoughts on the future problems that I may encounter and any further suggestions are appreciated. Thanks.
I have hosted Bitnami parse server in AWS as a HTTP service. I am unable to create a new app in the parse server through its dashboard. I also tried a 1 hour demo with Bitnami parse-server in that demo also I am unable to create a new app. How to do this?
https://bitnami.com/stack/parse
I am unable to achieve this through REST API also. Because the demo site doesn't required a credentials to login. The /1/apps API call requires a email/password to create an app.
How to create a app in this demo site?
Bitnami developer here,
Unfortunately, you can not create a new app using a demo site. Note that this app would serve another API. For that, you need to access via SSH and edit the /opt/bitnami/apps/parse/htdocs/server.js file. For instance, you could have 2 apps with the code below:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
//API 1
var api1 = new ParseServer({
databaseURI: "mongodb://root:password#127.0.0.1:27017/bitnami_parse1",
cloud: "./node_modules/parse-server/lib/cloud-code/Parse.Cloud.js",
appId: "myappid1",
masterKey: "mymasterkey1",
fileKey: "myfilekey1",
serverURL: 'http://X.X.X.X:80/parse1'
});
app.use('/parse1', api1);
//API 2
var api2 = new ParseServer({
databaseURI: "mongodb://root:password#127.0.0.1:27017/bitnami_parse",
cloud: "./node_modules/parse-server/lib/cloud-code/Parse.Cloud.js",
appId: "myappid2",
masterKey: "mymasterkey2",
fileKey: "myfilekey2",
serverURL: 'http://X.X.X.X:80/parse2'
});
app.use('/parse2', api2);
var port = 1337;
app.listen(port, function() {
console.log('parse-server running on port ' + port);
});
//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
apps: [
{
appName: "myapp1",
appId: 'myappid1',
masterKey: 'mymasterkey1',
fileKey: 'myfilekey1',
production: true,
serverURL: 'http://X.X.X.X:80/parse1'
}
,
{
appName: "myapp2",
appId: 'myappid2',
masterKey: 'mymasterkey2',
fileKey: 'myfilekey2',
production: true,
serverURL: 'http://X.X.X.X:80/parse2'
}
]
,
"users": [
{
"user":"user",
"pass":"password"
}
]
});
app.use('/', dashboard);
var portdash = 4040;
app.listen(portdash, function() {
console.log('parse-dashboard running on port ' + portdash);
});
Then, you would need to add the lines below to your /opt/bitnami/apps/parse/conf/httpd-app.conf to set the Apache ProxyPass configuration:
ProxyPass /parse1 http://127.0.0.1:1337/parse1
ProxyPassReverse /parse1 http://127.0.0.1:1337/parse1
ProxyPass /parse2 http://127.0.0.1:1337/parse2
ProxyPassReverse /parse2 http://127.0.0.1:1337/parse2
and then restart the services executing:
$ sudo /opt/bitnami/ctlscript.sh restart
I hope you find it useful.
Currently building an application in node.js. I am trying to make a server-side HTTP request to an ASP script and return the results.
If I navigate to the url in my browser, everything is fine. Data is returned. However, when I do this in node.js using restler, or any other module for that matter. I get nothing back......UNTIL I add the ASP.NET_SessionId cookie to the header of the request. I copied this cookie from the successul GET from my browser.
How do I get/set this session cookie server-side in node.js?
Using express framework. Code below.
app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('cat'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.get('/', routes.index);
app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
route index.js
/*
* GET home page.
*/
exports.index = function(req, res){
var http = require("http"),
sys = require('util'),
rest = require('restler');
rest.get('http://192.168.154.134/dca/stream/StreamDown.asp?' +
'Action=GetRepositoryConnections' , {headers:{
'Cookie':'ASP.NET_SessionId=jj1jx255wlkwib45gq0d3555;' +
' ASPSESSIONIDASDDSBQR=ACABCJNDIIONGGMPGAOMMJJD;' +
' ASPSESSIONIDCQQRQDQR=BAIBCEODMMKAPJAOLLMMDNEJ;' +
' ASPSESSIONIDAQSTRAQR=KMLDIOODECFNBKPGINLLNBKC;' +
' ASPSESSIONIDASQQQDQR=OKGBKCPDHDIKAJNOGFKACCCG'}
}).on('complete', function(result) {
if (result instanceof Error) {
sys.puts('Error: ' + result.message);
this.retry(5000); // try again after 5 sec
} else {
sys.puts(result);
}
});
res.render('index', { title: 'Express' });
};
Try request. It has a "cookie jar" so it will remember cookies for you.