diff --git a/server/app.js b/server/app.js new file mode 100644 index 0000000..5fdcf2b --- /dev/null +++ b/server/app.js @@ -0,0 +1,27 @@ +const express = require('express'); +const cors = require('cors'); +const path = require('path'); +// const postsRoutes = require('./routes/posts'); //TODO uncomment as this is built +// const projectsRoutes = require('./routes/projects'); //TODO uncomment as this is built + +const app = express(); + +// Middleware + +app.use(cors()); +app.use(express.json()); + +// API Routes +// app.use('/api/posts', postsRoutes); //TODO uncomment as this is built +// app.use('/api/projects', projectsRoutes); //TODO uncomment as this is built + +// Serve Static files in production +if (process.env.NODE_ENV === 'production') { + app.use(express.static(path.join(__dirname, '../client/dist'))); + + app.get('*', (req, res) => { + res.sendFile(path.resolve(__dirname, '../client', 'dist', 'index.html')); + }); +} + +module.exports = app; \ No newline at end of file