質問編集履歴

1

Ruby サーバー情報の追加

2021/09/28 07:53

投稿

kento_ar
kento_ar

スコア30

test CHANGED
File without changes
test CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
 
12
12
 
13
+
14
+
15
+
16
+
17
+
18
+
13
19
  ```
14
20
 
15
21
  back | Started PUT "/api/v1/auth" for 172.18.0.1 at 2021-09-28 15:56:20 +0900
@@ -34,6 +40,10 @@
34
40
 
35
41
 
36
42
 
43
+
44
+
45
+ ### フロントエンド(ポート8080)
46
+
37
47
  ```
38
48
 
39
49
  <template>
@@ -107,3 +117,285 @@
107
117
  </script>
108
118
 
109
119
  ```
120
+
121
+
122
+
123
+ ### バックエンド(ポート3000)
124
+
125
+
126
+
127
+ Gemfile
128
+
129
+
130
+
131
+ ```
132
+
133
+ # image
134
+
135
+ gem 'carrierwave'
136
+
137
+ gem 'fog-aws'
138
+
139
+ gem 'mini_magick'
140
+
141
+ ```
142
+
143
+
144
+
145
+ ---
146
+
147
+
148
+
149
+ /back/app/controllers/api/v1/auth/registrations_controller.rb
150
+
151
+ ```
152
+
153
+ # class Api::V1::Auth::RegistrationsController < ApplicationController
154
+
155
+ module Api
156
+
157
+ module V1
158
+
159
+ module Auth
160
+
161
+ class RegistrationsController < DeviseTokenAuth::RegistrationsController
162
+
163
+ private
164
+
165
+
166
+
167
+ def sign_up_params
168
+
169
+ params.permit(:email, :password, :password_confirmation, :image)
170
+
171
+ end
172
+
173
+
174
+
175
+ def account_update_params
176
+
177
+ params.permit(:first_name, :last_name, :email, :password, :image)
178
+
179
+ end
180
+
181
+ end
182
+
183
+ end
184
+
185
+ end
186
+
187
+ end
188
+
189
+ ```
190
+
191
+
192
+
193
+ ---
194
+
195
+ /back/db/migrate/20210910042637_devise_token_auth_create_users.rb
196
+
197
+ ```
198
+
199
+ Rails.application.routes.draw do
200
+
201
+ devise_for :users
202
+
203
+
204
+
205
+ namespace :api do
206
+
207
+ namespace :v1, format: 'json' do
208
+
209
+ mount_devise_token_auth_for 'User', at: 'auth', controllers: {
210
+
211
+ registrations: 'api/v1/auth/registrations'
212
+
213
+ }
214
+
215
+ resources :users, only: %i[index show create update destroy]
216
+
217
+ end
218
+
219
+ end
220
+
221
+ end
222
+
223
+ ```
224
+
225
+ 内容:gem 'devise' を使用。エンドポイントは api/v1/auth。
226
+
227
+
228
+
229
+ ---
230
+
231
+
232
+
233
+ back/config/initializers/carrierwave.rb
234
+
235
+ ```
236
+
237
+ require 'carrierwave/storage/abstract'
238
+
239
+ require 'carrierwave/storage/file'
240
+
241
+ require 'carrierwave/storage/fog'
242
+
243
+
244
+
245
+ CarrierWave.configure do |config|
246
+
247
+ if Rails.env.production?
248
+
249
+ config.cache_storage = :fog
250
+
251
+ config.fog_directory = 's3-bucket-for-images'
252
+
253
+ config.fog_credentials = {
254
+
255
+ provider: 'AWS',
256
+
257
+ aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
258
+
259
+ aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
260
+
261
+ region: 'ap-northeast-1'
262
+
263
+ }
264
+
265
+ else
266
+
267
+ config.asset_host = 'http://localhost:3000'
268
+
269
+ config.cache_storage = :file
270
+
271
+ end
272
+
273
+ end
274
+
275
+ ```
276
+
277
+ 内容:config.asset_host = 'http://localhost:3000' を指定
278
+
279
+
280
+
281
+ ---
282
+
283
+
284
+
285
+ /back/config/environments/development.rb
286
+
287
+
288
+
289
+ ```
290
+
291
+ <snip/>
292
+
293
+
294
+
295
+ config.action_controller.asset_host = 'http://localhost:3000'
296
+
297
+
298
+
299
+ <snip/>
300
+
301
+
302
+
303
+ ```
304
+
305
+
306
+
307
+ ---
308
+
309
+
310
+
311
+ /back/app/uploaders/image_uploader.rb
312
+
313
+
314
+
315
+ ```
316
+
317
+ class ImageUploader < CarrierWave::Uploader::Base
318
+
319
+ if Rails.env.development?
320
+
321
+ storage :file
322
+
323
+ elsif Rails.env.test?
324
+
325
+ storage :file
326
+
327
+ else
328
+
329
+ storage :fog
330
+
331
+ end
332
+
333
+
334
+
335
+ def store_dir
336
+
337
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
338
+
339
+ end
340
+
341
+
342
+
343
+ def default_url(*_args)
344
+
345
+ end
346
+
347
+
348
+
349
+ def extension_allowlist
350
+
351
+ %w[jpg jpeg gif png]
352
+
353
+ end
354
+
355
+
356
+
357
+ def filename
358
+
359
+ original_filename
360
+
361
+ end
362
+
363
+ end
364
+
365
+ ```
366
+
367
+
368
+
369
+
370
+
371
+ ---
372
+
373
+
374
+
375
+
376
+
377
+ /back/db/migrate/20210910042637_devise_token_auth_create_users.rb
378
+
379
+ ```
380
+
381
+ <snip/>
382
+
383
+
384
+
385
+ ## User Info
386
+
387
+ t.string :first_name
388
+
389
+ t.string :last_name
390
+
391
+ t.string :image
392
+
393
+ t.string :email
394
+
395
+
396
+
397
+ <snip/>
398
+
399
+ ```
400
+
401
+ 内容:imageカラムを追加