나는 인증없이 잘 작동하는 react/express/socket.io
응용 프로그램을 가지고 있습니다. 응용 프로그램을 Passport
인증을 사용하도록 이식했습니다. 인증은 정상적으로 실행됩니다. 응용 프로그램은 인증없이 정상적으로 실행됩니다. 그러나이 둘은 함께 임피던스가 일치하지 않습니다. 다음과 같이인증에서 웹 사이트로 - 불일치
내 디렉토리 구조는 다음과 같습니다
app.use(express.static(path.join(__dirname, '../client/www')));
...lots of code here...
http.listen(8080, function() {
console.log('listening on: 8080');
});
:
[[email protected] react-ts]$ ls -la
total 32
drwxrwxr-x 6 idf idf 4096 Mar 6 23:13 .
drwxrwxr-x 23 idf idf 4096 Mar 6 22:52 ..
drwxrwxr-x 7 idf idf 4096 Mar 6 21:49 backup
drwxrwxr-x 3 idf idf 4096 Mar 6 22:32 client
drwxrwxr-x 8 idf idf 4096 Mar 7 01:42 .git
-rw-rw-r-- 1 idf idf 21 Feb 7 23:25 .gitignore
-rw-rw-r-- 1 idf idf 1181 Mar 6 23:13 package.json
drwxrwxr-x 4 idf idf 4096 Mar 7 01:26 server
[[email protected] react-trader]$
비판적으로 client
이
[[email protected] client]$ ls
www
[[email protected] client]$
[[email protected] www]$ ls -la
total 24
drwxrwxr-x 4 idf idf 4096 Feb 14 00:34 .
drwxrwxr-x 3 idf idf 4096 Mar 6 22:32 ..
drwxrwxr-x 2 idf idf 4096 Feb 8 00:00 css
-rw-rw-r-- 1 idf idf 593 Mar 2 04:33 index.html
-rw-rw-r-- 1 idf idf 1362 Feb 14 00:30 index.html.hide
drwxrwxr-x 2 idf idf 4096 Mar 5 23:44 js
[[email protected] www]$
[[email protected] js]$ ls -la
total 36
drwxrwxr-x 2 idf idf 4096 Mar 5 23:44 .
drwxrwxr-x 4 idf idf 4096 Feb 14 00:34 ..
-rw-rw-r-- 1 idf idf 16438 Mar 6 00:34 app.js
-rw-rw-r-- 1 idf idf 348 Feb 17 05:42 feed-socketio.js
[[email protected] js]$
내가 인증없이 웹 사이트를 표시하는 데 사용하는 방법 인으로하는 말을했다 그러나 인증 프런트 엔드를 추가 한 후 이번에 동일한 경로를 추가하면 gi
//displays our homepage
app.get('/', function(req, res){
res.render('home', {user: req.user});
});
: 인증의
Cannot GET /client/www/index.html
일부는 다음과 같습니다 : 브라우저가 돌아 오면 다음과 같이 말한다 성공 로그인시 디렉토리하지만 주요 index.html
파일, successRedirect: '../client/www/index.html',
//sends the request through our local login/signin strategy,
//and if successful takes user to homepage,
//otherwise returns then to signin page
app.post('/login', passport.authenticate('local-signin', {
successRedirect: '../client/www/index.html',
failureRedirect: '/signin'
})
);
단지를 ving
내가 돌아 오는 것 같아서 /
을에 넣었습니다.그리고 나서 app.get('/)
을 다시 작성하면 어쨌든 app.use(express.static(path.join(__dirname, '../client/www')));
과 같은 마법을 수행합니다. 즉, 응용 프로그램은 이 아니며 정적 페이지는이고 동적으로 생성 된 웹 페이지는 app.js
입니다. , 로그인에 성공한, 응용 프로그램의 인증 부분에서
<!DOCTYPE html>
<html>
<head>
<title>Trader Desktop</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
<script src="/socket.io/socket.io.js"></script>
<script src="js/feed-socketio.js"></script>
<script type="text/jsx" src="js/app.js"></script>
</head>
<body>
<div class="container" id="main">
</div>
</body>
</html>
:
이var HomePage = React.createClass({
getInitialState: function(){
...
},
...
});
React.render(<HomePage />, document.getElementById('main'));
파일 index.html
단지 쉘입니다 : 실제 작업은 app.js
으로 읽는 파일의 마지막 행을 수행 여기에 주어진 우리는이 파일 main.handlebars
에 저를 취하고있다 참조 :
// Configure express to use handlebars templates
var hbs = exphbs.create({
defaultLayout: 'main',
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
이 파일은라는 하위 디렉토리 안에 0 내부 디렉토리가 layout
전화 :
[[email protected] server]$ ls -la
total 64
drwxrwxr-x 4 idf idf 4096 Mar 7 01:26 .
drwxrwxr-x 6 idf idf 4096 Mar 6 23:13 ..
-rw-rw-r-- 1 idf idf 475 Mar 7 00:01 config.js
-rw-rw-r-- 1 idf idf 8274 Mar 2 19:28 feed.js
-rw-rw-r-- 1 idf idf 2408 Mar 7 00:01 functions.js
drwxrwxr-x 440 idf idf 20480 Mar 6 23:37 node_modules
-rw-rw-r-- 1 idf idf 1198 Mar 6 23:37 package.json
-rw-rw-r-- 1 idf idf 7144 Mar 7 01:28 server.js
drwxrwxr-x 3 idf idf 4096 Mar 6 23:41 views
[[email protected] views]$ ls -la
total 20
drwxrwxr-x 3 idf idf 4096 Mar 6 23:41 .
drwxrwxr-x 4 idf idf 4096 Mar 7 01:26 ..
-rw-rw-r-- 1 idf idf 756 Mar 6 23:41 home.handlebars
drwxrwxr-x 2 idf idf 4096 Mar 6 23:41 layouts
-rw-rw-r-- 1 idf idf 1952 Mar 6 23:41 signin.handlebars
[[email protected] views]$
[[email protected] layouts]$ ls -la
total 12
drwxrwxr-x 2 idf idf 4096 Mar 6 23:41 .
drwxrwxr-x 3 idf idf 4096 Mar 6 23:41 ..
-rw-rw-r-- 1 idf idf 2734 Mar 6 23:41 main.handlebars
[[email protected] layouts]$
아마 매우 간단 뭔가를 놓친 거지,하지만 수정이 무엇인지 확실하지. 본질적으로, 나는 제어를 express
/react
/socket.io
-정적 홈 페이지가 아닌으로 전달하는 인증이 필요합니다.
/index.html을 가져올 수 없습니다. 아마도 app.use없이 index.html을 찾을 수 없습니다 (express.static (path.join (__ dirname, '../client/www')))); 하지만 처음에 사이트를 탐색 할 때이 정보를 입력하면 인증 페이지가 아닌 웹 사이트로 연결됩니다. – Ivan
나는 도움이되는 단서라고 생각하는 원래 게시물에 조금 더 추가했습니다. – Ivan
@Ivan 예 동적 경로로 정적 미들웨어가 변경되었습니다. – Matt