Skip to content
Snippets Groups Projects
Commit 961c1d09 authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Add node-server, edit config in environnement with appropriated urls for en...

Add node-server, edit config in environnement with appropriated urls for en anf fr versions of the app
parent 13487e00
No related branches found
No related tags found
No related merge requests found
/node_modules
/dist
\ No newline at end of file
{
"name": "node-server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.2",
"compression": "^1.7.2",
"express": "^4.16.3"
}
}
// Use ng build to build your app into build directory.
// Create nodejs app to server the build directory as static content, then create route for api.
// Following is an example of nodejs app using express that will serve the Angular2 app:
/*
Put content of angular2 build into 'public' folder.
*/
const html = __dirname + '/dist';
const port = 8080;
// Express
const bodyParser = require('body-parser');
const compression = require('compression');
const express = require('express');
var app = express();
app
.use(compression())
.use(bodyParser.json())
// Static content
.use(express.static(html))
.use('/', function(req, res) {
// Check if language is set in url else take browser settings from http request header
const language = req.path.split('/')[1] || req.acceptsLanguages()[0];
let redirect = '';
switch (language) {
case 'fr':
case 'fr-FR':
redirect = '/fr';
break;
default:
redirect = '/en';
}
res.redirect(redirect);
})
// Start server
.listen(port, function () {
console.log('Port: ' + port);
console.log('Html: ' + html);
});
\ No newline at end of file
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
"start-aot-en": "ng serve --aot --i18nFile=src/i18n/messages.en.xlf --i18nFormat=xlf --locale=en", "start-aot-en": "ng serve --aot --i18nFile=src/i18n/messages.en.xlf --i18nFormat=xlf --locale=en",
"build": "ng build", "build": "ng build",
"build-prod": "ng build --prod", "build-prod": "ng build --prod",
"build-i18n": "for lang in en fr; do ng build --output-path=dist/$lang --aot --bh /$lang/ --i18n-file=src/locale/messages.$lang.xlf --i18n-format=xlf --locale=$lang; done", "build-i18n": "for lang in en fr; do ng build --output-path=dist/$lang --aot --bh /$lang/ --i18n-file=src/i18n/messages.$lang.xlf --i18n-format=xlf --locale=$lang; done",
"win-build-i18n:fr": "ng build --output-path=dist/fr --aot --bh /fr/ --i18n-file=src/locale/messages.fr.xlf --i18n-format=xlf --locale=fr", "win-build-i18n:fr": "ng build --output-path=dist/fr --aot --bh /fr/ --i18n-file=src/i18n/messages.fr.xlf --i18n-format=xlf --locale=fr",
"win-build-i18n:en": "ng build --output-path=dist/en --aot --bh /en/ --i18n-file=src/locale/messages.en.xlf --i18n-format=xlf --locale=en", "win-build-i18n:en": "ng build --output-path=dist/en --aot --bh /en/ --i18n-file=src/i18n/messages.en.xlf --i18n-format=xlf --locale=en",
"win-build-i18n": "npm run win-build-i18n:en && npm run win-build-i18n:fr", "win-build-i18n": "npm run win-build-i18n:en && npm run win-build-i18n:fr",
"test": "ng test --sourcemaps=false --code-coverage=true", "test": "ng test --sourcemaps=false --code-coverage=true",
"lint": "ng lint", "lint": "ng lint",
......
...@@ -12,7 +12,7 @@ export const environment = { ...@@ -12,7 +12,7 @@ export const environment = {
}, },
angularAppHost: { angularAppHost: {
fr: 'http://localhost:4000/fr', fr: 'http://localhost:8080/fr',
en: 'http://localhost:4000/en' en: 'http://localhost:8080/en'
} }
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment