summaryrefslogtreecommitdiff
path: root/src/server/web
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/web')
-rw-r--r--src/server/web/feed.ts6
-rw-r--r--src/server/web/index.ts42
-rw-r--r--src/server/web/manifest.ts2
-rw-r--r--src/server/web/url-preview.ts10
4 files changed, 33 insertions, 27 deletions
diff --git a/src/server/web/feed.ts b/src/server/web/feed.ts
index d4792c63aa..57b1401e35 100644
--- a/src/server/web/feed.ts
+++ b/src/server/web/feed.ts
@@ -1,7 +1,7 @@
import { Feed } from 'feed';
-import config from '@/config';
-import { User } from '../../models/entities/user';
-import { Notes, DriveFiles, UserProfiles } from '../../models';
+import config from '@/config/index.js';
+import { User } from '@/models/entities/user.js';
+import { Notes, DriveFiles, UserProfiles } from '@/models/index.js';
import { In } from 'typeorm';
export default async function(user: User) {
diff --git a/src/server/web/index.ts b/src/server/web/index.ts
index 44ab2a997f..68cfc5d0f0 100644
--- a/src/server/web/index.ts
+++ b/src/server/web/index.ts
@@ -4,7 +4,9 @@
import * as os from 'os';
import * as fs from 'fs';
-import ms = require('ms');
+import { fileURLToPath } from 'url';
+import { dirname } from 'path';
+import * as ms from 'ms';
import * as Koa from 'koa';
import * as Router from '@koa/router';
import * as send from 'koa-send';
@@ -13,37 +15,41 @@ import * as views from 'koa-views';
import * as glob from 'glob';
import * as MarkdownIt from 'markdown-it';
-import packFeed from './feed';
-import { fetchMeta } from '@/misc/fetch-meta';
-import { genOpenapiSpec } from '../api/openapi/gen-spec';
-import config from '@/config';
-import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips, GalleryPosts } from '../../models';
-import { parseAcct } from '@/misc/acct';
-import { getNoteSummary } from '@/misc/get-note-summary';
+import packFeed from './feed.js';
+import { fetchMeta } from '@/misc/fetch-meta.js';
+import { genOpenapiSpec } from '../api/openapi/gen-spec.js';
+import config from '@/config/index.js';
+import { Users, Notes, Emojis, UserProfiles, Pages, Channels, Clips, GalleryPosts } from '@/models/index.js';
+import { parseAcct } from '@/misc/acct.js';
+import { getNoteSummary } from '@/misc/get-note-summary.js';
import { getConnection } from 'typeorm';
-import { redisClient } from '../../db/redis';
-import locales = require('../../../locales');
+import { redisClient } from '../../db/redis.js';
+import locales from '../../../locales/index.js';
+
+//const _filename = fileURLToPath(import.meta.url);
+const _filename = __filename;
+const _dirname = dirname(_filename);
const markdown = MarkdownIt({
html: true
});
-const changelog = fs.readFileSync(`${__dirname}/../../../CHANGELOG.md`, { encoding: 'utf8' });
+const changelog = fs.readFileSync(`${_dirname}/../../../CHANGELOG.md`, { encoding: 'utf8' });
function genDoc(path: string): string {
let md = fs.readFileSync(path, { encoding: 'utf8' });
md = md.replace('<!--[CHANGELOG]-->', changelog);
return md;
}
-const staticAssets = `${__dirname}/../../../assets/`;
-const docAssets = `${__dirname}/../../../src/docs/`;
-const assets = `${__dirname}/../../assets/`;
+const staticAssets = `${_dirname}/../../../assets/`;
+const docAssets = `${_dirname}/../../../src/docs/`;
+const assets = `${_dirname}/../../assets/`;
// Init app
const app = new Koa();
// Init renderer
-app.use(views(__dirname + '/views', {
+app.use(views(_dirname + '/views', {
extension: 'pug',
options: {
version: config.version,
@@ -52,7 +58,7 @@ app.use(views(__dirname + '/views', {
}));
// Serve favicon
-app.use(favicon(`${__dirname}/../../../assets/favicon.ico`));
+app.use(favicon(`${_dirname}/../../../assets/favicon.ico`));
// Common request handler
app.use(async (ctx, next) => {
@@ -75,7 +81,7 @@ router.get('/static-assets/(.*)', async ctx => {
router.get('/doc-assets/(.*)', async ctx => {
if (ctx.path.includes('..')) return;
- const path = `${__dirname}/../../../src/docs/${ctx.path.replace('/doc-assets/', '')}`;
+ const path = `${_dirname}/../../../src/docs/${ctx.path.replace('/doc-assets/', '')}`;
const doc = genDoc(path);
ctx.set('Content-Type', 'text/plain; charset=utf-8');
ctx.body = doc;
@@ -134,7 +140,7 @@ router.get('/docs.json', async ctx => {
ctx.body = [];
return;
}
- const dirPath = `${__dirname}/../../../src/docs/${lang}`.replace(/\\/g, '/');
+ const dirPath = `${_dirname}/../../../src/docs/${lang}`.replace(/\\/g, '/');
const paths = glob.sync(`${dirPath}/**/*.md`);
const docs: { path: string; title: string; summary: string; }[] = [];
for (const path of paths) {
diff --git a/src/server/web/manifest.ts b/src/server/web/manifest.ts
index 918fe27c03..a35b2a5696 100644
--- a/src/server/web/manifest.ts
+++ b/src/server/web/manifest.ts
@@ -1,6 +1,6 @@
import * as Koa from 'koa';
import * as manifest from './manifest.json';
-import { fetchMeta } from '@/misc/fetch-meta';
+import { fetchMeta } from '@/misc/fetch-meta.js';
module.exports = async (ctx: Koa.Context) => {
const json = JSON.parse(JSON.stringify(manifest));
diff --git a/src/server/web/url-preview.ts b/src/server/web/url-preview.ts
index 1ba8e0034a..af9e2c77f5 100644
--- a/src/server/web/url-preview.ts
+++ b/src/server/web/url-preview.ts
@@ -1,10 +1,10 @@
import * as Koa from 'koa';
import summaly from 'summaly';
-import { fetchMeta } from '@/misc/fetch-meta';
-import Logger from '../../services/logger';
-import config from '@/config';
-import { query } from '../../prelude/url';
-import { getJson } from '@/misc/fetch';
+import { fetchMeta } from '@/misc/fetch-meta.js';
+import Logger from '@/services/logger.js';
+import config from '@/config/index.js';
+import { query } from '../../prelude/url.js';
+import { getJson } from '@/misc/fetch.js';
const logger = new Logger('url-preview');