From 8a01b0ff35524ad675c58ec040d4c813e22180c9 Mon Sep 17 00:00:00 2001 From: Kyle Belanger Date: Fri, 28 Feb 2025 11:15:00 -0500 Subject: [PATCH] add app.js --- server/app.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 server/app.js 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