server.js 609 B

1234567891011121314151617181920212223242526272829
  1. var express = require('express')
  2. var path = require('path');
  3. var bodyParser = require('body-parser')
  4. const app = express();
  5. app.use(bodyParser.json());
  6. app.use(bodyParser.urlencoded({ extended: true }));
  7. app.use(express.static(path.join(__dirname, 'build')))
  8. app.get('/auth/check', (req, res) => {
  9. if (req.cookie) {
  10. return true
  11. } else {
  12. return false
  13. }
  14. })
  15. app.get('/*', (req, res) => {
  16. if (!req.cookie) {
  17. res.redirect('/login')
  18. } else {
  19. res.sendFile(path.join(__dirname, 'build', 'index.html'))
  20. }
  21. })
  22. app.listen(5000, () => {
  23. console.log('ok')
  24. })