Skip to content
Snippets Groups Projects
Commit 4b135924 authored by ncastejon's avatar ncastejon
Browse files
parents 6586c249 cd292f76
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ COPY ./webapp /app/webapp ...@@ -7,6 +7,7 @@ COPY ./webapp /app/webapp
WORKDIR /app/webapp WORKDIR /app/webapp
# Install npm dependencies # Install npm dependencies
RUN npm install RUN npm install
RUN npm rebuild node-sass
# Building the Angular app /dist i18n # Building the Angular app /dist i18n
RUN npm run build-i18n RUN npm run build-i18n
...@@ -17,5 +18,7 @@ COPY --from=builder /app/webapp/dist /usr/share/nginx/html ...@@ -17,5 +18,7 @@ COPY --from=builder /app/webapp/dist /usr/share/nginx/html
## Install dependency to get lua module in .conf ## Install dependency to get lua module in .conf
RUN apt-get update RUN apt-get update
RUN apt-get --assume-yes install nginx-extras RUN apt-get --assume-yes install nginx-extras
/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
...@@ -2,29 +2,28 @@ ...@@ -2,29 +2,28 @@
server { server {
listen 8080; listen 8080;
server_name portail-data; server_name portail-data;
root /usr/share/nginx/html; root /usr/share/nginx/html/;
location = / { location = / {
rewrite_by_lua ' rewrite_by_lua '
for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do for lang in (ngx.var.http_accept_language .. ","):gmatch("([^,]*),") do
if string.sub(lang, 0, 2) == "en" then if string.sub(lang, 0, 2) == "en" then
ngx.redirect("/en/") ngx.redirect("/en/")
end end
if string.sub(lang, 0, 2) == "fr" then if string.sub(lang, 0, 2) == "fr" then
ngx.redirect("/fr/") ngx.redirect("/fr/")
end end
end end
'; ngx.redirect("/en/")
#rewrite ^/$ /en/ permanent; ';
}
# First attempt to serve request as file, then location /en/ {
# as directory, then fall back to displaying a 404. try_files $uri$args $uri/ /en/index.html;
# Uncomment to enable naxsi on this location }
# include /etc/nginx/naxsi.rules
}
error_page 404 = @notfound;
location @notfound { location /fr/ {
return 301 /; try_files $uri$args $uri/ /fr/index.html;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment