回答編集履歴
2
訂正
answer
CHANGED
@@ -4,14 +4,36 @@
|
|
4
4
|
[https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls](https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls)
|
5
5
|
|
6
6
|
## 追記
|
7
|
-
expressを使用したくない場合のサンプルがありました。確認は行ってないので参考までに
|
7
|
+
~~expressを使用したくない場合のサンプルがありました。確認は行ってないので参考までに~~
|
8
|
+
|
8
9
|
[https://codeday.me/jp/qa/20181214/48640.html](https://codeday.me/jp/qa/20181214/48640.html)
|
9
10
|
|
10
|
-
```
|
11
|
+
```js
|
11
12
|
app.get('*',function(req,res,next){
|
12
13
|
if(req.headers['x-forwarded-proto']!='https')
|
13
14
|
res.redirect('https://mypreferreddomain.com'+req.url)
|
14
15
|
else
|
15
16
|
next() /* Continue to other routes if we're not redirecting */
|
16
17
|
})
|
18
|
+
```
|
19
|
+
|
20
|
+
## 追記2
|
21
|
+
|
22
|
+
こちらが、expressを使用してないコードです。
|
23
|
+
|
24
|
+
[https://qiita.com/watsuyo_2/items/1c99b59f93ea1ee77f14](https://qiita.com/watsuyo_2/items/1c99b59f93ea1ee77f14)
|
25
|
+
|
26
|
+
```js
|
27
|
+
'use strict';
|
28
|
+
const http = require('http');
|
29
|
+
const server = http.createServer((req, res) => {
|
30
|
+
res.writeHead(302, {
|
31
|
+
'Location': 'https://www.google.co.jp/'
|
32
|
+
});
|
33
|
+
res.end();
|
34
|
+
});
|
35
|
+
const port = 8000;
|
36
|
+
server.listen(port, () => {
|
37
|
+
console.info('Listening on ' + port);
|
38
|
+
});
|
17
39
|
```
|
1
コード追記
answer
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
herokuにはルータ機能がないので、アプリケーションレベルでリダイレクトしないといけないっぽいですね。
|
2
2
|
express(node.js)以外にも公式にサンプルがあります。
|
3
3
|
|
4
|
-
[https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls](https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls)
|
4
|
+
[https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls](https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls)
|
5
|
+
|
6
|
+
## 追記
|
7
|
+
expressを使用したくない場合のサンプルがありました。確認は行ってないので参考までに
|
8
|
+
[https://codeday.me/jp/qa/20181214/48640.html](https://codeday.me/jp/qa/20181214/48640.html)
|
9
|
+
|
10
|
+
```ts
|
11
|
+
app.get('*',function(req,res,next){
|
12
|
+
if(req.headers['x-forwarded-proto']!='https')
|
13
|
+
res.redirect('https://mypreferreddomain.com'+req.url)
|
14
|
+
else
|
15
|
+
next() /* Continue to other routes if we're not redirecting */
|
16
|
+
})
|
17
|
+
```
|