Last active
January 11, 2023 23:32
-
-
Save nblenke/b7adef675d378b1d7811d343d4be7d20 to your computer and use it in GitHub Desktop.
node react server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express' | |
import * as path from 'path' | |
import cors from 'cors' | |
const app = express() | |
const PORT = process.env.PORT || 5000 | |
const __dirname = path.resolve(path.dirname('')) | |
app.use(cors()) | |
app.use(express.static(path.join(__dirname, 'public'))) | |
app.use( | |
'/static', | |
express.static(path.join(__dirname, './build/static')) | |
) | |
app.get('/', function (req, res) { | |
res.sendFile('index.html', { | |
root: path.join(__dirname, './build/'), | |
}) | |
}) | |
app.get('/*', function (req, res) { | |
res.sendFile('index.html', { | |
root: path.join(__dirname, './build/'), | |
}) | |
}) | |
app.use(express.json()) | |
app.listen(PORT, () => console.log(`listening on ${PORT}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment