Files
classroomio/src/server.js
T

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-07-25 17:44:11 +03:00
import dotenv from 'dotenv';
2021-07-31 23:06:14 +03:00
import { json } from 'body-parser';
2020-12-24 20:32:05 +02:00
import sirv from 'sirv';
2021-07-31 23:06:14 +03:00
import express from 'express';
2020-12-24 20:32:05 +02:00
import compression from 'compression';
import * as sapper from '@sapper/server';
2021-07-31 23:06:14 +03:00
import cookieParser from 'cookie-parser';
import { getSupabase } from './utils/functions/supabase';
2020-12-24 20:32:05 +02:00
2021-07-31 23:06:14 +03:00
dotenv.config();
2020-12-24 20:32:05 +02:00
2021-07-31 23:06:14 +03:00
const config = {
isProd: process.env.NODE_ENV !== 'development',
2021-07-31 23:06:14 +03:00
telegramToken: process.env.SVELTE_APP_TELEGRAM_API_TOKEN,
supabaseConfig: {
2021-08-26 13:35:56 +03:00
bucketPath:
'https://koxqonvbkeakwvmdegcf.supabase.in/storage/v1/object/sign',
2021-07-31 23:06:14 +03:00
url: process.env.SVELTE_APP_SUPABASE_URL,
anonKey: process.env.SVELTE_APP_SUPABASE_ANON_KEY,
},
};
const supabase = getSupabase(config);
express() // You can also use Express
.use(cookieParser())
.use(json())
2021-07-25 17:44:11 +03:00
.use(
compression({ threshold: 0 }),
sirv('static', { dev: true }),
2021-07-31 23:06:14 +03:00
sapper.middleware({
session: async (req) => {
const { user } = await supabase.auth.api.getUserByCookie(req);
2021-08-18 19:47:02 +03:00
console.log('cookie calling');
// console.log('req', req.headers.host);
2021-07-31 23:06:14 +03:00
return {
user: JSON.stringify(user),
config,
host: req.headers.host,
2021-07-31 23:06:14 +03:00
};
},
})
2021-07-25 17:44:11 +03:00
)
2021-07-31 23:06:14 +03:00
.listen(process.env.PORT, (err) => {
2021-07-25 17:44:11 +03:00
if (err) console.log('error', err);
});