Skip to content

Commit

Permalink
#23 Support for running in a subdir. (#153)
Browse files Browse the repository at this point in the history
Use relative paths for all requests to the API.
  • Loading branch information
rnwood authored Jul 1, 2019
1 parent 45bf61a commit 905ee7c
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Rnwood.Smtp4dev/ApiModel/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private MessageEntitySummary HandleMimeEntity(MimeEntity entity)
FileName = string.IsNullOrEmpty(e.ContentType?.Name)
? e.ContentDisposition?.FileName
: e.ContentType.Name,
Url = $"/api/messages/{Id}/part/{result.Id}/content"
Url = $"api/messages/{Id}/part/{result.Id}/content"
});
}
}
Expand Down
4 changes: 3 additions & 1 deletion Rnwood.Smtp4dev/ClientApp/ApiClient/AttachmentSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

export default class AttachmentSummary {

constructor(fileName: string, contentId: string, url: string, ) {
constructor(fileName: string, contentId: string, id: string, url: string, ) {

this.fileName = fileName;
this.contentId = contentId;
this.id = id;
this.url = url;
}


fileName: string;
contentId: string;
id: string;
url: string;
}
10 changes: 4 additions & 6 deletions Rnwood.Smtp4dev/ClientApp/ApiClient/HomeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import IActionResult from './IActionResult';
import axios from "axios";

export default class HomeController {
public _baseUrl: string;

constructor(baseUrl: string = "/"){
this._baseUrl = baseUrl;

constructor(){
}



// post: api/Home/
public index_url(): string {
return `${this._baseUrl}api/Home/`;
return `api/Home/`;
}

public async index(): Promise<IActionResult> {
Expand All @@ -24,7 +22,7 @@ export default class HomeController {

// post: api/Home/
public error_url(): string {
return `${this._baseUrl}api/Home/`;
return `api/Home/`;
}

public async error(): Promise<IActionResult> {
Expand Down
6 changes: 3 additions & 3 deletions Rnwood.Smtp4dev/ClientApp/ApiClient/MessageEntitySummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import Header from './Header';
import AttachmentSummary from './AttachmentSummary';
export default class MessageEntitySummary {

constructor(headers: Header[], childParts: MessageEntitySummary[], name: string, messageId: string, id: string, contentId: string, attachments: AttachmentSummary[], size: number, ) {
constructor(id: string, headers: Header[], childParts: MessageEntitySummary[], name: string, messageId: string, contentId: string, attachments: AttachmentSummary[], size: number, ) {

this.id = id;
this.headers = headers;
this.childParts = childParts;
this.name = name;
this.messageId = messageId;
this.id = id;
this.contentId = contentId;
this.attachments = attachments;
this.size = size;
}


id: string;
headers: Header[];
childParts: MessageEntitySummary[];
name: string;
messageId: string;
id: string;
contentId: string;
attachments: AttachmentSummary[];
size: number;
Expand Down
50 changes: 24 additions & 26 deletions Rnwood.Smtp4dev/ClientApp/ApiClient/MessagesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import FileStreamResult from './FileStreamResult';
import axios from "axios";

export default class MessagesController {
public _baseUrl: string;

constructor(baseUrl: string = "/"){
this._baseUrl = baseUrl;

constructor(){
}



// get: api/Messages?sortColumn=${encodeURIComponent(sortColumn)}&sortIsDescending=${sortIsDescending}
public getSummaries_url(sortColumn: string, sortIsDescending: boolean): string {
return `${this._baseUrl}api/Messages?sortColumn=${encodeURIComponent(sortColumn)}&sortIsDescending=${sortIsDescending}`;
return `api/Messages?sortColumn=${encodeURIComponent(sortColumn)}&sortIsDescending=${sortIsDescending}`;
}

public async getSummaries(sortColumn: string, sortIsDescending: boolean): Promise<MessageSummary[]> {
Expand All @@ -26,7 +24,7 @@ export default class MessagesController {

// get: api/Messages/${encodeURIComponent(id)}
public getMessage_url(id: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}`;
return `api/Messages/${encodeURIComponent(id)}`;
}

public async getMessage(id: string): Promise<Message> {
Expand All @@ -36,7 +34,7 @@ export default class MessagesController {

// post: api/Messages/${encodeURIComponent(id)}
public markMessageRead_url(id: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}`;
return `api/Messages/${encodeURIComponent(id)}`;
}

public async markMessageRead(id: string): Promise<void> {
Expand All @@ -46,47 +44,47 @@ export default class MessagesController {

// get: api/Messages/${encodeURIComponent(id)}/source
public downloadMessage_url(id: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}/source`;
return `api/Messages/${encodeURIComponent(id)}/source`;
}

public async downloadMessage(id: string): Promise<FileStreamResult> {

return (await axios.get(this.downloadMessage_url(id), null || undefined)).data as FileStreamResult;
}

// get: api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(cid)}/content
public getPartContent_url(id: string, cid: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(cid)}/content`;
// get: api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(partid)}/content
public getPartContent_url(id: string, partid: string): string {
return `api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(partid)}/content`;
}

public async getPartContent(id: string, cid: string): Promise<FileStreamResult> {
public async getPartContent(id: string, partid: string): Promise<FileStreamResult> {

return (await axios.get(this.getPartContent_url(id, cid), null || undefined)).data as FileStreamResult;
return (await axios.get(this.getPartContent_url(id, partid), null || undefined)).data as FileStreamResult;
}

// get: api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(cid)}/source
public getPartSource_url(id: string, cid: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(cid)}/source`;
// get: api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(partid)}/source
public getPartSource_url(id: string, partid: string): string {
return `api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(partid)}/source`;
}

public async getPartSource(id: string, cid: string): Promise<string> {
public async getPartSource(id: string, partid: string): Promise<string> {

return (await axios.get(this.getPartSource_url(id, cid), null || undefined)).data as string;
return (await axios.get(this.getPartSource_url(id, partid), null || undefined)).data as string;
}

// get: api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(cid)}/raw
public getPartSourceRaw_url(id: string, cid: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(cid)}/raw`;
// get: api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(partid)}/raw
public getPartSourceRaw_url(id: string, partid: string): string {
return `api/Messages/${encodeURIComponent(id)}/part/${encodeURIComponent(partid)}/raw`;
}

public async getPartSourceRaw(id: string, cid: string): Promise<string> {
public async getPartSourceRaw(id: string, partid: string): Promise<string> {

return (await axios.get(this.getPartSourceRaw_url(id, cid), null || undefined)).data as string;
return (await axios.get(this.getPartSourceRaw_url(id, partid), null || undefined)).data as string;
}

// get: api/Messages/${encodeURIComponent(id)}/html
public getMessageHtml_url(id: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}/html`;
return `api/Messages/${encodeURIComponent(id)}/html`;
}

public async getMessageHtml(id: string): Promise<string> {
Expand All @@ -96,7 +94,7 @@ export default class MessagesController {

// delete: api/Messages/${encodeURIComponent(id)}
public delete_url(id: string): string {
return `${this._baseUrl}api/Messages/${encodeURIComponent(id)}`;
return `api/Messages/${encodeURIComponent(id)}`;
}

public async delete(id: string): Promise<void> {
Expand All @@ -106,7 +104,7 @@ export default class MessagesController {

// delete: api/Messages/*
public deleteAll_url(): string {
return `${this._baseUrl}api/Messages/*`;
return `api/Messages/*`;
}

public async deleteAll(): Promise<void> {
Expand Down
16 changes: 7 additions & 9 deletions Rnwood.Smtp4dev/ClientApp/ApiClient/SessionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import Session from './Session';
import axios from "axios";

export default class SessionsController {
public _baseUrl: string;

constructor(baseUrl: string = "/"){
this._baseUrl = baseUrl;

constructor(){
}



// get: api/Sessions
public getSummaries_url(): string {
return `${this._baseUrl}api/Sessions`;
return `api/Sessions`;
}

public async getSummaries(): Promise<SessionSummary[]> {
Expand All @@ -25,7 +23,7 @@ export default class SessionsController {

// get: api/Sessions/${encodeURIComponent(id)}
public getSession_url(id: string): string {
return `${this._baseUrl}api/Sessions/${encodeURIComponent(id)}`;
return `api/Sessions/${encodeURIComponent(id)}`;
}

public async getSession(id: string): Promise<Session> {
Expand All @@ -35,7 +33,7 @@ export default class SessionsController {

// get: api/Sessions/${encodeURIComponent(id)}/log
public getSessionLog_url(id: string): string {
return `${this._baseUrl}api/Sessions/${encodeURIComponent(id)}/log`;
return `api/Sessions/${encodeURIComponent(id)}/log`;
}

public async getSessionLog(id: string): Promise<string> {
Expand All @@ -45,7 +43,7 @@ export default class SessionsController {

// delete: api/Sessions/${encodeURIComponent(id)}
public delete_url(id: string): string {
return `${this._baseUrl}api/Sessions/${encodeURIComponent(id)}`;
return `api/Sessions/${encodeURIComponent(id)}`;
}

public async delete(id: string): Promise<void> {
Expand All @@ -55,7 +53,7 @@ export default class SessionsController {

// delete: api/Sessions/*
public deleteAll_url(): string {
return `${this._baseUrl}api/Sessions/*`;
return `api/Sessions/*`;
}

public async deleteAll(): Promise<void> {
Expand Down
8 changes: 3 additions & 5 deletions Rnwood.Smtp4dev/ClientApp/ApiClient/Template.tst
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ $Classes(*Controller)[$ControllerImports
import axios from "axios";

export default class $ServiceName {
public _baseUrl: string;

constructor(baseUrl: string = "/"){
this._baseUrl = baseUrl;

constructor(){
}

$Methods[

// $HttpMethod: $Url
public $name_url($Parameters(p => p.Type.IsPrimitive)[$name: $Type][, ]): string {
return `${this._baseUrl}$Url`;
return `$Url`;
}

public async $name($Parameters[$name: $Type][, ]): Promise<$ReturnType> {
Expand Down
2 changes: 1 addition & 1 deletion Rnwood.Smtp4dev/ClientApp/components/messagelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class MessageList extends Vue {
constructor() {
super();

this.connection = new HubConnectionManager('/hubs/messages', this.refresh);
this.connection = new HubConnectionManager('hubs/messages', this.refresh);
this.connection.on('messageschanged', async () => {
await this.refresh();
});
Expand Down
2 changes: 1 addition & 1 deletion Rnwood.Smtp4dev/ClientApp/components/sessionlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class SessionList extends Vue {
constructor() {
super();

this.connection = new HubConnectionManager('/hubs/sessions', this.refresh);
this.connection = new HubConnectionManager('hubs/sessions', this.refresh);
this.connection.on('sessionschanged', () => {
this.refresh();
});
Expand Down
2 changes: 1 addition & 1 deletion Rnwood.Smtp4dev/Controllers/MessagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public string GetMessageHtml(Guid id)

var part = message.Parts.Flatten(p => p.ChildParts).FirstOrDefault(p => p.ContentId == cid);

imageElement.Attributes["src"].Value = $"/api/Messages/{id.ToString()}/part/{part?.Id ?? "notfound"}/content";
imageElement.Attributes["src"].Value = $"api/Messages/{id.ToString()}/part/{part?.Id ?? "notfound"}/content";
}
}

Expand Down
3 changes: 2 additions & 1 deletion Rnwood.Smtp4dev/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ private static IWebHost BuildWebHost(string[] args)
{ "--smtpport", "ServerOptions:Port"},
{ "--db", "ServerOptions:Database" },
{ "--messagestokeep", "ServerOptions:NumberOfMessagesToKeep" },
{ "--sessionstokeep", "ServerOptions:NumberOfSessionsToKeep" }
{ "--sessionstokeep", "ServerOptions:NumberOfSessionsToKeep" },
{ "--rooturl", "ServerOptions:RootUrl"}
})
.Build();

Expand Down
3 changes: 2 additions & 1 deletion Rnwood.Smtp4dev/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:28260/",
"applicationUrl": "http://localhost:28260",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "/blah",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
3 changes: 3 additions & 0 deletions Rnwood.Smtp4dev/Rnwood.Smtp4dev.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
</ItemGroup>

<ItemGroup>
<None Update="ClientApp\ApiClient\AttachmentSummary.ts">
<CustomToolNamespace>ApiModel\AttachmentSummary.cs</CustomToolNamespace>
</None>
<None Update="ClientApp\ApiClient\HomeController.ts">
<CustomToolNamespace>Controllers\HomeController.cs</CustomToolNamespace>
</None>
Expand Down
2 changes: 2 additions & 0 deletions Rnwood.Smtp4dev/Server/ServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class ServerOptions

public int NumberOfMessagesToKeep { get; set; } = 100;
public int NumberOfSessionsToKeep { get; set; } = 100;

public string RootUrl { get; set; }
}
}
Loading

0 comments on commit 905ee7c

Please sign in to comment.