Input-Text geht, CORS behoben
This commit is contained in:
20
backend/dist/app.js
vendored
20
backend/dist/app.js
vendored
@@ -32,13 +32,22 @@ const allowedOrigins = [
|
||||
'http://localhost:3000',
|
||||
config_1.config.cors.origin
|
||||
].filter(Boolean);
|
||||
app.use((0, cors_1.default)({
|
||||
origin: allowedOrigins,
|
||||
credentials: true,
|
||||
}));
|
||||
const corsConfig = config_1.config.cors.origin === '*'
|
||||
? {
|
||||
origin: true,
|
||||
credentials: true,
|
||||
}
|
||||
: {
|
||||
origin: allowedOrigins,
|
||||
credentials: true,
|
||||
};
|
||||
app.use((0, cors_1.default)(corsConfig));
|
||||
app.use((req, res, next) => {
|
||||
const origin = req.headers.origin;
|
||||
if (origin && allowedOrigins.includes(origin)) {
|
||||
if (config_1.config.cors.origin === '*') {
|
||||
res.header('Access-Control-Allow-Origin', origin || '*');
|
||||
}
|
||||
else if (origin && allowedOrigins.includes(origin)) {
|
||||
res.header('Access-Control-Allow-Origin', origin);
|
||||
}
|
||||
res.header('Access-Control-Allow-Credentials', 'true');
|
||||
@@ -52,6 +61,7 @@ app.use((req, res, next) => {
|
||||
app.use(express_1.default.json({ limit: '10mb' }));
|
||||
app.use(express_1.default.urlencoded({ extended: true, limit: '10mb' }));
|
||||
app.use(requestLogger_1.requestLogger);
|
||||
app.use('/uploads', express_1.default.static(path_1.default.join(process.cwd(), 'uploads')));
|
||||
app.use('/api/health', health_1.default);
|
||||
app.use('/api/recipes', recipes_1.default);
|
||||
app.use('/api/ingredients', ingredients_1.default);
|
||||
|
||||
Reference in New Issue
Block a user