diff --git a/config/paths.js b/config/paths.js index fe1d96a2..ed16c68b 100644 --- a/config/paths.js +++ b/config/paths.js @@ -1,10 +1,23 @@ +// @flow strict const path = require('path'); const fs = require('fs'); const appDirectory = fs.realpathSync(process.cwd()); const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath); -const paths = { +type PathsType = { + clientBuild: string, + serverBuild: string, + dotenv: string, + src: string, + srcClient: string, + srcServer: string, + srcApp: string, + publicPath: string, + resolveModules?: Array +}; + +const paths: PathsType = { clientBuild: resolveApp('build/client'), serverBuild: resolveApp('build/server'), dotenv: resolveApp('.env'), diff --git a/src/server/index.js b/src/server/index.js index 06aa19a4..31a1241d 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -1,24 +1,35 @@ -// eslint-disable-next-line import/no-extraneous-dependencies +// @flow strict import express from 'express'; +import type { + $Application, + $Request, + $Response, + NextFunction, +} from 'express'; import cors from 'cors'; import path from 'path'; import chalk from 'chalk'; +// "express-manifest-helpers" has not compatible Flow version +// $FlowIgnoreMe import manifestHelpers from 'express-manifest-helpers'; import bodyParser from 'body-parser'; -import serverRender from './render'; -import paths from '../../config/paths'; import store from '@/store'; - +// "paths" isn't been transpiled, so it can be ignored +// $FlowIgnoreMe +import paths from '../../config/paths'; +import serverRender from './render'; +// "dotenv" has not compatible Flow version +// $FlowFixMe require('dotenv').config(); -const app = express(); +const app: $Application = express(); // Use Nginx or Apache to serve static assets in production or remove the if() around the following // lines to use the express.static middleware to serve assets for production (not recommended!) if (process.env.NODE_ENV === 'development') { app.use(paths.publicPath, express.static(path.join(paths.clientBuild, paths.publicPath))); - app.use('/favicon.ico', (req, res) => { + app.use('/favicon.ico', (req: $Request, res: $Response): void => { res.send(''); }); } @@ -27,8 +38,10 @@ app.use(cors()); app.use(bodyParser.json()); -app.use((req, res, next) => { - req.store =store; +app.use((req: $Request, res: $Response, next: NextFunction) => { + // "store" doesn't exists on express$Request, so we can just ignore it + // $FlowIgnore + req.store = store; return next(); }); @@ -43,7 +56,7 @@ app.use( app.use(serverRender()); // eslint-disable-next-line no-unused-vars -app.use((err, req, res, next) => { +app.use((err: Error, req: $Request, res: $Response, next: NextFunction): $Response => { return res.status(404).json({ status: 'error', message: err.message, @@ -66,7 +79,7 @@ app.use((err, req, res, next) => { }); }); -app.listen(process.env.PORT || 8500, () => { +app.listen(process.env.PORT || 8500, (): void => { // eslint-disable-next-line no-console console.log( `[${new Date().toISOString()}]`,