File size: 10,114 Bytes
6f5b644
 
 
 
 
 
 
 
 
 
e30ea26
6f5b644
 
 
 
e30ea26
6f5b644
 
 
 
 
 
 
 
 
e30ea26
6f5b644
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import { json } from "@remix-run/node";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { useLoaderData, Link } from "@remix-run/react";

export async function loader({ request }: LoaderFunctionArgs) {
  // Check environment variables
  const envCheck = {
    GITHUB_APP_ID: {
      value: process.env.GITHUB_APP_ID || null,
      required: true,
      example: "your-app-id",
    },
    GITHUB_APP_NAME: {
      value: process.env.GITHUB_APP_NAME || null,
      required: true,
      example: "your-app-name",
    },
    GITHUB_APP_PRIVATE_KEY: {
      value: process.env.GITHUB_APP_PRIVATE_KEY ? "βœ“ Set" : null,
      required: true,
      example: "-----BEGIN RSA PRIVATE KEY-----...",
    },
    GITHUB_APP_CLIENT_ID: {
      value: process.env.GITHUB_APP_CLIENT_ID || null,
      required: true,
      example: "your-client-id",
    },
    GITHUB_APP_CLIENT_SECRET: {
      value: process.env.GITHUB_APP_CLIENT_SECRET ? "βœ“ Set" : null,
      required: true,
      example: "your-client-secret",
    },
    GITHUB_WEBHOOK_SECRET: {
      value: process.env.GITHUB_WEBHOOK_SECRET ? "βœ“ Set" : null,
      required: false,
      example: "your-webhook-secret",
    },
    GITHUB_CALLBACK_URL: {
      value: process.env.GITHUB_CALLBACK_URL || null,
      required: true,
      example: "http://localhost:3000/auth/github/callback",
    },
    SESSION_SECRET: {
      value: process.env.SESSION_SECRET ? "βœ“ Set" : null,
      required: true,
      example: "your-session-secret",
    },
  };

  const missing = Object.entries(envCheck).filter(
    ([key, config]) => config.required && !config.value
  );

  const isReady = missing.length === 0;

  return json({
    envCheck,
    missing,
    isReady,
    nodeEnv: process.env.NODE_ENV || "development",
  });
}

export default function Status() {
  const { envCheck, missing, isReady, nodeEnv } = useLoaderData<typeof loader>();

  return (
    <div className="min-h-screen bg-gray-50 py-8">
      <div className="max-w-4xl mx-auto px-4">
        <div className="bg-white rounded-lg shadow-md p-6">
          <div className="flex items-center justify-between mb-6">
            <h1 className="text-2xl font-bold text-gray-900">
              Environment Status
            </h1>
            <Link
              to="/"
              className="text-blue-600 hover:text-blue-700 text-sm font-medium"
            >
              ← Back to Home
            </Link>
          </div>

          {/* Status Overview */}
          <div className="mb-8">
            <div className={`p-4 rounded-lg border ${
              isReady 
                ? 'bg-green-50 border-green-200' 
                : 'bg-red-50 border-red-200'
            }`}>
              <div className="flex items-center">
                <div className="flex-shrink-0">
                  {isReady ? (
                    <svg className="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor">
                      <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
                    </svg>
                  ) : (
                    <svg className="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
                      <path fillRule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clipRule="evenodd" />
                    </svg>
                  )}
                </div>
                <div className="ml-3">
                  <h3 className={`text-sm font-medium ${
                    isReady ? 'text-green-800' : 'text-red-800'
                  }`}>
                    {isReady ? 'βœ… Ready to go!' : '⚠️ Configuration needed'}
                  </h3>
                  <div className={`mt-2 text-sm ${
                    isReady ? 'text-green-700' : 'text-red-700'
                  }`}>
                    {isReady ? (
                      <p>All required environment variables are configured.</p>
                    ) : (
                      <p>
                        {missing.length} required environment variable{missing.length > 1 ? 's' : ''} missing.
                      </p>
                    )}
                  </div>
                </div>
              </div>
            </div>
          </div>

          {/* Environment Variables Table */}
          <div className="mb-8">
            <h2 className="text-lg font-semibold text-gray-900 mb-4">
              Environment Variables
            </h2>
            <div className="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg">
              <table className="min-w-full divide-y divide-gray-300">
                <thead className="bg-gray-50">
                  <tr>
                    <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                      Variable
                    </th>
                    <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                      Status
                    </th>
                    <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                      Required
                    </th>
                    <th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                      Example
                    </th>
                  </tr>
                </thead>
                <tbody className="bg-white divide-y divide-gray-200">
                  {Object.entries(envCheck).map(([key, config]) => (
                    <tr key={key}>
                      <td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                        {key}
                      </td>
                      <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        {config.value ? (
                          <span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
                            {config.value}
                          </span>
                        ) : (
                          <span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
                            Not set
                          </span>
                        )}
                      </td>
                      <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                        {config.required ? 'βœ… Yes' : 'βšͺ Optional'}
                      </td>
                      <td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500 font-mono">
                        {config.example}
                      </td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
          </div>

          {/* Missing Variables */}
          {missing.length > 0 && (
            <div className="mb-8">
              <h2 className="text-lg font-semibold text-gray-900 mb-4">
                Missing Configuration
              </h2>
              <div className="bg-yellow-50 border border-yellow-200 rounded-lg p-4">
                <div className="flex">
                  <div className="flex-shrink-0">
                    <svg className="h-5 w-5 text-yellow-400" viewBox="0 0 20 20" fill="currentColor">
                      <path fillRule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clipRule="evenodd" />
                    </svg>
                  </div>
                  <div className="ml-3">
                    <h3 className="text-sm font-medium text-yellow-800">
                      Add these to your .env file:
                    </h3>
                    <div className="mt-2 text-sm text-yellow-700">
                      <div className="bg-gray-900 text-green-400 p-3 rounded font-mono text-xs overflow-x-auto">
                        {missing.map(([key, config]) => (
                          <div key={key}>
                            {key}={config.example}
                          </div>
                        ))}
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          )}

          {/* Quick Actions */}
          <div className="bg-gray-50 rounded-lg p-4">
            <h3 className="text-lg font-semibold text-gray-900 mb-4">
              Quick Actions
            </h3>
            <div className="grid md:grid-cols-2 gap-4">
              <div>
                <h4 className="font-medium text-gray-900 mb-2">Generate Secrets</h4>
                <p className="text-sm text-gray-600 mb-3">
                  Generate random secrets for SESSION_SECRET and GITHUB_WEBHOOK_SECRET:
                </p>
                <code className="text-xs bg-gray-800 text-green-400 p-2 rounded block">
                  npm run secrets
                </code>
              </div>
              <div>
                <h4 className="font-medium text-gray-900 mb-2">Environment</h4>
                <p className="text-sm text-gray-600 mb-2">
                  Current environment: <span className="font-mono">{nodeEnv}</span>
                </p>
                <p className="text-sm text-gray-600">
                  {nodeEnv === 'development' ? (
                    <>βœ… Development mode - using .env file</>
                  ) : (
                    <>πŸš€ Production mode - using system environment</>
                  )}
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}