Bye bye subdomains

This commit is contained in:
syuilo 2018-03-27 14:13:12 +09:00
parent b6462b8a2e
commit 753fce41ec
8 changed files with 81 additions and 74 deletions

View File

@ -109,7 +109,6 @@ type Mixin = {
ws_url: string;
auth_url: string;
docs_url: string;
ch_url: string;
stats_url: string;
status_url: string;
dev_url: string;
@ -135,12 +134,11 @@ export default function load() {
mixin.ws_scheme = mixin.scheme.replace('http', 'ws');
mixin.ws_url = `${mixin.ws_scheme}://${mixin.host}`;
mixin.api_url = `${mixin.scheme}://${mixin.host}/api`;
mixin.auth_url = `${mixin.scheme}://auth.${mixin.host}`;
mixin.ch_url = `${mixin.scheme}://ch.${mixin.host}`;
mixin.dev_url = `${mixin.scheme}://dev.${mixin.host}`;
mixin.docs_url = `${mixin.scheme}://docs.${mixin.host}`;
mixin.stats_url = `${mixin.scheme}://stats.${mixin.host}`;
mixin.status_url = `${mixin.scheme}://status.${mixin.host}`;
mixin.auth_url = `${mixin.scheme}://${mixin.host}/auth`;
mixin.dev_url = `${mixin.scheme}://${mixin.host}/dev`;
mixin.docs_url = `${mixin.scheme}://${mixin.host}/docs`;
mixin.stats_url = `${mixin.scheme}://${mixin.host}/stats`;
mixin.status_url = `${mixin.scheme}://${mixin.host}/status`;
mixin.drive_url = `${mixin.scheme}://${mixin.host}/files`;
return Object.assign(config, mixin);

View File

@ -9,7 +9,6 @@ import * as cluster from 'cluster';
import * as express from 'express';
import * as morgan from 'morgan';
import Accesses from 'accesses';
import vhost = require('vhost');
import log from './log-request';
import config from './conf';

View File

@ -21,13 +21,13 @@
// Get the current url information
const url = new URL(location.href);
// Extarct the (sub) domain part of the current url
//
// e.g.
// misskey.alice => misskey
// misskey.strawberry.pasta => misskey
// dev.misskey.arisu.tachibana => dev
let app = url.host === HOST ? 'misskey' : url.host.substr(0, -HOST.length);
//#region Detect app name
let app = null;
if (url.pathname == '/docs') app = 'docs';
if (url.pathname == '/dev') app = 'dev';
if (url.pathname == '/auth') app = 'auth';
//#endregion
// Detect the user language
// Note: The default language is English
@ -57,7 +57,7 @@
}
// Switch desktop or mobile version
if (app == 'misskey') {
if (app == null) {
app = isMobile ? 'mobile' : 'desktop';
}

View File

@ -2,13 +2,15 @@
* Desktop Client
*/
import VueRouter from 'vue-router';
// Style
import './style.styl';
import '../../element.scss';
import init from '../init';
import fuckAdBlock from '../common/scripts/fuck-ad-block';
import HomeStreamManager from '../common/scripts/streaming/home-stream-manager';
import { HomeStreamManager } from '../common/scripts/streaming/home';
import composeNotification from '../common/scripts/compose-notification';
import chooseDriveFolder from './api/choose-drive-folder';
@ -41,8 +43,26 @@ init(async (launch) => {
require('./views/components');
require('./views/widgets');
// Init router
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '/', name: 'index', component: MkIndex },
{ path: '/i/customize-home', component: MkHomeCustomize },
{ path: '/i/messaging/:username', component: MkMessagingRoom },
{ path: '/i/drive', component: MkDrive },
{ path: '/i/drive/folder/:folder', component: MkDrive },
{ path: '/selectdrive', component: MkSelectDrive },
{ path: '/search', component: MkSearch },
{ path: '/othello', component: MkOthello },
{ path: '/othello/:game', component: MkOthello },
{ path: '/@:user', component: MkUser },
{ path: '/@:user/:post', component: MkPost }
]
});
// Launch the app
const [app, os] = launch(os => ({
const [, os] = launch(router, os => ({
chooseDriveFolder,
chooseDriveFile,
dialog,
@ -71,21 +91,6 @@ init(async (launch) => {
registerNotifications(os.stream);
}
}
// Routing
app.$router.addRoutes([
{ path: '/', name: 'index', component: MkIndex },
{ path: '/i/customize-home', component: MkHomeCustomize },
{ path: '/i/messaging/:username', component: MkMessagingRoom },
{ path: '/i/drive', component: MkDrive },
{ path: '/i/drive/folder/:folder', component: MkDrive },
{ path: '/selectdrive', component: MkSelectDrive },
{ path: '/search', component: MkSearch },
{ path: '/othello', component: MkOthello },
{ path: '/othello/:game', component: MkOthello },
{ path: '/@:user', component: MkUser },
{ path: '/@:user/:post', component: MkPost }
]);
}, true);
function registerNotifications(stream: HomeStreamManager) {

View File

@ -3,6 +3,7 @@
*/
import Vue from 'vue';
import VueRouter from 'vue-router';
import BootstrapVue from 'bootstrap-vue';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap-vue/dist/bootstrap-vue.css';
@ -26,14 +27,18 @@ Vue.component('mk-ui', ui);
* init
*/
init(launch => {
// Launch the app
const [app] = launch();
// Init router
const router = new VueRouter({
mode: 'history',
base: '/dev/',
routes: [
{ path: '/', component: Index },
{ path: '/apps', component: Apps },
{ path: '/app/new', component: AppNew },
{ path: '/app/:id', component: App },
]
});
// Routing
app.$router.addRoutes([
{ path: '/', component: Index },
{ path: '/apps', component: Apps },
{ path: '/app/new', component: AppNew },
{ path: '/app/:id', component: App },
]);
// Launch the app
launch(router);
});

View File

@ -91,14 +91,14 @@ if (localStorage.getItem('should-refresh') == 'true') {
}
// MiOSを初期化してコールバックする
export default (callback: (launch: (api?: (os: MiOS) => API) => [Vue, MiOS]) => void, sw = false) => {
export default (callback: (launch: (router: VueRouter, api?: (os: MiOS) => API) => [Vue, MiOS]) => void, sw = false) => {
const os = new MiOS(sw);
os.init(() => {
// アプリ基底要素マウント
document.body.innerHTML = '<div id="app"></div>';
const launch = (api?: (os: MiOS) => API) => {
const launch = (router: VueRouter, api?: (os: MiOS) => API) => {
os.apis = api ? api(os) : null;
Vue.mixin({
@ -112,9 +112,7 @@ export default (callback: (launch: (api?: (os: MiOS) => API) => [Vue, MiOS]) =>
});
const app = new Vue({
router: new VueRouter({
mode: 'history'
}),
router,
created() {
this.$watch('os.i', i => {
// キャッシュ更新

View File

@ -2,6 +2,8 @@
* Mobile Client
*/
import VueRouter from 'vue-router';
// Style
import './style.styl';
import '../../element.scss';
@ -45,8 +47,33 @@ init((launch) => {
// http://qiita.com/junya/items/3ff380878f26ca447f85
document.body.setAttribute('ontouchstart', '');
// Init router
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '/', name: 'index', component: MkIndex },
{ path: '/signup', name: 'signup', component: MkSignup },
{ path: '/i/settings', component: MkSettings },
{ path: '/i/settings/profile', component: MkProfileSetting },
{ path: '/i/notifications', component: MkNotifications },
{ path: '/i/messaging', component: MkMessaging },
{ path: '/i/messaging/:username', component: MkMessagingRoom },
{ path: '/i/drive', component: MkDrive },
{ path: '/i/drive/folder/:folder', component: MkDrive },
{ path: '/i/drive/file/:file', component: MkDrive },
{ path: '/selectdrive', component: MkSelectDrive },
{ path: '/search', component: MkSearch },
{ path: '/othello', component: MkOthello },
{ path: '/othello/:game', component: MkOthello },
{ path: '/@:user', component: MkUser },
{ path: '/@:user/followers', component: MkFollowers },
{ path: '/@:user/following', component: MkFollowing },
{ path: '/@:user/:post', component: MkPost }
]
});
// Launch the app
const [app] = launch(os => ({
launch(router, os => ({
chooseDriveFolder,
chooseDriveFile,
dialog,
@ -54,26 +81,4 @@ init((launch) => {
post: post(os),
notify
}));
// Routing
app.$router.addRoutes([
{ path: '/', name: 'index', component: MkIndex },
{ path: '/signup', name: 'signup', component: MkSignup },
{ path: '/i/settings', component: MkSettings },
{ path: '/i/settings/profile', component: MkProfileSetting },
{ path: '/i/notifications', component: MkNotifications },
{ path: '/i/messaging', component: MkMessaging },
{ path: '/i/messaging/:username', component: MkMessagingRoom },
{ path: '/i/drive', component: MkDrive },
{ path: '/i/drive/folder/:folder', component: MkDrive },
{ path: '/i/drive/file/:file', component: MkDrive },
{ path: '/selectdrive', component: MkSelectDrive },
{ path: '/search', component: MkSearch },
{ path: '/othello', component: MkOthello },
{ path: '/othello/:game', component: MkOthello },
{ path: '/@:user', component: MkUser },
{ path: '/@:user/followers', component: MkFollowers },
{ path: '/@:user/following', component: MkFollowing },
{ path: '/@:user/:post', component: MkPost }
]);
}, true);

View File

@ -10,9 +10,6 @@ import * as express from 'express';
import * as bodyParser from 'body-parser';
import * as favicon from 'serve-favicon';
import * as compression from 'compression';
import vhost = require('vhost');
import config from '../conf';
/**
* Init app
@ -20,7 +17,7 @@ import config from '../conf';
const app = express();
app.disable('x-powered-by');
app.use(vhost(`docs.${config.host}`, require('./docs/server')));
app.use('/docs', require('./docs/server'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({