| 20 | } |
| 21 | |
| 22 | function routes( |
| 23 | options: SCServer.SCServerOptions, |
| 24 | store: Store, |
| 25 | scServer: SCServer |
| 26 | ) { |
| 27 | const limit = options.maxRequestBody; |
| 28 | const logHTTPRequests = options.logHTTPRequests; |
| 29 | |
| 30 | if (logHTTPRequests) { |
| 31 | if (typeof logHTTPRequests === 'object') |
| 32 | app.use( |
| 33 | morgan( |
| 34 | 'combined', |
| 35 | logHTTPRequests as morgan.Options< |
| 36 | http.IncomingMessage, |
| 37 | http.ServerResponse |
| 38 | > |
| 39 | ) |
| 40 | ); |
| 41 | else app.use(morgan('combined')); |
| 42 | } |
| 43 | |
| 44 | const server = new ApolloServer({ |
| 45 | typeDefs: schema, |
| 46 | resolvers, |
| 47 | context: { |
| 48 | store: store, |
| 49 | }, |
| 50 | }); |
| 51 | server |
| 52 | .start() |
| 53 | .then(() => { |
| 54 | server.applyMiddleware({ app } as { |
| 55 | app: express.Application; |
| 56 | }); |
| 57 | }) |
| 58 | .catch((error) => { |
| 59 | console.error(error); // eslint-disable-line no-console |
| 60 | }); |
| 61 | |
| 62 | serveUmdModule('react'); |
| 63 | serveUmdModule('react-dom'); |
| 64 | serveUmdModule('@redux-devtools/app'); |
| 65 | |
| 66 | app.get('/port.js', function (req, res) { |
| 67 | res.send(`reduxDevToolsPort = ${options.port!}`); |
| 68 | }); |
| 69 | app.get('*', function (req, res) { |
| 70 | res.sendFile(path.join(__dirname, '../app/index.html')); |
| 71 | }); |
| 72 | |
| 73 | app.use(cors({ methods: 'POST' })); |
| 74 | app.use(bodyParser.json({ limit: limit })); |
| 75 | app.use(bodyParser.urlencoded({ limit: limit, extended: false })); |
| 76 | |
| 77 | app.post('/', function (req, res) { |
| 78 | if (!req.body) return res.status(404).end(); |
| 79 | switch (req.body.op) { |