Skip to content

Instantly share code, notes, and snippets.

@nblenke
Last active January 11, 2023 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nblenke/b7adef675d378b1d7811d343d4be7d20 to your computer and use it in GitHub Desktop.
Save nblenke/b7adef675d378b1d7811d343d4be7d20 to your computer and use it in GitHub Desktop.
node react server
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