|
1 | | -const createError = require('http-errors'); |
2 | 1 | const express = require('express'); |
3 | 2 | const path = require('path'); |
| 3 | +const cookieParser = require('cookie-parser'); |
4 | 4 | const logger = require('morgan'); |
| 5 | + |
| 6 | +const indexRouter = require('./routes/index'); |
| 7 | +const usersRouter = require('./routes/users'); |
5 | 8 | const heroesRouter = require('./routes/heroes'); |
6 | | -const providerStateRouter = require('./routes/provider_state'); |
| 9 | +const providerStateRouter = require ('./routes/provider_state'); |
| 10 | + |
7 | 11 | const app = express(); |
8 | 12 |
|
9 | 13 | app.use(logger('dev')); |
10 | 14 | app.use(express.json()); |
11 | | -app.use(express.urlencoded({extended: false})); |
| 15 | +app.use(express.urlencoded({ extended: false })); |
| 16 | +app.use(cookieParser()); |
| 17 | +app.use(express.static(path.join(__dirname, 'public'))); |
12 | 18 |
|
| 19 | +app.use('/', indexRouter); |
| 20 | +app.use('/users', usersRouter); |
13 | 21 | app.use('/heroes', heroesRouter); |
14 | 22 |
|
15 | | -registerPactEndpoint(); |
16 | | - |
17 | | -// catch 404 and forward to error handler |
18 | | -app.use(function (req, res, next) { |
19 | | - next(createError(404)); |
20 | | -}); |
| 23 | +if (process.env.PACT_MODE === 'true') { |
| 24 | + app.use('/provider-state', providerStateRouter); |
| 25 | +} |
21 | 26 |
|
22 | 27 | module.exports = app; |
23 | | - |
24 | | -/** |
25 | | - * Registers a special endpoint for pact provider tests that allows to |
26 | | - * set the server into a certain "provider state". |
27 | | - * |
28 | | - * This endpoint is only registered if the environment variable "PACT_MODE" |
29 | | - * is set to "true". |
30 | | - */ |
31 | | -function registerPactEndpoint() { |
32 | | - const pactMode = (process.env.PACT_MODE === 'true'); |
33 | | - if (pactMode) { |
34 | | - app.use('/provider-state', providerStateRouter); |
35 | | - } |
36 | | -} |
0 commit comments