Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gdd-sigma-poc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume WANG
gdd-sigma-poc
Commits
46bef15f
Commit
46bef15f
authored
6 years ago
by
Guillaume WANG
Browse files
Options
Downloads
Patches
Plain Diff
stuff again
parent
d3c0a506
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app.ts
+22
-15
22 additions, 15 deletions
src/app.ts
with
22 additions
and
15 deletions
src/app.ts
+
22
−
15
View file @
46bef15f
...
...
@@ -2,7 +2,7 @@
* @file Initialise et configure le serveur Express sur lequel tourne le back.
*
* Inclut les middlewares des packages utilisés: apollo-server, passportjs, morgan...
* et
définit le middleware de notre API
.
* et
branche nos propres middleware : l'API GraphQL et l'interface admin du backend (adminview)
.
* Pour comprendre ce que fait chaque package, se référer à leur page sur https://www.npmjs.com.
*
* On peut considérer que les app.use (et app.get et app.post) sont pattern-matchés et
...
...
@@ -16,7 +16,7 @@ import bodyParser from 'body-parser';
import
{
express
as
graphqlVoyager
}
from
'
graphql-voyager/middleware
'
;
import
{
ApolloServer
}
from
'
apollo-server-express
'
;
import
schema
from
'
./graphql/schema
'
;
// definition du schéma et des resolvers
// l'interface admin du back (adminview)
// l'interface admin du back
end
(adminview)
import
router
from
'
./adminview/admin.router
'
;
// packages pour l'authentification
import
passport
from
'
passport
'
;
...
...
@@ -39,27 +39,24 @@ app.use(bodyParser.json()); //parses bodies of media type "application/json"
app
.
use
(
bodyParser
.
urlencoded
({
//parses bodies of media type "application/x-www-form-urlencoded"
extended
:
true
//use qs library (see https://www.npmjs.com/package/body-parser#bodyparserurlencodedoptions)
}));
// parse Cookie header and populate req.cookies with an object keyed by the cookie names
app
.
use
(
cookieParser
());
// ne *pas* inclure de header HTTP publicisant que l'application tourne sous Express
app
.
disable
(
'
x-powered-by
'
);
// setup morgan (HTTP request logger middleware)
app
.
use
(
morgan
(
'
dev
'
));
/**
* @desc SETUP DE ADMINVIEW
* @desc Authentification de la requête (cookie)
* =============================================
* Si la requête possède un cookie, on regarde dans la session s'il correspond a un cookie valide.
* Si oui, on récupère l'uid de l'utilisateur correspondant dans la session afin de le passer à GraphQL dans le context.
* Si non, on passe quand meme un uid spécial signifiant que l'utilisateur n'est pas authentifié.
* NB : la session ne contient que les correspondances cookie / uid, et rien d'autre.
*/
// setting up view engine for pug, for adminview
console
.
log
(
"
Express app is running at
"
,
__dirname
);
let
viewpath
=
path
.
resolve
(
__dirname
,
'
views
'
);
app
.
set
(
'
views
'
,
viewpath
);
app
.
set
(
'
view engine
'
,
'
pug
'
);
// load the session
// from passport middleware's perspective: authenticate request "against the session"
/**
* @desc AUTHENTIFICATION POUR LES REQUETES POSSEDANT UN COOKIE ET PROVENANT D'UN UTILISATEUR DEJA AUTHENTIFIE
* Remarque: introduit aussi les middlewares session et passport,
* qui sont aussi utiles pour l'authentification dans les autres cas.
*/
/**
* WTF??? why is sessionSecret in ldap_config.json? it has nothing to do with ldap.
...
...
@@ -242,6 +239,16 @@ app.use('/voyager',
graphqlVoyager
({
endpointUrl
:
'
/graphql
'
})
);
/**
* @desc SETUP DE L'INTERFACE ADMIN DU BACKEND ("ADMINVIEW")
*/
// setting up view engine for pug, for adminview
console
.
log
(
"
Express app is running at
"
,
__dirname
);
let
viewpath
=
path
.
resolve
(
__dirname
,
'
views
'
);
app
.
set
(
'
views
'
,
viewpath
);
app
.
set
(
'
view engine
'
,
'
pug
'
);
// on utilise un express.Router qui sert a creer un "sous-middleware stack".
app
.
use
(
'
/adminview
'
,
router
);
// catches and resolves HTTP requests to paths '/adminview/*'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment