回答編集履歴

5

a

2018/04/04 04:08

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -111,3 +111,11 @@
111
111
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
112
112
 
113
113
  ```
114
+
115
+
116
+
117
+ # 追記
118
+
119
+
120
+
121
+ 類似したこちらの解決済み質問([express.staticの使用方法](https://teratail.com/questions/120112))も参考になさってみてください。

4

a

2018/04/04 04:08

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -1,4 +1,4 @@
1
- # 1
1
+ # 候補1
2
2
 
3
3
  ```
4
4
 
@@ -32,7 +32,53 @@
32
32
 
33
33
 
34
34
 
35
- # 2
35
+
36
+
37
+ ## 参考
38
+
39
+ [http://expressjs.com/en/starter/static-files.html
40
+
41
+ ](http://expressjs.com/en/starter/static-files.html)
42
+
43
+
44
+
45
+ > To create a virtual path prefix (where the path does not actually exist in the file system) for files that are served by the express.static function, specify a mount path for the static directory, as shown below:
46
+
47
+
48
+
49
+ > `app.use('/static', express.static('public'))`
50
+
51
+ Now, you can load the files that are in the public directory from the /static path prefix.
52
+
53
+
54
+
55
+ > http://localhost:3000/static/images/kitten.jpg
56
+
57
+ http://localhost:3000/static/css/style.css
58
+
59
+ http://localhost:3000/static/js/app.js
60
+
61
+ http://localhost:3000/static/images/bg.png
62
+
63
+ http://localhost:3000/static/hello.html
64
+
65
+
66
+
67
+ > However, the path that you provide to the express.static function is relative to the directory from where you launch your node process. If you run the express app from another directory, it’s safer to use the absolute path of the directory that you want to serve:
68
+
69
+
70
+
71
+ > `app.use('/static', express.static(path.join(__dirname, 'public')))`
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ # 候補2
36
82
 
37
83
  ```
38
84
 
@@ -54,7 +100,7 @@
54
100
 
55
101
 
56
102
 
57
- # 3
103
+ # 候補3
58
104
 
59
105
  普通にcdnを使うのが手っ取り早いですね。
60
106
 

3

a

2018/04/02 14:06

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -1,3 +1,5 @@
1
+ # 1
2
+
1
3
  ```
2
4
 
3
5
  var app = express();
@@ -26,11 +28,35 @@
26
28
 
27
29
 
28
30
 
29
- 動作未確認の一例ですが、こんな感じでいけませんか
31
+ 動作未確認の一例ですが、こんな感じでいけませんか?
30
32
 
31
33
 
32
34
 
35
+ # 2
36
+
37
+ ```
38
+
39
+ <!- こちらではなく ->
40
+
41
+ <script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
42
+
43
+
44
+
45
+ <!- こちら? ->
46
+
47
+ <script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
48
+
49
+
50
+
51
+ ```
52
+
53
+ それか、単にパスの指定が間違っている可能性有り
54
+
55
+
56
+
57
+ # 3
58
+
33
- それか普通にcdnを使う
59
+ 普通にcdnを使うのが手っ取り早いですね
34
60
 
35
61
 
36
62
 

2

a

2018/04/02 13:58

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -10,6 +10,8 @@
10
10
 
11
11
  app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js/bootstrap.min.js'));
12
12
 
13
+ //他の2つ省略
14
+
13
15
  ```
14
16
 
15
17
 
@@ -17,6 +19,8 @@
17
19
  ```
18
20
 
19
21
  <script src="/js/bootstrap.min.js"></script>
22
+
23
+ //他の2つ省略
20
24
 
21
25
  ```
22
26
 
@@ -32,6 +36,6 @@
32
36
 
33
37
  ```
34
38
 
35
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
39
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
36
40
 
37
41
  ```

1

a

2018/04/02 13:54

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -23,3 +23,15 @@
23
23
 
24
24
 
25
25
  動作未確認の一例ですが、こんな感じでいけませんかね?
26
+
27
+
28
+
29
+ それか普通にcdnを使うか。
30
+
31
+
32
+
33
+ ```
34
+
35
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
36
+
37
+ ```