diff --git a/.gitignore b/.gitignore index 8f3086e..6389c42 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ uploads/* tmp/* -.env -site -site/* \ No newline at end of file +.env \ No newline at end of file diff --git a/routes.ts b/routes.ts index 0f2d1c8..d57e596 100644 --- a/routes.ts +++ b/routes.ts @@ -10,6 +10,12 @@ const imageCollection = db.collection('images'); const userTable = db.collection('users'); +export const site = async (ctx: RouterContext) => { + if(ctx.params.filename == "sw.js" || ctx.params.filename == "script.js"){ + ctx.response.type = "text/javascript" + } + ctx.response.body = await renderFileToString(`${Deno.cwd()}/site/${ctx.params.filename}`, {}) +} export const icons = async (ctx: RouterContext, next: any) => { const identifier = ctx.params.filename @@ -124,7 +130,6 @@ export const getImage = async (ctx: RouterContext) => { ctx.response.type = info.mime; ctx.response.body = img; } - } export const deleteImage = async (ctx: RouterContext) => { @@ -151,7 +156,6 @@ export const deleteImage = async (ctx: RouterContext) => { }else{ ctx.response.body = {message: 'Unauthorized'}; ctx.response.status = 401 - } } } diff --git a/server.ts b/server.ts index ed82960..9bc6169 100644 --- a/server.ts +++ b/server.ts @@ -1,5 +1,5 @@ import { Application, Router } from "https://deno.land/x/oak/mod.ts"; -import { getImage, uploadImage, deleteImage, chunks, mergeChunks, announce, icons} from './routes.ts'; +import { getImage, uploadImage, deleteImage, chunks, mergeChunks, announce, site, icons} from './routes.ts'; import "https://deno.land/std@0.178.0/dotenv/load.ts"; @@ -16,6 +16,7 @@ router.get('/', async(ctx: RouterContext, next: any) => { } }) +.get('/:filename', site) .get('/i/:filename', icons) .post('/upload', uploadImage) .post('/announce', announce) @@ -24,7 +25,6 @@ router.get('/', async(ctx: RouterContext, next: any) => { .delete('/image/:filename', deleteImage) .get('/image/:filename', getImage) - const app = new Application(); app.use(router.routes())