Created
November 5, 2019 22:28
-
-
Save JesseDavda/44ecebd0bd0aede629b68001d371dd29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 cors from 'cors'; | |
import path from 'path'; | |
import * as FinanceTracker from './config/spa.config'; | |
const app = express(); | |
app.use(cors()); | |
app.use(express.json()); | |
function getAssetPath() { | |
return path.join(__dirname, "../client/build/static"); | |
} | |
app.use(express.static('../client/build')); | |
app.get('/', (req, res) => { | |
res.sendFile(path.resolve(getAssetPath(), `${FinanceTracker.getRedirectName()}.html`), {etag:false}); | |
}); | |
app.get('/:entryPoint', (req, res) => { | |
if(req.params.entryPoint.toLowerCase() === 'myaccounts' || req.params.entryPoint.toLowerCase() === "login") { | |
res.sendFile(path.resolve(getAssetPath(), req.params.entryPoint), {etag: false}); | |
} else { | |
res.redirect(303, '/') | |
} | |
}); | |
const PORT = process.env.PORT || 3001; | |
app.listen(PORT, () => { | |
console.log("Server listening on port: ", PORT); | |
}); |
This file contains hidden or 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
const ConfiguredSPAs = () => { | |
function SPA(params) { | |
this.params = params; | |
} | |
const FinanceTracker = new SPA({ | |
name: 'FinanceTracker', | |
entryPoint: '../../client/build/index.html', | |
redirect: true | |
}); | |
FinanceTracker.appTitle = "Finance Tracker"; | |
FinanceTracker.getEntryPoint = () => { | |
return FinanceTracker.params.entryPoint; | |
} | |
FinanceTracker.getRedirectName = () => { | |
return FinanceTracker.params.name; | |
} | |
return FinanceTracker | |
} | |
export default ConfiguredSPAs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment