diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..67ff63fc603b159a9ae03a74d178ce8e84ff94dd Binary files /dev/null and b/assets/favicon.ico differ diff --git a/ldap_config.json b/ldap_config.json index d18f8313f487619df82d05f9eaae182db0e1ca91..57370d5e8279fa05723aa4f9c3e9290246b161d7 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 68aec59fcbb9159e1635542aa46192dd87cf0f9f..e672d8fdf425ae31fd5d8270b68fbdd104dd3240 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 017f637dd84094d37a1b78a2a3f77b1f340cd8e9..1f45c14d3e4e64ffec13a848490be751ffa2cad8 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 1b849768be1f1d03ef70e549420ff7c6f2fa0466..050b5e932fae24ff015f06de14786806c0ac855e 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 8a9d8ad430f0cab239223504a62e5d9266b30939..422e6b59865d187f63d9faad7b68d636647f156f 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 b80f64c58079eebbc2a46dcbf1aa4c6278777e8c..8a2f66171630ea72d1d9c45896d099a242a0cf92 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'] }] },