From 7355a43f18dd05c46488273198e0cf8b1708a619 Mon Sep 17 00:00:00 2001 From: Guillaume WANG <guillaume.wang@polytechnique.edu> Date: Sat, 24 Nov 2018 18:23:02 +0100 Subject: [PATCH] fix admin_router, favicon and assets --- assets/favicon.ico | Bin 0 -> 1406 bytes ldap_config.json | 3 +-- src/adminview/admin_router.ts | 8 -------- src/app.ts | 16 +++++++++++++++- src/config_passport.js | 6 +++--- src/ldap/config.ts | 4 ++-- webpack.config.js | 12 +++++++----- 7 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 assets/favicon.ico diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..67ff63fc603b159a9ae03a74d178ce8e84ff94dd GIT binary patch literal 1406 zcmZQzU<5(|0R}M0U}azs1F|%L7$l?s#Ec9aKoZP=&}i)cyAi^ptkDn{4S|sp0*uH2 z<ZX05PyiYlFb0eUmMahd7l85+T1XIpDaC3enhj)f!R|%(A3Fm>0}!8o&cN{eI|IY# i{|pR2f%p#)|Ep(U_z%P&8pH>QgXEtB@p+(HkUjw8&>Nfp literal 0 HcmV?d00001 diff --git a/ldap_config.json b/ldap_config.json index d18f831..57370d5 100644 --- a/ldap_config.json +++ b/ldap_config.json @@ -58,6 +58,5 @@ "admin": "memberUid", "class": "objectClass" } - }, - "sessionSecret":"ozyNMHdT,WFTu|t" + } } \ No newline at end of file diff --git a/src/adminview/admin_router.ts b/src/adminview/admin_router.ts index 68aec59..e672d8f 100644 --- a/src/adminview/admin_router.ts +++ b/src/adminview/admin_router.ts @@ -33,10 +33,6 @@ import flash from 'connect-flash'; // packages pour l'API REST et pour GraphQL Voyager import knex from '../../db/knex_router'; import { express as graphqlVoyager } from 'graphql-voyager/middleware'; -// packages pour pouvoir importer des fichiers de config -import path from 'path'; -import { static as expressStatic } from 'express'; // pour pouvoir servir les fichiers statiques -import favicon from 'serve-favicon'; // tres tres important :p const whitelist = [ "magi.karp", @@ -58,10 +54,6 @@ const router = Router(); router.use(flash()); -console.log("Express router is running at", __dirname); -router.use(favicon(path.resolve(__dirname, 'favicon.ico'))); -router.use('/assets', expressStatic(path.resolve(__dirname, '..', '..', 'assets'))); - let port = process.env.PORT || 3000; /** diff --git a/src/app.ts b/src/app.ts index 017f637..1f45c14 100644 --- a/src/app.ts +++ b/src/app.ts @@ -60,6 +60,12 @@ const corsOptions = { }; app.use(cors(corsOptions)); +// respond to "GET /favicon.ico" requests +// favicon middleware is placed near the top of the middleware stack, to answer favicon requests faster, as they are relatively frequent +// (plus, they should not have to trigger any authentication middleware) +import favicon from 'serve-favicon'; // tres tres important :p +app.use(favicon(path.resolve(__dirname, 'adminview', 'favicon.ico'))); + /** * @desc Authentification de la requête contre le session-store (cookie) * ===================================================================== @@ -228,13 +234,21 @@ server.applyMiddleware({ app }); * - à une API REST fait-maison (peut-être encore à débugger) * - à GraphQL Voyager, un package qui permet d'afficher une représentation sous forme de graphe du schéma GraphQL. */ +// servir les fichiers statiques (e.g. images) rendant l'interface jolie +app.use('/assets', express.static(path.resolve(__dirname, '../', 'assets'))); + // setup the 'pug' view engine. the adminview "sub-app" will inherit this. https://expressjs.com/en/4x/api.html#app.set -//console.log("Express app is running at", __dirname); +//console.log("Express app is running at (__dirname) ", __dirname); +//console.log("Express app is running at (full path) ", path.resolve(__dirname));let viewpath = path.resolve(__dirname, 'adminview', 'views'); let viewpath = path.resolve(__dirname, 'adminview', 'views'); app.set('views', viewpath); app.set('view engine', 'pug'); app.use('/adminview', router); // catches and resolves HTTP requests to paths '/adminview/*' +// also redirect other HTTP GET requests to the adminview router +app.get('/', function (req, res) { + res.redirect('/adminview'); +}); /** * @desc Catch-all diff --git a/src/config_passport.js b/src/config_passport.js index 1b84976..050b5e9 100644 --- a/src/config_passport.js +++ b/src/config_passport.js @@ -37,11 +37,11 @@ import { ldapConfig } from './ldap/config'; // specifies options for 'ldapauth' strategy, to customize the behaviour of subsequent passport.authenticate('ldapauth') calls passport.use(new LdapStrategy({ server: { - url: ldapConfig.ldap.server, + url: ldapConfig.server, //bindDn: '.............', //bindCredentials: '..........', - searchBase: ldapConfig.ldap.searchBase, - searchFilter: ldapConfig.ldap.searchFilter, + // searchBase: ldapConfig.searchBase, TODO: this cannot be left empty. + // searchFilter: ldapConfig.searchFilter, TODO: this cannot be left empty. //searchAttributes: ['givenName', 'sn'], //tlsOptions: '..........', }, diff --git a/src/ldap/config.ts b/src/ldap/config.ts index 8a9d8ad..422e6b5 100644 --- a/src/ldap/config.ts +++ b/src/ldap/config.ts @@ -7,8 +7,8 @@ import fs from 'fs'; import path from 'path'; import colors from 'colors'; // Point central ; tous les champs de la BDD sont 'cachés' dans config.json et pas visibles directement -let path_config = path.resolve('..','ldap_config.json') -let path_credentials = path.resolve('..','ldap_credentials.json') +let path_config = path.resolve('ldap_config.json') +let path_credentials = path.resolve('ldap_credentials.json') console.log(colors.cyan("Loading LDAP config file from "+path_config)); console.log(colors.cyan("Loading LDAP credentials from "+path_credentials)); export const ldapConfig = JSON.parse(fs.readFileSync(path_config).toString()); diff --git a/webpack.config.js b/webpack.config.js index b80f64c..8a2f661 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -18,11 +18,12 @@ const config = { }, target: 'node', - //node: { __dirname: false }, <-- TODO: check that this can be removed + // allows using __dirname with the correct semantic (otherwise __dirname will return '/' regardless of file) + node: { __dirname: true }, // Choose a style of source mapping to enhance the debugging process // https://webpack.js.org/configuration/devtool/ - devtool: 'inline-source-map', //TODO: in production, remove this + //devtool: 'inline-source-map', //TODO: in production, or if deemed too slow, remove this // do not bundle node_modules, nor secret config files externals: [ @@ -77,11 +78,12 @@ const config = { }] }, { test: /\.(png|jpg|ico)$/, - use: [{ - loader: 'url-loader?limit=8192', + use: { + loader: 'url-loader?limit=8192' // loads files as base64 encoded URL if filesize is < limit // default fallback: file-loader - }] + } + //use: ['file-loader'] }] }, -- GitLab