Proxy front-end from back-end

master
Ian Mancini 4 years ago
parent 43cdcd3307
commit 5fad05ac31

6986
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,5 +1,4 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
@ -13,24 +12,13 @@ module.exports = {
version: 'detect',
},
},
env: {
browser: true,
amd: true,
node: true,
},
plugins: ['simple-import-sort'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
rules: {
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
'react/prop-types': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'simple-import-sort/sort': 'error',
'react/prop-types': ['off'],
},
}

File diff suppressed because it is too large Load Diff

@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@chakra-ui/core": "^1.0.0-rc.7",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
@ -10,6 +11,7 @@
"@types/node": "^12.0.0",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"framer-motion": "^2.9.4",
"http-proxy-middleware": "^1.0.6",
"react": "^17.0.1",
"react-dom": "^17.0.1",

@ -1,7 +1,19 @@
import { ChakraProvider, Heading, Stack, Link, VStack } from '@chakra-ui/core'
import React from 'react'
function App(): JSX.Element {
return <div>cliente</div>
return (
<ChakraProvider resetCSS>
<VStack>
<Heading> museo.red </Heading>
<Stack>
<Link href="/auth/facebook">ingresar con facebook</Link>
<Link href="/auth/twitter">ingresar con facebook</Link>
<Link href="/auth/google">ingresar con google</Link>
</Stack>
</VStack>
</ChakraProvider>
)
}
export default App

@ -3,7 +3,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware')
module.exports = (app) => {
app.use(
['/auth', '/socket.io'],
['/socket.io'],
createProxyMiddleware({
target: 'http://localhost:3000',
changeOrigin: true,

@ -1,6 +1,6 @@
{
"extends": ["eslint:recommended", "prettier"],
"plugins": ["prettier", "simple-import-sort"],
"plugins": ["prettier"],
"rules": {},
"root": true,
"parserOptions": {
@ -12,7 +12,6 @@
"node": true
},
"rules": {
"prettier/prettier": ["error", {}, { "usePrettierrc": true }],
"simple-import-sort/sort": "error"
"prettier/prettier": ["error", {}, { "usePrettierrc": true }]
}
}

@ -2364,6 +2364,11 @@
"is-symbol": "^1.0.2"
}
},
"es6-promise": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz",
"integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w=="
},
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
@ -2730,6 +2735,31 @@
"vary": "~1.1.2"
}
},
"express-http-proxy": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/express-http-proxy/-/express-http-proxy-1.6.2.tgz",
"integrity": "sha512-soP7UXySFdLbeeMYL1foBkEoZj6HELq9BDAOCr1sLRpqjPaFruN5o6+bZeC+7U4USWIl4JMKEiIvTeKJ2WQdlQ==",
"requires": {
"debug": "^3.0.1",
"es6-promise": "^4.1.1",
"raw-body": "^2.3.0"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"express-session": {
"version": "1.17.1",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.1.tgz",

@ -7,7 +7,7 @@
"scripts": {
"build": "babel src --out-dir build --copy-files",
"serve": "node build/index.js",
"start": "nodemon -w src --exec \"yarn build && yarn serve\"",
"start": "nodemon -w src --exec \"npm run build && npm run serve\"",
"lint": "eslint src/**/*.js*",
"fix": "eslint --fix src/**/*.js*"
},
@ -38,6 +38,7 @@
"cookie-parser": "^1.4.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-http-proxy": "^1.6.2",
"express-session": "^1.17.1",
"mongoose": "^5.10.10",
"passport": "^0.4.1",

@ -1,8 +1,8 @@
import path from 'path'
import dotenv from 'dotenv'
dotenv.config({ path: path.join(__dirname, '../../../.env') });
dotenv.config({ path: path.join(__dirname, '../../../.env') })
import { Strategy } from 'passport-facebook';
import { Strategy } from 'passport-facebook'
import { Router } from 'express'
import passport from 'passport'
@ -13,19 +13,25 @@ const strategyOptions = {
clientID: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
callbackURL: '/auth/facebook/redirect',
profileFields: ['id', 'displayName', 'picture.type(large)', 'email']
profileFields: ['id', 'displayName', 'picture.type(large)', 'email'],
}
export function facebookStrategy() {
return new Strategy(strategyOptions, genericStrategy('facebook'));
return new Strategy(strategyOptions, genericStrategy('facebook'))
}
export const facebookRouter = Router()
const facebookAuthenticateOptions = {
authType: 'rerequest', scope: ['email']
authType: 'rerequest',
scope: ['email'],
}
facebookRouter.get('/facebook', passport.authenticate('facebook', facebookAuthenticateOptions));
facebookRouter.get('/facebook/redirect',
passport.authenticate('facebook', { successRedirect: '/museo', failureRedirect: '/' }));
facebookRouter.get(
'/facebook',
passport.authenticate('facebook', facebookAuthenticateOptions),
)
facebookRouter.get(
'/facebook/redirect',
passport.authenticate('facebook', { successRedirect: '/museo', failureRedirect: '/' }),
)

@ -1,11 +1,12 @@
import 'regenerator-runtime/runtime';
import 'regenerator-runtime/runtime'
import path from 'path'
import dotenv from 'dotenv'
dotenv.config({ path: path.join(__dirname, '../.env') });
dotenv.config({ path: path.join(__dirname, '../.env') })
import http from 'http';
import express from 'express';
import http from 'http'
import express from 'express'
import proxy from 'express-http-proxy'
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
import session from 'express-session'
@ -15,66 +16,66 @@ import connectRedis from 'connect-redis'
import passport from 'passport'
import mongoose from 'mongoose'
import { authRouter, initPassport } from './auth/passport';
import ensureAuthenticated from './auth/middleware';
import { authRouter, initPassport } from './auth/passport'
const RedisStore = connectRedis(session);
const RedisStore = connectRedis(session)
const redisClient = redis.createClient({
host: '127.0.0.1',
port: 6379,
password: process.env.REDIS_PASSWORD
password: process.env.REDIS_PASSWORD,
})
redisClient.on('error', (error) => {
console.error(error);
});
console.error(error)
})
redisClient.on('connect', () => {
console.log('Connection to Redis has been established successfully.');
});
console.log('Connection to Redis has been established successfully.')
})
mongoose.connect('mongodb://localhost:27017', {
mongoose.connect(
'mongodb://localhost:27017',
{
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true,
user: process.env.MONGODB_USER,
pass: process.env.MONGODB_PASSWORD,
dbName: 'museum'
}, () => {
dbName: 'museum',
},
() => {
console.log('Connection to MongoDB has been established successfully.')
})
},
)
const app = express();
app.set('trust proxy', 1);
const server = http.createServer(app);
const app = express()
app.set('trust proxy', 1)
const server = http.createServer(app)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser(process.env.SESSION_SECRET));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser(process.env.SESSION_SECRET))
app.use(
session({
store: new RedisStore({ client: redisClient }),
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
})
);
}),
)
app.use(passport.initialize());
app.use(passport.session());
initPassport();
app.use('/auth', authRouter);
app.use(passport.initialize())
app.use(passport.session())
initPassport()
app.use('/auth', authRouter)
app.use(express.static(path.resolve(__dirname, '../static')));
app.get('/', (_req, res) => {
res.render('index');
});
app.get('/museo', ensureAuthenticated, (req, res) => {
res.render('museo', { user: req.user })
});
if (process.env.NODE_ENV !== 'PRODUCTION') {
const proxy = require('express-http-proxy')
app.use('/', proxy('http://localhost:4000/'))
} else {
// probably serve up build version in production
}
server.listen(3000, () => {
console.log('> Ready on http://localhost:3000');
});
console.log('> Ready on http://localhost:3000')
})

Loading…
Cancel
Save