Change prod workflow and add automatic deployment
This commit is contained in:
@@ -11,29 +11,32 @@ const fastify = Fastify({ logger: true });
|
||||
await connectDB();
|
||||
|
||||
const allowedOrigins = [
|
||||
'http://192.168.0.26:5169',
|
||||
'http://192.168.0.26:5173',
|
||||
'http://localhost:5173',
|
||||
'http://localhost',
|
||||
process.env.SERVER_EXT_ACCESS,
|
||||
process.env.SERVER_INT_ACCESS,
|
||||
'https://localhost',
|
||||
'capacitor://localhost',
|
||||
'https://10.0.2.2:5173',
|
||||
'https://zenkanji.crylia.de'
|
||||
];
|
||||
|
||||
if (process.env.CORS_ORIGINS) {
|
||||
const prodOrigins = process.env.CORS_ORIGINS.split(',');
|
||||
allowedOrigins.push(...prodOrigins);
|
||||
}
|
||||
'http://localhost:5173'
|
||||
].filter(Boolean).map(uri => uri.replace(/\/$/, ''));
|
||||
|
||||
await fastify.register(cors, {
|
||||
origin: allowedOrigins,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
||||
origin: (origin, cb) => {
|
||||
if (!origin) return cb(null, true);
|
||||
|
||||
if (allowedOrigins.includes(origin)) {
|
||||
return cb(null, true);
|
||||
}
|
||||
|
||||
console.log(`CORS BLOCKED: Browser sent "${origin}". Allowed list:`, allowedOrigins);
|
||||
|
||||
cb(new Error("Not allowed by CORS"));
|
||||
},
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
credentials: true
|
||||
});
|
||||
|
||||
await fastify.register(jwt, {
|
||||
secret: JWT_SECRET
|
||||
secret: process.env.JWT_SECRET
|
||||
});
|
||||
|
||||
fastify.decorate('authenticate', async function (req, reply) {
|
||||
@@ -67,7 +70,6 @@ await fastify.register(routes);
|
||||
const start = async () => {
|
||||
try {
|
||||
await fastify.listen({ port: PORT, host: '0.0.0.0' });
|
||||
console.log(`Server running at http://localhost:${PORT}`);
|
||||
} catch (err) {
|
||||
fastify.log.error(err);
|
||||
process.exit(1);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export const PORT = process.env.PORT || 3000;
|
||||
export const MONGO_URI = process.env.MONGO_URI || 'mongodb://mongo:27017/zenkanji' || 'mongodb://192.168.0.26:27017/zenkanji';
|
||||
export const SRS_TIMINGS_HOURS = [0, 2, 4, 8, 23, 47];
|
||||
export const PORT = 3000;
|
||||
export const MONGO_URI = process.env.MONGO_URI
|
||||
export const JWT_SECRET = process.env.JWT_SECRET;
|
||||
|
||||
Reference in New Issue
Block a user